def test_can_override_in_children(): sm = SpecificationMapper() child = sm.new_child_mapper() sm.define_specification_for('foo', const(1)) child.define_specification_for('foo', const(2)) assert sm.specification_for('foo') == 1 assert child.specification_for('foo') == 2
def test_child_can_call_other_specs_on_prototype(): s = SpecificationMapper() s.define_specification_for('bar', lambda t, d: t.specification_for('foo') + 1) s2 = s.new_child_mapper() s2.define_specification_for('foo', const(1)) assert s2.specification_for('bar') == 2
def test_cache_correctly_handles_inheritance(): s = SpecificationMapper() s.define_specification_for_instances( list, lambda s, d: [s.specification_for(d[0])]) t = s.new_child_mapper() t.define_specification_for_instances(str, lambda *_: Foo()) x = t.specification_for('foo') y = t.specification_for(['foo'])[0] assert x is y
def test_can_create_children(): sm = SpecificationMapper() child = sm.new_child_mapper() sm.define_specification_for('foo', const(1)) assert child.specification_for('foo') == 1