def test_attribute_failure(): sys.modules['empty3'] = imp.new_module('empty3') metafunc('empty3.comp', hofs1, fofs1, composition=True) import empty3.comp assert raises(AttributeError, lambda: empty3.comp.foo) assert raises(AttributeError, lambda: empty3.comp.inc.double.foo) metafunc('empty3', hofs1, fofs1, composition=True) import empty3 assert raises(AttributeError, lambda: empty3.inc._source.foo)
def test_metafunc_on_metamodules(): sys.modules['empty10'] = imp.new_module('empty10') metafunc('empty10.comp', inc, one, composition=True) import empty10.comp.inc.inc.inc assert raises(ValueError, lambda: metafunc('empty10.comp.inc', double, two, composition=True)) # It is allowed to do this on a base module as long as names don't clash # XXX: perhaps this should be a convenient way to add fofs and hofs metafunc('empty10.comp', double, [one, two, three], composition=True) import empty10 assert empty10.comp.double.double.one() == 4 assert raises(AttributeError, lambda: empty10.comp.double.inc.one()) assert raises(AttributeError, lambda: empty10.comp.inc.double.one()) assert raises(ValueError, lambda: (metafunc('empty10.comp', [inc, triple], one, composition=True))) # same tests on a hidden metamodule metafunc('empty10', inc, one, composition=True) assert raises(ValueError, lambda: metafunc('empty10.inc', double, two, composition=True)) metafunc('empty10', double, [one, two, three], composition=True) assert empty10.double.double.one() == 4 assert raises(AttributeError, lambda: empty10.double.inc.one()) assert raises(AttributeError, lambda: empty10.inc.double.one()) assert raises(ValueError, lambda: (metafunc('empty10', [inc, triple], one, composition=True)))
def test_add_fofs(): sys.modules['empty8'] = imp.new_module('empty8') metafunc('empty8.comp', inc, one, composition=True) import empty8 assert empty8.comp.inc.one() == 2 addfuncs('empty8.comp', two) assert empty8.comp.inc.two() == 3 assert empty8.comp.inc.inc.two() == 4 assert raises(ValueError, lambda: addfuncs('empty8.comp', two)) assert raises(ValueError, lambda: addfuncs('empty8.comp', inc)) assert raises(ValueError, lambda: addfuncs('empty8', three)) assert raises(ValueError, lambda: addfuncs('empty8.comp.foo.bar', three)) addfuncs('empty8.comp.inc.inc', three) assert empty8.comp.inc.three() == 4
def test_metafunc_on_metamodules(): sys.modules['empty10'] = imp.new_module('empty10') metafunc('empty10.comp', inc, one, composition=True) import empty10.comp.inc.inc.inc assert raises( ValueError, lambda: metafunc('empty10.comp.inc', double, two, composition=True)) # It is allowed to do this on a base module as long as names don't clash # XXX: perhaps this should be a convenient way to add fofs and hofs metafunc('empty10.comp', double, [one, two, three], composition=True) import empty10 assert empty10.comp.double.double.one() == 4 assert raises(AttributeError, lambda: empty10.comp.double.inc.one()) assert raises(AttributeError, lambda: empty10.comp.inc.double.one()) assert raises( ValueError, lambda: (metafunc('empty10.comp', [inc, triple], one, composition=True))) # same tests on a hidden metamodule metafunc('empty10', inc, one, composition=True) assert raises( ValueError, lambda: metafunc('empty10.inc', double, two, composition=True)) metafunc('empty10', double, [one, two, three], composition=True) assert empty10.double.double.one() == 4 assert raises(AttributeError, lambda: empty10.double.inc.one()) assert raises(AttributeError, lambda: empty10.inc.double.one()) assert raises( ValueError, lambda: (metafunc('empty10', [inc, triple], one, composition=True)))
def test_add_hofs(): sys.modules['empty9'] = imp.new_module('empty9') metafunc('empty9.comp', inc, one, composition=True) import empty9 assert empty9.comp.inc.inc.one() == 3 addmetafuncs('empty9.comp', double) assert empty9.comp.double.one() == 2 assert empty9.comp.inc.inc.inc.double.one() == 8 assert raises(ValueError, lambda: addmetafuncs('empty9.comp', double)) assert raises(ValueError, lambda: addmetafuncs('empty9.comp', one)) assert raises(ValueError, lambda: addmetafuncs('empty9', triple)) assert raises(ValueError, lambda: addmetafuncs('empty9.comp.foo.bar', triple)) addmetafuncs('empty9.comp.inc.inc', triple) assert empty9.comp.triple.one() == 3
def test_mirror_module(): sys.modules['empty1'] = imp.new_module('empty1') import empty1 as orig_empty meta_empty = metafunc('empty1', hofs1, fofs1, composition=True) import empty1 as new_empty assert orig_empty == meta_empty assert orig_empty == new_empty assert meta_empty.double.double.one() == 4 from empty1.inc.inc.double import one assert one() == 6 # don't override modules assert raises(ValueError, lambda: metafunc('empty1', hofs1, fofs1, composition=True))
def test_raises(): assert raises(ZeroDivisionError, lambda: 1 / 0) assert not raises(ZeroDivisionError, lambda: 1)
def test_fofs_and_hofs_dont_intersect(): sys.modules['empty11'] = imp.new_module('empty11') assert raises(ValueError, lambda: metafunc('empty11.comp', [one, inc], inc, composition=True))
def test_bad_module_name(): assert raises(ValueError, lambda: metafunc('zmm.foo.bar.comp', hofs1, fofs1, composition=True))
def test_fofs_and_hofs_dont_intersect(): sys.modules['empty11'] = imp.new_module('empty11') assert raises( ValueError, lambda: metafunc('empty11.comp', [one, inc], inc, composition=True))
def test_bad_module_name(): assert raises( ValueError, lambda: metafunc('zmm.foo.bar.comp', hofs1, fofs1, composition=True))