def test_story_empty_play_proxy_class(): assert test_mod.Stuff(1, 2).mix(3, 4) == (1, 2, 3, 4) with Story(test_mod).replay(recurse_lock=True, proxy=True, strict=False) as replay: obj = test_mod.Stuff(1, 2) assert obj.mix(3, 4) == (1, 2, 3, 4) assert obj.mix('a', 'b') == (1, 2, 'a', 'b') raises(TypeError, obj.meth, 123) obj = test_mod.Stuff(0, 1) assert obj.mix('a', 'b') == (0, 1, 'a', 'b') assert obj.mix(3, 4) == (0, 1, 3, 4) raises(TypeError, obj.meth, 123) assert format_calls(replay._actual) == format_calls(OrderedDict([ ((None, 'test_pkg1.test_pkg2.test_mod.Stuff', "1, 2", ''), _Binds('stuff_1')), (('stuff_1', 'mix', "3, 4", ''), _Returns("(1, 2, 3, 4)")), (('stuff_1', 'mix', "'a', 'b'", ''), _Returns("(1, 2, 'a', 'b')")), (('stuff_1', 'meth', "123", ''), _Raises(repr_ex(TypeError( 'meth() takes exactly 1 argument (2 given)' if PY2 else 'meth() takes 1 positional argument but 2 were given' )))), ((None, 'test_pkg1.test_pkg2.test_mod.Stuff', "0, 1", ''), _Binds('stuff_2')), (('stuff_2', 'mix', "'a', 'b'", ''), _Returns("(0, 1, 'a', 'b')")), (('stuff_2', 'mix', "3, 4", ''), _Returns("(0, 1, 3, 4)")), (('stuff_2', 'meth', "123", ''), _Raises(repr_ex(TypeError( 'meth() takes exactly 1 argument (2 given)' if PY2 else 'meth() takes 1 positional argument but 2 were given' )))) ]))
def test_story_half_play_proxy_class(): assert test_mod.Stuff(1, 2).mix(3, 4) == (1, 2, 3, 4) with Story(test_mod) as story: obj = test_mod.Stuff(1, 2) obj.mix(3, 4) == (1, 2, 3, 4) with story.replay(recurse_lock=True, proxy=True, strict=False) as replay: obj = test_mod.Stuff(1, 2) assert obj.mix(3, 4) == (1, 2, 3, 4) assert obj.meth() is None raises(TypeError, obj.meth, 123) obj = test_mod.Stuff(0, 1) assert obj.mix('a', 'b') == (0, 1, 'a', 'b') assert obj.mix(3, 4) == (0, 1, 3, 4) raises(TypeError, obj.meth, 123) assert replay.unexpected == format_calls(OrderedDict([ (('stuff_1', 'meth', '', ''), _Returns('None')), (('stuff_1', 'meth', '123', ''), _Raises(repr_ex(TypeError( 'meth() takes exactly 1 argument (2 given)' if PY2 else 'meth() takes 1 positional argument but 2 were given' )))), ((None, 'test_pkg1.test_pkg2.test_mod.Stuff', '0, 1', ''), _Binds("stuff_2")), (('stuff_2', 'mix', "'a', 'b'", ''), _Returns("(0, 1, 'a', 'b')")), (('stuff_2', 'mix', '3, 4', ''), _Returns('(0, 1, 3, 4)')), (('stuff_2', 'meth', '123', ''), _Raises(repr_ex(TypeError( 'meth() takes exactly 1 argument (2 given)' if PY2 else 'meth() takes 1 positional argument but 2 were given' )))) ]))
def test_story_empty_play_proxy(): assert test_mod.target() is None raises(TypeError, test_mod.target, 123) with Story(test_mod).replay(recurse_lock=True, proxy=True, strict=False) as replay: assert test_mod.target() is None raises(TypeError, test_mod.target, 123) assert format_calls(replay._actual) == format_calls(OrderedDict([ ((None, 'test_pkg1.test_pkg2.test_mod.target', '', ''), _Returns("None")), ((None, 'test_pkg1.test_pkg2.test_mod.target', '123', ''), _Raises(repr_ex(TypeError( 'target() takes no arguments (1 given)' if PY2 else 'target() takes 0 positional arguments but 1 was given', )))) ]))
def test_story_full_play_proxy(): with Story(test_mod) as story: test_mod.target(123) == 'foobar' test_mod.target(1234) ** ValueError with story.replay(recurse_lock=True, proxy=True, strict=False) as replay: assert test_mod.target() is None assert test_mod.target(123) == 'foobar' raises(ValueError, test_mod.target, 1234) raises(TypeError, test_mod.target, 'asdf') assert replay.unexpected == format_calls(OrderedDict([ ((None, 'test_pkg1.test_pkg2.test_mod.target', '', ''), _Returns("None")), ((None, 'test_pkg1.test_pkg2.test_mod.target', "'asdf'", ''), _Raises(repr_ex(TypeError( 'target() takes no arguments (1 given)' if PY2 else 'target() takes 0 positional arguments but 1 was given',) ))) ]))