Commit 037594f5 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get a bunch more sqlalchemy tests working

- allow list subclasses to add __init__ functions that take more parameters
- support `[dict] == [attrwrapper]`
- fix bug in my recent weakref change
parent 149c3b42
......@@ -468,7 +468,7 @@ class WeakKeyDictionary(UserDict.UserDict):
def pop(self, key, *args):
r = ref(key)
self.keys.pop(r, None)
self.refs.pop(r, None)
return self.data.pop(r, *args)
def setdefault(self, key, default=None):
......
......@@ -697,6 +697,8 @@ void setupDescr() {
member_descriptor_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)memberGet, UNKNOWN, 3)));
member_descriptor_cls->freeze();
property_cls->instances_are_nonzero = true;
property_cls->giveAttr("__init__",
new BoxedFunction(boxRTFunction((void*)propertyInit, UNKNOWN, 5, false, false,
ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")),
......
......@@ -571,6 +571,9 @@ Box* dictEq(BoxedDict* self, Box* _rhs) {
raiseExcHelper(TypeError, "descriptor '__eq__' requires a 'dict' object but received a '%s'",
getTypeName(self));
if (_rhs->cls == attrwrapper_cls)
_rhs = attrwrapperToDict(_rhs);
if (!PyDict_Check(_rhs))
return NotImplemented;
......
......@@ -1078,12 +1078,6 @@ Box* listRemove(BoxedList* self, Box* elt) {
BoxedClass* list_iterator_cls = NULL;
BoxedClass* list_reverse_iterator_cls = NULL;
Box* listNew(BoxedClass* cls, Box* container) {
assert(PyType_Check(cls));
assert(isSubclass(cls, list_cls));
return new (cls) BoxedList();
}
Box* listInit(BoxedList* self, Box* container) {
assert(PyList_Check(self));
......@@ -1337,9 +1331,9 @@ void setupList() {
list_cls->giveAttr("extend", new BoxedFunction(boxRTFunction((void*)listIAdd, UNKNOWN, 2)));
list_cls->giveAttr("insert", new BoxedFunction(boxRTFunction((void*)listInsert, NONE, 3)));
list_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)listMul, LIST, 2)));
list_cls->giveAttr("__rmul__", new BoxedFunction(boxRTFunction((void*)listMul, LIST, 2)));
list_cls->giveAttr("__imul__", new BoxedFunction(boxRTFunction((void*)listImul, LIST, 2)));
list_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)listMul, UNKNOWN, 2)));
list_cls->giveAttr("__rmul__", new BoxedFunction(boxRTFunction((void*)listMul, UNKNOWN, 2)));
list_cls->giveAttr("__imul__", new BoxedFunction(boxRTFunction((void*)listImul, UNKNOWN, 2)));
list_cls->giveAttr("__iadd__", new BoxedFunction(boxRTFunction((void*)listIAdd, UNKNOWN, 2)));
list_cls->giveAttr("__add__", new BoxedFunction(boxRTFunction((void*)listAdd, UNKNOWN, 2)));
......@@ -1349,7 +1343,6 @@ void setupList() {
{ None, None, False }));
list_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)listContains, BOXED_BOOL, 2)));
list_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)listNew, UNKNOWN, 2, false, false), { None }));
list_cls->giveAttr("__init__",
new BoxedFunction(boxRTFunction((void*)listInit, UNKNOWN, 2, false, false), { NULL }));
......
......@@ -2731,6 +2731,13 @@ void attrwrapperDel(Box* b, llvm::StringRef attr) {
AttrWrapper::delitem(b, boxString(attr));
}
BoxedDict* attrwrapperToDict(Box* b) {
assert(b->cls == attrwrapper_cls);
Box* d = AttrWrapper::copy(static_cast<AttrWrapper*>(b));
assert(d->cls == dict_cls);
return static_cast<BoxedDict*>(d);
}
static int excess_args(PyObject* args, PyObject* kwds) noexcept {
return PyTuple_GET_SIZE(args) || (kwds && PyDict_Check(kwds) && PyDict_Size(kwds));
}
......
......@@ -1069,6 +1069,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value);
Box* unwrapAttrWrapper(Box* b);
Box* attrwrapperKeys(Box* b);
void attrwrapperDel(Box* b, llvm::StringRef attr);
BoxedDict* attrwrapperToDict(Box* b);
Box* boxAst(AST* ast);
AST* unboxAst(Box* b);
......
......@@ -131,13 +131,18 @@ MODULES_TO_TEST = [
'test.engine.test_pool',
'test.engine.test_reconnect',
'test.ext.test_compiler',
'test.ext.test_hybrid',
'test.ext.test_orderinglist',
'test.orm.test_association',
'test.orm.test_assorted_eager',
'test.orm.test_attributes',
'test.orm.test_backref_mutations',
'test.orm.test_bind',
'test.orm.test_bulk',
'test.orm.test_bundle',
'test.orm.test_collection',
'test.orm.test_compile',
'test.orm.test_composites',
'test.orm.test_cycles',
'test.orm.test_defaults',
'test.orm.test_default_strategies',
......@@ -146,10 +151,18 @@ MODULES_TO_TEST = [
'test.orm.test_descriptor',
'test.orm.test_eager_relations',
'test.orm.test_evaluator',
'test.orm.test_events',
'test.orm.test_expire',
'test.orm.test_hasparent',
'test.orm.test_immediate_load',
'test.orm.test_inspect',
'test.orm.test_joins',
'test.orm.test_lazy_relations',
'test.orm.test_load_on_fks',
'test.orm.test_lockmode',
'test.orm.test_manytomany',
'test.orm.test_naturalpks',
'test.orm.test_of_type',
'test.orm.test_onetoone',
'test.orm.test_options',
'test.orm.test_query',
......@@ -157,6 +170,10 @@ MODULES_TO_TEST = [
'test.orm.test_scoping',
'test.orm.test_selectable',
'test.orm.test_sync',
'test.orm.test_transaction',
'test.orm.test_unitofworkv2',
'test.orm.test_update_delete',
'test.orm.test_utils',
'test.orm.test_validators',
'test.sql.test_case_statement',
'test.sql.test_constraints',
......@@ -164,6 +181,7 @@ MODULES_TO_TEST = [
'test.sql.test_ddlemit',
'test.sql.test_delete',
'test.sql.test_functions',
'test.sql.test_generative',
'test.sql.test_insert',
'test.sql.test_inspect',
'test.sql.test_join_rewriting',
......@@ -171,6 +189,8 @@ MODULES_TO_TEST = [
'test.sql.test_operators',
'test.sql.test_query',
'test.sql.test_rowcount',
'test.sql.test_selectable',
'test.sql.test_text',
]
FAILING = [
......@@ -178,34 +198,14 @@ FAILING = [
# 'test.aaa_profiling.test_resultset', # Wants sys.getrefcount
# 'test.dialect.test_sqlite', # ascii codec can't encode
# 'test.ext.test_extendedattr', # does `locals()[42] = 99` in a classdef to prove it can. maybe we could say is_pypy to avoid it.
'test.ext.test_hybrid',
'test.ext.test_orderinglist',
'test.orm.test_attributes',
'test.orm.test_collection',
'test.orm.test_composites',
'test.orm.test_dynamic',
'test.orm.test_events',
'test.orm.test_hasparent',
'test.orm.test_immediate_load',
'test.orm.test_joins',
'test.orm.test_lazy_relations',
'test.orm.test_manytomany',
'test.orm.test_merge',
'test.orm.test_naturalpks',
'test.orm.test_of_type',
'test.orm.test_relationships',
'test.orm.test_session',
'test.orm.test_transaction',
'test.orm.test_unitofworkv2',
'test.orm.test_update_delete',
'test.orm.test_utils',
'test.orm.test_versioning',
'test.sql.test_compiler',
'test.sql.test_generative',
'test.sql.test_quote',
'test.sql.test_selectable',
'test.sql.test_text',
'test.sql.test_unicode'
# 'test.orm.test_dynamic', # not sure; things end up being put in tuples
# 'test.orm.test_merge', # needs PyObject_AsWriteBuffer
# 'test.orm.test_relationships', # not sure; things end up being put in tuples
# 'test.orm.test_session', # unclear
# 'test.orm.test_versioning', # crashes in the uuid module with an AttributeError from ctypes
# 'test.sql.test_compiler', # unclear
# 'test.sql.test_quote', # unclear
# 'test.sql.test_unicode', # "ascii codec can't encod character"
]
# MODULES_TO_TEST = ['test.orm.test_bulk']
......
......@@ -36,3 +36,24 @@ print MyList((1,2,3)) < MyList((1,2,3,4))
print MyList((1,2,3)) >= MyList((1,2,3))
print MyList((1,2,3)) <= MyList((1,2,3))
print type(MyList((1, 2, 3)) * 1)
class ListWithInit(list):
def __init__(self, *args, **kwargs):
print "ListWithInit.__init__", args, kwargs
l = ListWithInit(1, 2, 3, a=5)
l.a = 1
l.b = 2
# Adapted from the sqlalchemy test:
import pickle
l2 = pickle.loads(pickle.dumps(l))
print l == l2
assert l.__dict__ == l2.__dict__, (l.__dict__, l2.__dict__)
# Regression test:
def f(l):
l *= 1
for i in xrange(3000):
f(l)
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