diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-06 01:14:26 -0500 |
|---|---|---|
| committer | mike bayer <mike_mp@zzzcomputing.com> | 2019-01-06 17:34:50 +0000 |
| commit | 1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch) | |
| tree | 28e725c5c8188bd0cfd133d1e268dbca9b524978 /test/orm/test_utils.py | |
| parent | 404e69426b05a82d905cbb3ad33adafccddb00dd (diff) | |
| download | sqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz | |
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits
applied at all.
The black run will format code consistently, however in
some cases that are prevalent in SQLAlchemy code it produces
too-long lines. The too-long lines will be resolved in the
following commit that will resolve all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.
Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'test/orm/test_utils.py')
| -rw-r--r-- | test/orm/test_utils.py | 328 |
1 files changed, 179 insertions, 149 deletions
diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py index 44161ddcd..d53e99d13 100644 --- a/test/orm/test_utils.py +++ b/test/orm/test_utils.py @@ -19,19 +19,23 @@ from .inheritance import _poly_fixtures class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): - __dialect__ = 'default' + __dialect__ = "default" def _fixture(self, cls, properties={}): - table = Table('point', MetaData(), - Column('id', Integer(), primary_key=True), - Column('x', Integer), - Column('y', Integer)) + table = Table( + "point", + MetaData(), + Column("id", Integer(), primary_key=True), + Column("x", Integer), + Column("y", Integer), + ) mapper(cls, table, properties=properties) return table def test_simple(self): class Point(object): pass + table = self._fixture(Point) alias = aliased(Point) @@ -46,6 +50,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): def test_not_instantiatable(self): class Point(object): pass + table = self._fixture(Point) alias = aliased(Point) @@ -64,9 +69,9 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): # TODO: I don't quite understand this # still if util.py2k: - assert not getattr(alias, 'zero') + assert not getattr(alias, "zero") else: - assert getattr(alias, 'zero') + assert getattr(alias, "zero") def test_classmethod(self): class Point(object): @@ -96,7 +101,6 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): assert Point.max_x is alias.max_x def test_descriptors(self): - class descriptor(object): def __init__(self, fn): self.fn = fn @@ -108,7 +112,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): return self def method(self): - return 'method' + return "method" class Point(object): center = (0, 0) @@ -122,13 +126,14 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): assert Point.thing != (0, 0) assert Point().thing == (0, 0) - assert Point.thing.method() == 'method' + assert Point.thing.method() == "method" assert alias.thing != (0, 0) - assert alias.thing.method() == 'method' + assert alias.thing.method() == "method" def _assert_has_table(self, expr, table): from sqlalchemy import Column # override testlib's override + for child in expr.get_children(): if isinstance(child, Column): assert child.table is table @@ -150,7 +155,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): sess.query(alias).filter(alias.left_of(Point)), "SELECT point_1.id AS point_1_id, point_1.x AS point_1_x, " "point_1.y AS point_1_y FROM point AS point_1, point " - "WHERE point_1.x < point.x" + "WHERE point_1.x < point.x", ) def test_hybrid_descriptor_two(self): @@ -176,7 +181,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): sess.query(alias).filter(alias.double_x > Point.x), "SELECT point_1.id AS point_1_id, point_1.x AS point_1_x, " "point_1.y AS point_1_y FROM point AS point_1, point " - "WHERE point_1.x * :x_1 > point.x" + "WHERE point_1.x * :x_1 > point.x", ) def test_hybrid_descriptor_three(self): @@ -203,10 +208,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): eq_(str(alias.x + 1), "point_1.x + :x_1") eq_(str(alias.x_alone + 1), "point_1.x + :x_1") - is_( - Point.x_alone.__clause_element__(), - Point.x.__clause_element__() - ) + is_(Point.x_alone.__clause_element__(), Point.x.__clause_element__()) eq_(str(alias.x_alone == alias.x), "point_1.x = point_1.x") @@ -219,7 +221,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): sess.query(alias).filter(alias.x_alone > Point.x), "SELECT point_1.id AS point_1_id, point_1.x AS point_1_x, " "point_1.y AS point_1_y FROM point AS point_1, point " - "WHERE point_1.x > point.x" + "WHERE point_1.x > point.x", ) def test_proxy_descriptor_one(self): @@ -227,9 +229,7 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): def __init__(self, x, y): self.x, self.y = x, y - self._fixture(Point, properties={ - 'x_syn': synonym("x") - }) + self._fixture(Point, properties={"x_syn": synonym("x")}) alias = aliased(Point) eq_(str(Point.x_syn), "Point.x_syn") @@ -239,16 +239,14 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( sess.query(alias.x_syn).filter(alias.x_syn > Point.x_syn), "SELECT point_1.x AS point_1_x FROM point AS point_1, point " - "WHERE point_1.x > point.x" + "WHERE point_1.x > point.x", ) def test_parententity_vs_parentmapper(self): class Point(object): pass - self._fixture(Point, properties={ - 'x_syn': synonym("x") - }) + self._fixture(Point, properties={"x_syn": synonym("x")}) pa = aliased(Point) is_(Point.x_syn._parententity, inspect(Point)) @@ -257,17 +255,21 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): is_(Point.x._parentmapper, inspect(Point)) is_( - Point.x_syn.__clause_element__()._annotations['parententity'], - inspect(Point)) + Point.x_syn.__clause_element__()._annotations["parententity"], + inspect(Point), + ) is_( - Point.x.__clause_element__()._annotations['parententity'], - inspect(Point)) + Point.x.__clause_element__()._annotations["parententity"], + inspect(Point), + ) is_( - Point.x_syn.__clause_element__()._annotations['parentmapper'], - inspect(Point)) + Point.x_syn.__clause_element__()._annotations["parentmapper"], + inspect(Point), + ) is_( - Point.x.__clause_element__()._annotations['parentmapper'], - inspect(Point)) + Point.x.__clause_element__()._annotations["parentmapper"], + inspect(Point), + ) pa = aliased(Point) @@ -277,19 +279,20 @@ class AliasedClassTest(fixtures.TestBase, AssertsCompiledSQL): is_(pa.x._parentmapper, inspect(Point)) is_( - pa.x_syn.__clause_element__()._annotations['parententity'], - inspect(pa) + pa.x_syn.__clause_element__()._annotations["parententity"], + inspect(pa), ) is_( - pa.x.__clause_element__()._annotations['parententity'], - inspect(pa) + pa.x.__clause_element__()._annotations["parententity"], inspect(pa) ) is_( - pa.x_syn.__clause_element__()._annotations['parentmapper'], - inspect(Point)) + pa.x_syn.__clause_element__()._annotations["parentmapper"], + inspect(Point), + ) is_( - pa.x.__clause_element__()._annotations['parentmapper'], - inspect(Point)) + pa.x.__clause_element__()._annotations["parentmapper"], + inspect(Point), + ) class IdentityKeyTest(_fixtures.FixtureTest): @@ -320,7 +323,7 @@ class IdentityKeyTest(_fixtures.FixtureTest): mapper(User, users) s = create_session() - u = User(name='u1') + u = User(name="u1") s.add(u) s.flush() key = orm_util.identity_key(instance=u) @@ -347,7 +350,7 @@ class IdentityKeyTest(_fixtures.FixtureTest): class PathRegistryTest(_fixtures.FixtureTest): - run_setup_mappers = 'once' + run_setup_mappers = "once" run_inserts = None run_deletes = None @@ -357,14 +360,8 @@ class PathRegistryTest(_fixtures.FixtureTest): def test_root_registry(self): umapper = inspect(self.classes.User) - is_( - RootRegistry()[umapper], - umapper._path_registry - ) - eq_( - RootRegistry()[umapper], - PathRegistry.coerce((umapper,)) - ) + is_(RootRegistry()[umapper], umapper._path_registry) + eq_(RootRegistry()[umapper], PathRegistry.coerce((umapper,))) def test_expand(self): umapper = inspect(self.classes.User) @@ -372,10 +369,17 @@ class PathRegistryTest(_fixtures.FixtureTest): path = PathRegistry.coerce((umapper,)) eq_( - path[umapper.attrs.addresses][amapper] - [amapper.attrs.email_address], - PathRegistry.coerce((umapper, umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + path[umapper.attrs.addresses][amapper][ + amapper.attrs.email_address + ], + PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ), ) def test_entity_boolean(self): @@ -398,24 +402,42 @@ class PathRegistryTest(_fixtures.FixtureTest): def test_indexed_entity(self): umapper = inspect(self.classes.User) amapper = inspect(self.classes.Address) - path = PathRegistry.coerce((umapper, umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + path = PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) is_(path[0], umapper) is_(path[2], amapper) def test_indexed_key(self): umapper = inspect(self.classes.User) amapper = inspect(self.classes.Address) - path = PathRegistry.coerce((umapper, umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + path = PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) eq_(path[1], umapper.attrs.addresses) eq_(path[3], amapper.attrs.email_address) def test_slice(self): umapper = inspect(self.classes.User) amapper = inspect(self.classes.Address) - path = PathRegistry.coerce((umapper, umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + path = PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) eq_(path[1:3], (umapper.attrs.addresses, amapper)) def test_addition(self): @@ -425,8 +447,14 @@ class PathRegistryTest(_fixtures.FixtureTest): p2 = PathRegistry.coerce((amapper, amapper.attrs.email_address)) eq_( p1 + p2, - PathRegistry.coerce((umapper, umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ), ) def test_length(self): @@ -436,8 +464,14 @@ class PathRegistryTest(_fixtures.FixtureTest): p0 = PathRegistry.coerce((umapper,)) p1 = PathRegistry.coerce((umapper, umapper.attrs.addresses)) p2 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper)) - p3 = PathRegistry.coerce((umapper, umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + p3 = PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) eq_(len(pneg1), 0) eq_(len(p0), 1) @@ -459,11 +493,19 @@ class PathRegistryTest(_fixtures.FixtureTest): p3 = PathRegistry.coerce((umapper, umapper.attrs.name)) p4 = PathRegistry.coerce((u_alias, umapper.attrs.addresses)) p5 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper)) - p6 = PathRegistry.coerce((amapper, amapper.attrs.user, umapper, - umapper.attrs.addresses)) - p7 = PathRegistry.coerce((amapper, amapper.attrs.user, umapper, - umapper.attrs.addresses, - amapper, amapper.attrs.email_address)) + p6 = PathRegistry.coerce( + (amapper, amapper.attrs.user, umapper, umapper.attrs.addresses) + ) + p7 = PathRegistry.coerce( + ( + amapper, + amapper.attrs.user, + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) is_(p1 == p2, True) is_(p1 == p3, False) @@ -492,15 +534,9 @@ class PathRegistryTest(_fixtures.FixtureTest): p2 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper)) p3 = PathRegistry.coerce((amapper, amapper.attrs.email_address)) - eq_( - p1.path, (umapper, umapper.attrs.addresses) - ) - eq_( - p2.path, (umapper, umapper.attrs.addresses, amapper) - ) - eq_( - p3.path, (amapper, amapper.attrs.email_address) - ) + eq_(p1.path, (umapper, umapper.attrs.addresses)) + eq_(p2.path, (umapper, umapper.attrs.addresses, amapper)) + eq_(p3.path, (amapper, amapper.attrs.email_address)) def test_registry_set(self): reg = {} @@ -517,10 +553,10 @@ class PathRegistryTest(_fixtures.FixtureTest): eq_( reg, { - ('p1key', p1.path): 'p1value', - ('p2key', p2.path): 'p2value', - ('p3key', p3.path): 'p3value', - } + ("p1key", p1.path): "p1value", + ("p2key", p2.path): "p2value", + ("p3key", p3.path): "p3value", + }, ) def test_registry_get(self): @@ -533,9 +569,9 @@ class PathRegistryTest(_fixtures.FixtureTest): p3 = PathRegistry.coerce((amapper, amapper.attrs.email_address)) reg.update( { - ('p1key', p1.path): 'p1value', - ('p2key', p2.path): 'p2value', - ('p3key', p3.path): 'p3value', + ("p1key", p1.path): "p1value", + ("p2key", p2.path): "p2value", + ("p3key", p3.path): "p3value", } ) @@ -555,9 +591,9 @@ class PathRegistryTest(_fixtures.FixtureTest): p3 = PathRegistry.coerce((amapper, amapper.attrs.email_address)) reg.update( { - ('p1key', p1.path): 'p1value', - ('p2key', p2.path): 'p2value', - ('p3key', p3.path): 'p3value', + ("p1key", p1.path): "p1value", + ("p2key", p2.path): "p2value", + ("p3key", p3.path): "p3value", } ) assert p1.contains(reg, "p1key") @@ -572,11 +608,7 @@ class PathRegistryTest(_fixtures.FixtureTest): p1 = PathRegistry.coerce((umapper, umapper.attrs.addresses)) p2 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper)) - reg.update( - { - ('p1key', p1.path): 'p1value', - } - ) + reg.update({("p1key", p1.path): "p1value"}) p1.setdefault(reg, "p1key", "p1newvalue_a") p1.setdefault(reg, "p1key_new", "p1newvalue_b") @@ -584,10 +616,10 @@ class PathRegistryTest(_fixtures.FixtureTest): eq_( reg, { - ('p1key', p1.path): 'p1value', - ('p1key_new', p1.path): 'p1newvalue_b', - ('p2key', p2.path): 'p2newvalue', - } + ("p1key", p1.path): "p1value", + ("p1key_new", p1.path): "p1newvalue_b", + ("p2key", p2.path): "p2newvalue", + }, ) def test_serialize(self): @@ -596,22 +628,19 @@ class PathRegistryTest(_fixtures.FixtureTest): umapper = inspect(self.classes.User) amapper = inspect(self.classes.Address) - p1 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper, - amapper.attrs.email_address)) + p1 = PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) p2 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper)) p3 = PathRegistry.coerce((umapper, umapper.attrs.addresses)) - eq_( - p1.serialize(), - [(User, "addresses"), (Address, "email_address")] - ) - eq_( - p2.serialize(), - [(User, "addresses"), (Address, None)] - ) - eq_( - p3.serialize(), - [(User, "addresses")] - ) + eq_(p1.serialize(), [(User, "addresses"), (Address, "email_address")]) + eq_(p2.serialize(), [(User, "addresses"), (Address, None)]) + eq_(p3.serialize(), [(User, "addresses")]) def test_deseralize(self): User = self.classes.User @@ -619,28 +648,32 @@ class PathRegistryTest(_fixtures.FixtureTest): umapper = inspect(self.classes.User) amapper = inspect(self.classes.Address) - p1 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper, - amapper.attrs.email_address)) + p1 = PathRegistry.coerce( + ( + umapper, + umapper.attrs.addresses, + amapper, + amapper.attrs.email_address, + ) + ) p2 = PathRegistry.coerce((umapper, umapper.attrs.addresses, amapper)) p3 = PathRegistry.coerce((umapper, umapper.attrs.addresses)) eq_( - PathRegistry.deserialize([(User, "addresses"), - (Address, "email_address")]), - p1 + PathRegistry.deserialize( + [(User, "addresses"), (Address, "email_address")] + ), + p1, ) eq_( PathRegistry.deserialize([(User, "addresses"), (Address, None)]), - p2 - ) - eq_( - PathRegistry.deserialize([(User, "addresses")]), - p3 + p2, ) + eq_(PathRegistry.deserialize([(User, "addresses")]), p3) class PathRegistryInhTest(_poly_fixtures._Polymorphic): - run_setup_mappers = 'once' + run_setup_mappers = "once" run_inserts = None run_deletes = None @@ -654,10 +687,7 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): # given a mapper and an attribute on a subclass, # the path converts what you get to be against that subclass - eq_( - p1.path, - (emapper, emapper.attrs.machines) - ) + eq_(p1.path, (emapper, emapper.attrs.machines)) def test_plain_compound(self): Company = _poly_fixtures.Company @@ -667,14 +697,20 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): pmapper = inspect(Person) emapper = inspect(Engineer) - p1 = PathRegistry.coerce((cmapper, cmapper.attrs.employees, - pmapper, emapper.attrs.machines)) + p1 = PathRegistry.coerce( + (cmapper, cmapper.attrs.employees, pmapper, emapper.attrs.machines) + ) # given a mapper and an attribute on a subclass, # the path converts what you get to be against that subclass eq_( p1.path, - (cmapper, cmapper.attrs.employees, emapper, emapper.attrs.machines) + ( + cmapper, + cmapper.attrs.employees, + emapper, + emapper.attrs.machines, + ), ) def test_plain_aliased(self): @@ -688,10 +724,7 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): p1 = PathRegistry.coerce((p_alias, emapper.attrs.machines)) # plain AliasedClass - the path keeps that AliasedClass directly # as is in the path - eq_( - p1.path, - (p_alias, emapper.attrs.machines) - ) + eq_(p1.path, (p_alias, emapper.attrs.machines)) def test_plain_aliased_compound(self): Company = _poly_fixtures.Company @@ -706,13 +739,19 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): c_alias = inspect(c_alias) p_alias = inspect(p_alias) - p1 = PathRegistry.coerce((c_alias, cmapper.attrs.employees, - p_alias, emapper.attrs.machines)) + p1 = PathRegistry.coerce( + (c_alias, cmapper.attrs.employees, p_alias, emapper.attrs.machines) + ) # plain AliasedClass - the path keeps that AliasedClass directly # as is in the path eq_( p1.path, - (c_alias, cmapper.attrs.employees, p_alias, emapper.attrs.machines) + ( + c_alias, + cmapper.attrs.employees, + p_alias, + emapper.attrs.machines, + ), ) def test_with_poly_sub(self): @@ -728,10 +767,7 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): # polymorphic AliasedClass - the path uses _entity_for_mapper() # to get the most specific sub-entity - eq_( - p1.path, - (e_poly, emapper.attrs.machines) - ) + eq_(p1.path, (e_poly, emapper.attrs.machines)) def test_with_poly_base(self): Person = _poly_fixtures.Person @@ -747,10 +783,7 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): # polymorphic AliasedClass - because "name" is on Person, # we get Person, not Engineer - eq_( - p1.path, - (p_poly, pmapper.attrs.name) - ) + eq_(p1.path, (p_poly, pmapper.attrs.name)) def test_with_poly_use_mapper(self): Person = _poly_fixtures.Person @@ -764,7 +797,4 @@ class PathRegistryInhTest(_poly_fixtures._Polymorphic): # polymorphic AliasedClass with the "use_mapper_path" flag - # the AliasedClass acts just like the base mapper - eq_( - p1.path, - (emapper, emapper.attrs.machines) - ) + eq_(p1.path, (emapper, emapper.attrs.machines)) |
