MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _fixture

Method _fixture

test/orm/test_composites.py:788–845  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

786 )
787
788 def _fixture(self):
789 class AB:
790 def __init__(self, a, b, cd):
791 self.a = a
792 self.b = b
793 self.cd = cd
794
795 @classmethod
796 def generate(cls, a, b, c, d):
797 return AB(a, b, CD(c, d))
798
799 def __composite_values__(self):
800 return (self.a, self.b) + self.cd.__composite_values__()
801
802 def __eq__(self, other):
803 return (
804 isinstance(other, AB)
805 and self.a == other.a
806 and self.b == other.b
807 and self.cd == other.cd
808 )
809
810 def __ne__(self, other):
811 return not self.__eq__(other)
812
813 class CD:
814 def __init__(self, c, d):
815 self.c = c
816 self.d = d
817
818 def __composite_values__(self):
819 return (self.c, self.d)
820
821 def __eq__(self, other):
822 return (
823 isinstance(other, CD)
824 and self.c == other.c
825 and self.d == other.d
826 )
827
828 def __ne__(self, other):
829 return not self.__eq__(other)
830
831 class Thing:
832 def __init__(self, ab):
833 self.ab = ab
834
835 stuff = self.tables.stuff
836 self.mapper_registry.map_imperatively(
837 Thing,
838 stuff,
839 properties={
840 "ab": composite(
841 AB.generate, stuff.c.a, stuff.c.b, stuff.c.c, stuff.c.d
842 )
843 },
844 )
845 return Thing, AB, CD

Callers 1

test_round_tripMethod · 0.95

Calls 2

compositeFunction · 0.90
map_imperativelyMethod · 0.80

Tested by

no test coverage detected