def test_members_can_specify_relative_positions_using_base_schemas(self): from cocktail.schema import Schema, Member b1 = Member("b1") b2 = Member("b2") b3 = Member("b3") b = Schema() b.members_order = ["b2", "b3"] b.add_member(b1) b.add_member(b2) b.add_member(b3) d1 = Member("d1") d2 = Member("d2", before_member="b2") d3 = Member("d3", after_member="b1") d = Schema() d.inherit(b) d.add_member(d1) d.add_member(d2) d.add_member(d3) ordered_members = d.ordered_members() assert ordered_members == [d2, b2, b3, b1, d3, d1]
def test_layers_members_from_derived_schemas(self): from cocktail.schema import Schema, Member b1 = Member("b1") b2 = Member("b2") b3 = Member("b3") b4 = Member("b4") b = Schema() b.members_order = ["b4", "b3"] b.add_member(b1) b.add_member(b2) b.add_member(b3) b.add_member(b4) d1 = Member("d1") d2 = Member("d2") d3 = Member("d3") d4 = Member("d4") d = Schema() d.inherit(b) d.members_order = ["d4", "d3"] d.add_member(d1) d.add_member(d2) d.add_member(d3) d.add_member(d4) mlist = b.ordered_members() assert len(mlist) == 4 assert mlist[:2] == [b4, b3] assert set(mlist[2:]) == set([b1, b2]) mlist = d.ordered_members(False) assert len(mlist) == 4 assert mlist[:2] == [d4, d3] assert set(mlist[2:]) == set([d1, d2]) mlist = d.ordered_members() assert len(mlist) == 8 assert mlist[:2] == [b4, b3] assert set(mlist[2:4]) == set([b1, b2]) assert mlist[4:6] == [d4, d3] assert set(mlist[6:]) == set([d1, d2])
def test_ignores_missing_anchors(self): from cocktail.schema import Schema, Member m1 = Member("m1", after_member="m3") m2 = Member("m2") schema = Schema() schema.members_order = ["m2"] schema.add_member(m1) schema.add_member(m2) assert schema.ordered_members() == [m2, m1]
def test_follows_explicit_ordering(self): from cocktail.schema import Schema, Member m1 = Member("m1") m2 = Member("m2") m3 = Member("m3") m4 = Member("m4") schema = Schema() schema.members_order = ["m1", "m4", "m3", "m2"] schema.add_member(m1) schema.add_member(m2) schema.add_member(m3) schema.add_member(m4) assert schema.ordered_members() == [m1, m4, m3, m2]
def test_implicitly_includes_unspecified_members(self): from cocktail.schema import Schema, Member m1 = Member("m1") m2 = Member("m2") m3 = Member("m3") m4 = Member("m4") schema = Schema() schema.members_order = ["m3", "m2"] schema.add_member(m1) schema.add_member(m2) schema.add_member(m3) schema.add_member(m4) ordered_members = schema.ordered_members() assert len(ordered_members) == 4 assert ordered_members[:2] == [m3, m2] assert set(ordered_members[2:]) == set([m1, m4])
def test_members_can_specify_relative_positions(self): from cocktail.schema import Schema, Member m1 = Member("m1") m2 = Member("m2") m3 = Member("m3") m4 = Member("m4", after_member="m5") m5 = Member("m5", before_member="m1") m6 = Member("m6", before_member="m3") schema = Schema() schema.members_order = ["m3", "m2"] schema.add_member(m1) schema.add_member(m2) schema.add_member(m3) schema.add_member(m4) schema.add_member(m5) schema.add_member(m6) ordered_members = schema.ordered_members() assert ordered_members == [m6, m3, m2, m5, m4, m1]