From: Mike Bayer Date: Sat, 14 Jul 2007 23:06:57 +0000 (+0000) Subject: - test module turns warnings into exceptions so they can be tested for X-Git-Tag: rel_0_3_9~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c752ee1499bf8e4bff7b2663655d9dd4099593d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - test module turns warnings into exceptions so they can be tested for - the two mapper PK tests should actually warn on the id column collision - reverted abc_inheritance back to normal --- diff --git a/test/orm/abc_inheritance.py b/test/orm/abc_inheritance.py index 9b2928fbec..7689bd5430 100644 --- a/test/orm/abc_inheritance.py +++ b/test/orm/abc_inheritance.py @@ -126,14 +126,13 @@ def produce_test(parent, child, direction): sess.clear() # assert result via direct get() of parent object - # TODO: dual PK here is a temporary workaround until #185 is fixed again - result = sess.query(parent_class).get([parent_obj.id, parent_obj.id]) + result = sess.query(parent_class).get(parent_obj.id) assert result.id == parent_obj.id assert result.collection[0].id == child_obj.id if direction == ONETOMANY: assert result.collection[1].id == child2.id elif direction == MANYTOONE: - result2 = sess.query(parent_class).get([parent2.id, parent2.id]) + result2 = sess.query(parent_class).get(parent2.id) assert result2.id == parent2.id assert result2.collection[0].id == child_obj.id diff --git a/test/orm/inheritance.py b/test/orm/inheritance.py index d608b2387a..d2e2b79c6f 100644 --- a/test/orm/inheritance.py +++ b/test/orm/inheritance.py @@ -519,9 +519,12 @@ class InheritTest8(testbase.ORMTest): def test_implicit(self): person_mapper = mapper(Person, person_table) mapper(Employee, employee_table, inherits=person_mapper) - print class_mapper(Employee).primary_key - assert list(class_mapper(Employee).primary_key) == [person_table.c.id, employee_table.c.id] - self._do_test(True) + try: + print class_mapper(Employee).primary_key + assert list(class_mapper(Employee).primary_key) == [person_table.c.id, employee_table.c.id] + assert False + except RuntimeWarning, e: + assert str(e) == "On mapper Mapper|Employee|employees, primary key column 'employees.id' is being combined with distinct primary key column 'persons.id' in attribute 'id'. Use explicit properties to give each column its own mapped attribute name." def test_explicit_props(self): person_mapper = mapper(Person, person_table) @@ -531,7 +534,11 @@ class InheritTest8(testbase.ORMTest): def test_explicit_composite_pk(self): person_mapper = mapper(Person, person_table) mapper(Employee, employee_table, inherits=person_mapper, primary_key=[person_table.c.id, employee_table.c.id]) - self._do_test(True) + try: + self._do_test(True) + assert False + except RuntimeWarning, e: + assert str(e) == "On mapper Mapper|Employee|employees, primary key column 'employees.id' is being combined with distinct primary key column 'persons.id' in attribute 'id'. Use explicit properties to give each column its own mapped attribute name." def test_explicit_pk(self): person_mapper = mapper(Person, person_table) diff --git a/test/orm/mapper.py b/test/orm/mapper.py index f366d4866e..063427134b 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -180,7 +180,9 @@ class MapperTest(MapperSuperTest): def bad_expunge(foo): raise Exception("this exception should be stated as a warning") - + + import warnings + warnings.filterwarnings("always", r".*this exception should be stated as a warning") sess.expunge = bad_expunge try: Foo(_sa_session=sess) diff --git a/test/testbase.py b/test/testbase.py index 7c5095d1a0..e2c15a537c 100644 --- a/test/testbase.py +++ b/test/testbase.py @@ -8,6 +8,9 @@ import optparse from sqlalchemy.schema import MetaData from sqlalchemy.orm import clear_mappers +import warnings +warnings.filterwarnings("error") + db = None metadata = None db_uri = None