MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_meta_getattr_one

Method test_meta_getattr_one

test/orm/test_utils.py:434–473  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

432 )
433
434 def test_meta_getattr_one(self):
435 class MetaPoint(type):
436 def __getattr__(cls, key):
437 if key == "x_syn":
438 return cls.x
439 raise AttributeError(key)
440
441 class Point(metaclass=MetaPoint):
442 pass
443
444 self._fixture(Point)
445 alias = aliased(Point)
446
447 eq_(str(Point.x_syn), "Point.x")
448 eq_(str(alias.x_syn), "aliased(Point).x")
449
450 # from __clause_element__() perspective, Point.x_syn
451 # and Point.x return the same thing, so that's good
452 eq_(str(Point.x.__clause_element__()), "point.x")
453 eq_(str(Point.x_syn.__clause_element__()), "point.x")
454
455 # same for the alias
456 eq_(str(alias.x + 1), "point_1.x + :x_1")
457 eq_(str(alias.x_syn + 1), "point_1.x + :x_1")
458
459 is_(Point.x_syn.__clause_element__(), Point.x.__clause_element__())
460
461 eq_(str(alias.x_syn == alias.x), "point_1.x = point_1.x")
462
463 a2 = aliased(Point)
464 eq_(str(a2.x_syn == alias.x), "point_1.x = point_2.x")
465
466 sess = fixture_session()
467
468 self.assert_compile(
469 sess.query(alias).filter(alias.x_syn > Point.x),
470 "SELECT point_1.id AS point_1_id, point_1.x AS point_1_x, "
471 "point_1.y AS point_1_y FROM point AS point_1, point "
472 "WHERE point_1.x > point.x",
473 )
474
475 def test_meta_getattr_two(self):
476 class MetaPoint(type):

Callers

nothing calls this directly

Calls 9

_fixtureMethod · 0.95
aliasedFunction · 0.90
eq_Function · 0.90
is_Function · 0.90
fixture_sessionFunction · 0.90
assert_compileMethod · 0.80
__clause_element__Method · 0.45
filterMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected