def test_xxx(): with Story(test_mod) as story: obj = test_mod.Stuff(1, 2) test_mod.target(1) == 2 test_mod.target(2) == 3 test_mod.target(3) ** ValueError other = test_mod.Stuff(2, 2) obj.other('a') == other obj.meth('a') == 'x' obj = test_mod.Stuff(2, 3) obj.meth() ** ValueError('crappo') obj.meth('c') == 'x' with story.replay(recurse_lock=True, strict=False) as replay: obj = test_mod.Stuff(1, 2) obj.meth('a') test_mod.target(1) obj.meth() test_mod.func(5) obj = test_mod.Stuff(4, 4) obj.meth() for k, v in story._calls.items(): print(k, "=>", v) print("############## UNEXPECTED ##############") for k, v in replay._actual.items(): print(k, "=>", v)
def test_story_text_helpers(): with Story(test_mod) as story: obj = test_mod.Stuff(1, 2) obj.meth('a') == 'x' obj.meth('b') == 'y' obj = test_mod.Stuff(2, 3) obj.meth('c') == 'z' test_mod.target(1) == 2 test_mod.target(2) == 3 with story.replay(recurse_lock=True, strict=False) as replay: obj = test_mod.Stuff(1, 2) obj.meth('a') obj.meth() obj = test_mod.Stuff(4, 4) obj.meth() test_mod.func(5) test_mod.target(1) print (replay.missing) assert replay.missing == """stuff_1.meth('b') == 'y' # returns stuff_2 = test_pkg1.test_pkg2.test_mod.Stuff(2, 3) stuff_2.meth('c') == 'z' # returns test_pkg1.test_pkg2.test_mod.target(2) == 3 # returns """ print (replay.unexpected) assert replay.unexpected == """stuff_1.meth() == None # returns stuff_2 = test_pkg1.test_pkg2.test_mod.Stuff(4, 4) stuff_2.meth() == None # returns test_pkg1.test_pkg2.test_mod.func(5) == None # returns """ print (replay.diff) if PY26: assert replay.diff == """--- expected """ """ +++ actual """ """ @@ -1,7 +1,7 @@ stuff_1 = test_pkg1.test_pkg2.test_mod.Stuff(1, 2) stuff_1.meth('a') == 'x' # returns -stuff_1.meth('b') == 'y' # returns -stuff_2 = test_pkg1.test_pkg2.test_mod.Stuff(2, 3) -stuff_2.meth('c') == 'z' # returns +stuff_1.meth() == None # returns +stuff_2 = test_pkg1.test_pkg2.test_mod.Stuff(4, 4) +stuff_2.meth() == None # returns +test_pkg1.test_pkg2.test_mod.func(5) == None # returns test_pkg1.test_pkg2.test_mod.target(1) == 2 # returns -test_pkg1.test_pkg2.test_mod.target(2) == 3 # returns """ else: assert replay.diff == """--- expected