MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_hybrid_descriptor_three

Method test_hybrid_descriptor_three

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

Source from the content-addressed store, hash-verified

342 )
343
344 def test_hybrid_descriptor_three(self):
345 class Point:
346 def __init__(self, x, y):
347 self.x, self.y = x, y
348
349 @hybrid_property
350 def x_alone(self):
351 return self.x
352
353 self._fixture(Point)
354 alias = aliased(Point)
355
356 eq_(str(Point.x_alone), "Point.x_alone")
357 eq_(str(alias.x_alone), "aliased(Point).x_alone")
358
359 # from __clause_element__() perspective, Point.x_alone
360 # and Point.x return the same thing, so that's good
361 eq_(str(Point.x.__clause_element__()), "point.x")
362 eq_(str(Point.x_alone.__clause_element__()), "point.x")
363
364 # same for the alias
365 eq_(str(alias.x + 1), "point_1.x + :x_1")
366 eq_(str(alias.x_alone + 1), "point_1.x + :x_1")
367
368 point_mapper = inspect(Point)
369
370 eq_(
371 Point.x_alone._annotations,
372 {
373 "entity_namespace": point_mapper,
374 "parententity": point_mapper,
375 "parentmapper": point_mapper,
376 "proxy_key": "x_alone",
377 "proxy_owner": point_mapper,
378 },
379 )
380 eq_(
381 Point.x._annotations,
382 {
383 "entity_namespace": point_mapper,
384 "parententity": point_mapper,
385 "parentmapper": point_mapper,
386 "proxy_key": "x",
387 "proxy_owner": point_mapper,
388 },
389 )
390
391 eq_(str(alias.x_alone == alias.x), "point_1.x = point_1.x")
392
393 a2 = aliased(Point)
394 eq_(str(a2.x_alone == alias.x), "point_1.x = point_2.x")
395
396 eq_(
397 a2.x._annotations,
398 {
399 "entity_namespace": inspect(a2),
400 "parententity": inspect(a2),
401 "parentmapper": point_mapper,

Callers

nothing calls this directly

Calls 9

_fixtureMethod · 0.95
aliasedFunction · 0.90
eq_Function · 0.90
inspectFunction · 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