]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- test module turns warnings into exceptions so they can be tested for
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 14 Jul 2007 23:06:57 +0000 (23:06 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 14 Jul 2007 23:06:57 +0000 (23:06 +0000)
- the two mapper PK tests should actually warn on the id column collision
- reverted abc_inheritance back to normal

test/orm/abc_inheritance.py
test/orm/inheritance.py
test/orm/mapper.py
test/testbase.py

index 9b2928fbecc78369f765662c0587c690fdd0de9b..7689bd5430e47d122b30206bd871300e30b380e1 100644 (file)
@@ -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
             
index d608b2387a84812040445f29f07fd470d5e793ad..d2e2b79c6f67229531564114e2bdd271fa2308c7 100644 (file)
@@ -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)
index f366d4866efd354d95a9734e9984859e06b4f6a0..063427134b185b2ea12abf14e9882da65d84810d 100644 (file)
@@ -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)
index 7c5095d1a0abf432a18d54cc5c07613e3154c4de..e2c15a537c4d7860330a19ce93b74b9ce30d80d3 100644 (file)
@@ -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