MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / assert_tables_equal

Method assert_tables_equal

lib/sqlalchemy/testing/assertions.py:783–824  ·  view source on GitHub ↗
(
        self,
        table,
        reflected_table,
        strict_types=False,
        strict_constraints=True,
    )

Source from the content-addressed store, hash-verified

781
782class ComparesTables:
783 def assert_tables_equal(
784 self,
785 table,
786 reflected_table,
787 strict_types=False,
788 strict_constraints=True,
789 ):
790 assert len(table.c) == len(reflected_table.c)
791 for c, reflected_c in zip(table.c, reflected_table.c):
792 eq_(c.name, reflected_c.name)
793 assert reflected_c is reflected_table.c[c.name]
794
795 if strict_constraints:
796 eq_(c.primary_key, reflected_c.primary_key)
797 eq_(c.nullable, reflected_c.nullable)
798
799 if strict_types:
800 msg = "Type '%s' doesn't correspond to type '%s'"
801 assert isinstance(reflected_c.type, type(c.type)), msg % (
802 reflected_c.type,
803 c.type,
804 )
805 else:
806 self.assert_types_base(reflected_c, c)
807
808 if isinstance(c.type, sqltypes.String):
809 eq_(c.type.length, reflected_c.type.length)
810
811 if strict_constraints:
812 eq_(
813 {f.column.name for f in c.foreign_keys},
814 {f.column.name for f in reflected_c.foreign_keys},
815 )
816 if c.server_default:
817 assert isinstance(
818 reflected_c.server_default, schema.FetchedValue
819 )
820
821 if strict_constraints:
822 assert len(table.primary_key) == len(reflected_table.primary_key)
823 for c in table.primary_key:
824 assert reflected_table.primary_key.columns[c.name] is not None
825
826 def assert_types_base(self, c1, c2):
827 assert c1.type._compare_type_affinity(

Callers 7

test_copyMethod · 0.80
test_basic_reflectionMethod · 0.80
test_composite_fkMethod · 0.80
test_reflectionMethod · 0.80
test_basic_reflectionMethod · 0.80

Calls 2

assert_types_baseMethod · 0.95
eq_Function · 0.85

Tested by 7

test_copyMethod · 0.64
test_basic_reflectionMethod · 0.64
test_composite_fkMethod · 0.64
test_reflectionMethod · 0.64
test_basic_reflectionMethod · 0.64