Commit 6a83fd81 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Test cleanup: enable a bunch of close-to-succeeding tests

Many of them originally failed due to a missing language feature,
but now were failing due to simple reasons like printing out the repr
of an object which doesn't define __repr__ and getting something like
"<C object at 0x1234567890>" (ie nondeterministic).
parent dc9d0adc
...@@ -688,7 +688,8 @@ void checkAndThrowCAPIException() { ...@@ -688,7 +688,8 @@ void checkAndThrowCAPIException() {
assert(!cur_thread_state.curexc_value); assert(!cur_thread_state.curexc_value);
if (_type) { if (_type) {
RELEASE_ASSERT(cur_thread_state.curexc_traceback == NULL, "unsupported"); RELEASE_ASSERT(cur_thread_state.curexc_traceback == NULL || cur_thread_state.curexc_traceback == None,
"unsupported");
BoxedClass* type = static_cast<BoxedClass*>(_type); BoxedClass* type = static_cast<BoxedClass*>(_type);
assert(isInstance(_type, type_cls) && isSubclass(static_cast<BoxedClass*>(type), BaseException) assert(isInstance(_type, type_cls) && isSubclass(static_cast<BoxedClass*>(type), BaseException)
&& "Only support throwing subclass of BaseException for now"); && "Only support throwing subclass of BaseException for now");
...@@ -902,7 +903,8 @@ extern "C" PyObject* PyNumber_Add(PyObject* lhs, PyObject* rhs) noexcept { ...@@ -902,7 +903,8 @@ extern "C" PyObject* PyNumber_Add(PyObject* lhs, PyObject* rhs) noexcept {
try { try {
return binop(lhs, rhs, AST_TYPE::Add); return binop(lhs, rhs, AST_TYPE::Add);
} catch (ExcInfo e) { } catch (ExcInfo e) {
Py_FatalError("unimplemented"); setCAPIException(e);
return NULL;
} }
} }
......
# expected: fail # expected: fail
# - metaclasses # - object.__getattribute__ doesn't exist
# attr-getting resolution. # attr-getting resolution.
......
# expected: fail
# - lambdas, varargs
# Testing im-boxing: # Testing im-boxing:
class C(object): class C(object):
def __repr__(self):
return "<C>"
def __call__(*args): def __call__(*args):
print args print args
return args return args
def mul(*args): def mul(*args):
return args return args
class C1(object): class C1(object):
def __repr__(self):
return "<C1>"
__add__ = C() __add__ = C()
__sub__ = lambda *args: args __sub__ = lambda *args: args
__mul__ = mul __mul__ = mul
......
# expected: fail
# - arbitrary stuff in classdefs
# objmodel classattrs (like __add__) can be non-functions, so might not get bound into instancemethods: # objmodel classattrs (like __add__) can be non-functions, so might not get bound into instancemethods:
class Adder(object): class Adder(object):
...@@ -10,6 +7,8 @@ class Adder(object): ...@@ -10,6 +7,8 @@ class Adder(object):
class C(object): class C(object):
__add__ = Adder() __add__ = Adder()
def __repr__(self):
return "<C>"
c = C() c = C()
print c + c print c + c
# expected: fail
# - inheritance not implemented
class C(object): class C(object):
x = 1 x = 1
...@@ -13,4 +10,5 @@ print d.x ...@@ -13,4 +10,5 @@ print d.x
# But also when doing instance-level lookups! # But also when doing instance-level lookups!
print D.x print D.x
print D.__dict__ print 'x' in C.__dict__
print 'x' in D.__dict__
# expected: fail
# - descriptors not implemented yet
# Make sure that we guard in a getattr IC to make sure that # Make sure that we guard in a getattr IC to make sure that
# we don't subsequently get an object with a __get__ defined. # we don't subsequently get an object with a __get__ defined.
class D(object): class D(object):
pass def __repr__(self):
return "<D>"
class C(object): class C(object):
def __repr__(self):
return "<C>"
d = D() d = D()
c = C() c = C()
......
# expected: fail
# - descriptors not implemented yet
def f1(): def f1():
class D(object): class D(object):
def __get__(self, instance, owner): def __get__(self, instance, owner):
...@@ -13,6 +10,9 @@ def f1(): ...@@ -13,6 +10,9 @@ def f1():
class C(object): class C(object):
d = D() d = D()
def __repr__(self):
return "<C>"
print C.d print C.d
print C().d print C().d
...@@ -33,9 +33,15 @@ def f2(): ...@@ -33,9 +33,15 @@ def f2():
print "__getattribute__", attr print "__getattribute__", attr
return 1 return 1
def __repr__(self):
return "<MaybeDescriptor>"
class HasDescriptor(object): class HasDescriptor(object):
x = MaybeDescriptor() x = MaybeDescriptor()
def __repr__(self):
return "<HasDescriptor>"
hd = HasDescriptor() hd = HasDescriptor()
# Getting hd.x will look up type(hd.__dict__[x]).__get__ # Getting hd.x will look up type(hd.__dict__[x]).__get__
# and not go through __getattribute__ # and not go through __getattribute__
......
# expected: fail # expected: fail
# - inheritance # - exception printing
class BadException(Exception): class BadException(Exception):
def __str__(self): def __str__(self):
......
# expected: fail # expected: fail
# execfile() not implemented yet # - we throw some very weird error here
try: try:
execfile("doesnt_exist.py") execfile("doesnt_exist.py")
......
# expected: fail
# This test case currently fails because it prints the relative path to the .so
# module rather than the absolute path.
import basic_test import basic_test
print basic_test print type(basic_test)
# TODO this should work even if we don't keep a reference to l; # TODO this should work even if we don't keep a reference to l;
# it doesn't currently always work, but it sometimes works, so it's hard # it doesn't currently always work, but it sometimes works, so it's hard
......
# expected: fail # expected: fail
# - need to support closures # - long % int
import sys import sys
......
# expected: fail # expected: fail
# - setattr() not supported # - memory explosion
class C(object): class C(object):
pass pass
......
# expected: fail
# - not implemented yet
class CallableNew(object): class CallableNew(object):
def __call__(self, cls, arg): def __call__(self, cls, arg):
print "new", cls, arg print "new", cls, arg
...@@ -9,6 +6,8 @@ class CallableInit(object): ...@@ -9,6 +6,8 @@ class CallableInit(object):
def __call__(self, arg): def __call__(self, arg):
print "init", arg print "init", arg
class C(object): class C(object):
def __repr__(self):
return "<C>"
def __getattribute__(self, name): def __getattribute__(self, name):
# This shouldn't get called # This shouldn't get called
print "__getattribute__", name print "__getattribute__", name
......
# expected: fail # expected: fail
# setattr() not implemented # - not implemented yet
class C(object):
def print_none(self):
print None
c = C()
c.print_none()
# Can't do this:
# c.None = 1
setattr(C, "None", 1)
print dir(C)
print C.None # prints None!
c.print_none() # prints None!
import sys import sys
m = sys.modules["__main__"] m = sys.modules["__main__"]
......
# allow-warning: converting unicode literal to str # allow-warning: converting unicode literal to str
# expected: fail # Simple optparse test, taken from the optparse.py docstring:
# - too slow
# - prints out poorly since we return an "attrwrapper" instead of a real dict
# Simple opt parse test, taken from the optparse.py docstring:
from optparse import OptionParser from optparse import OptionParser
...@@ -16,4 +11,4 @@ parser.add_option("-q", "--quiet", ...@@ -16,4 +11,4 @@ parser.add_option("-q", "--quiet",
help="don't print status messages to stdout") help="don't print status messages to stdout")
(options, args) = parser.parse_args(['test', '--file=/dev/null', 'hello world']) (options, args) = parser.parse_args(['test', '--file=/dev/null', 'hello world'])
print options, args print sorted(options.__dict__.items()), args
# expected: fail # expected: fail
# - Relative imports not supported # - crashes rather than throws an error
try: try:
from . import doesnt_exist from . import doesnt_exist
......
...@@ -6,6 +6,12 @@ print reduce(operator.add, "hello world") ...@@ -6,6 +6,12 @@ print reduce(operator.add, "hello world")
print reduce(operator.add, "", 0) print reduce(operator.add, "", 0)
try:
print reduce(operator.add, "hello world", 0)
except TypeError, e:
print e
def f(a, b): def f(a, b):
print "f", a, b print "f", a, b
return b return b
......
# expected: fail
# - can't pass exceptions through C API yet
# (TODO fold this into reduce.py once it works)
import operator
try:
print reduce(operator.add, "hello world", 0)
except TypeError, e:
print e
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment