def test013_calledTwice(self): spy = SinonSpy(os, "system") with self.assertRaises(Exception) as context: SinonAssertion.calledTwice(spy) os.system("cd") os.system("cd") SinonAssertion.calledTwice(spy)
def test006_fail_new_message(self): spy = SinonSpy(os, "system") exception_msg = "Hahaha" SinonAssertion.fail(exception_msg) with self.assertRaises(Exception) as context: SinonAssertion.called(spy) self.assertTrue(exception_msg in str(context.exception)) #test new errmsg
def test061_alwaysCalledWith_kwargs(self): spy = SinonSpy(C_func) sinon.g.C_func(a="a", b="b", c="c") sinon.g.C_func(a="xxxx", b="b", c="c") SinonAssertion.alwaysCalledWith(spy, b="b", c="c") sinon.g.C_func(a="d", b="e", c="f") with self.assertRaises(Exception) as context: SinonAssertion.alwaysCalledWith(spy, b="b", c="c")
def test060_alwaysCalledWith_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") sinon.g.C_func("a", "b", "xxxx") SinonAssertion.alwaysCalledWith(spy, "a", "b") sinon.g.C_func("d", "e", "f") with self.assertRaises(Exception) as context: SinonAssertion.alwaysCalledWith(spy, "a", "b")
def test092_alwaysCalledWithExactly_both(self): spy = SinonSpy(C_func) sinon.g.C_func("a", b="b", c="c") sinon.g.C_func("a", b="b", c="c") SinonAssertion.alwaysCalledWithExactly(spy, "a", b="b", c="c") sinon.g.C_func("a", b="b", c="xxx") with self.assertRaises(Exception) as context: SinonAssertion.alwaysCalledWithExactly(spy, "a", b="b", c="c")
def test072_neverCalledWith_both(self): spy = SinonSpy(C_func) sinon.g.C_func("a", b="b", c="c") with self.assertRaises(Exception) as context: SinonAssertion.neverCalledWith(spy, "a", b="b", c="c") SinonAssertion.neverCalledWith(spy, "a", "b", c="c") SinonAssertion.neverCalledWith(spy, "a", "b", "c") SinonAssertion.neverCalledWith(spy, "a", "b", "d") SinonAssertion.neverCalledWith(spy, "a", "b", c="d")
def test122_neverCalledWithMatch_both(self): spy = SinonSpy(C_func) sinon.g.C_func("a", b="b", c="c") with self.assertRaises(Exception) as context: SinonAssertion.neverCalledWithMatch(spy, str, b=str, c=str) SinonAssertion.neverCalledWithMatch(spy, int, int, c=int) SinonAssertion.neverCalledWithMatch(spy, int, int, int)
def test015_callCount(self): spy = SinonSpy(os, "system") SinonAssertion.callCount(spy, 0) os.system("cd") SinonAssertion.callCount(spy, 1) for i in range(10): os.system("cd") SinonAssertion.callCount(spy, 11)
def test112_alwaysCalledWithMatch_both(self): spy = SinonSpy(C_func) sinon.g.C_func("a", b="b", c="c") sinon.g.C_func("a", b="b") SinonAssertion.alwaysCalledWithMatch(spy, str, b=str) sinon.g.C_func("b", b="b", c=123) SinonAssertion.alwaysCalledWithMatch(spy, str, b=str) with self.assertRaises(Exception) as context: SinonAssertion.alwaysCalledWithMatch(spy, str, c=str)
def test111_alwaysCalledWithMatch_kwargs(self): spy = SinonSpy(C_func) sinon.g.C_func(a="a", b="b", c="c") sinon.g.C_func(a="xxxx", b="b", c="c") SinonAssertion.alwaysCalledWithMatch(spy, b=str, c=str) sinon.g.C_func(a="d", b="e", c=123) SinonAssertion.alwaysCalledWithMatch(spy, a=str, b=str) with self.assertRaises(Exception) as context: SinonAssertion.alwaysCalledWithMatch(spy, b=str, c=str)
def test110_alwaysCalledWithMatch_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") sinon.g.C_func("a", "b", "xxxx") SinonAssertion.alwaysCalledWithMatch(spy, str, str, str) sinon.g.C_func("d", "e", 123) SinonAssertion.alwaysCalledWithMatch(spy, str, str) with self.assertRaises(Exception) as context: SinonAssertion.alwaysCalledWithMatch(spy, str, str, str)
def test130_threw_default_type(self): spy = SinonSpy(D_func) # Without any exception with self.assertRaises(Exception) as context: SinonAssertion.threw(spy, ValueError) # With an exception try: sinon.g.D_func(err=ValueError) except: SinonAssertion.threw(spy) SinonAssertion.threw(spy, ValueError)
def test131_threw_custom_type(self): class MyException(Exception): pass spy = SinonSpy(D_func) # Without any exception with self.assertRaises(Exception) as context: SinonAssertion.threw(spy, MyException) # With an exception try: sinon.g.D_func(err=MyException) except: SinonAssertion.threw(spy) SinonAssertion.threw(spy, MyException)
def test140_alwaysThrew_default_type(self): spy = SinonSpy(D_func) with self.assertRaises(Exception) as context: SinonAssertion.alwaysThrew(spy) with self.assertRaises(Exception) as context: SinonAssertion.alwaysThrew(spy, ValueError) # With exceptions try: sinon.g.D_func(err=ValueError) except: SinonAssertion.alwaysThrew(spy) SinonAssertion.alwaysThrew(spy, ValueError) try: sinon.g.D_func(err=ValueError) except: SinonAssertion.alwaysThrew(spy) SinonAssertion.alwaysThrew(spy, ValueError) # With a new exception try: sinon.g.D_func(err=TypeError) except: SinonAssertion.alwaysThrew(spy) with self.assertRaises(Exception) as context: SinonAssertion.alwaysThrew(spy, ValueError)
def test132_threw_no_error(self): spy = SinonSpy(D_func) sinon.g.D_func(err=False) with self.assertRaises(Exception) as context: SinonAssertion.threw(spy)
def test001_arg_spy(self): spy = SinonSpy(os, "system") SinonAssertion.notCalled(spy)
def test081_calledWithExactly_kwargs(self): spy = SinonSpy(C_func) sinon.g.C_func(a="a", b="b", c="c") SinonAssertion.calledWithExactly(spy, a="a", b="b", c="c") with self.assertRaises(Exception) as context: SinonAssertion.calledWithExactly(spy, a="d", b="e", c="f")
def test070_neverCalledWith_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") with self.assertRaises(Exception) as context: SinonAssertion.neverCalledWith(spy, "a", "b", "c") SinonAssertion.neverCalledWith(spy, "a", "wrong", "c")
def test004_arg_string(self): with self.assertRaises(Exception) as context: SinonAssertion.notCalled("1234")
def test120_neverCalledWithMatch_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") with self.assertRaises(Exception) as context: SinonAssertion.neverCalledWithMatch(spy, str, str, str) SinonAssertion.neverCalledWithMatch(spy, int, int, int)
def test080_calledWithExactly_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") SinonAssertion.calledWithExactly(spy, "a", "b", "c") with self.assertRaises(Exception) as context: SinonAssertion.calledWithExactly(spy, "d", "e", "f")
def test0102_calledWithMatch_both(self): spy = SinonSpy(C_func) sinon.g.C_func("a", b="b", c="c") SinonAssertion.calledWithMatch(spy, str, b=str, c=str) SinonAssertion.calledWithMatch(spy, str, b=str) SinonAssertion.calledWithMatch(spy, str, c=str) SinonAssertion.calledWithMatch(spy, b=str, c=str) with self.assertRaises(Exception) as context: SinonAssertion.calledWithMatch(spy, str, str, c=str) with self.assertRaises(Exception) as context: SinonAssertion.calledWithMatch(spy, str, str, str)
def test100_calledWithMatch_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") SinonAssertion.calledWithMatch(spy, str, str, "c") SinonAssertion.calledWithMatch(spy, str, str) SinonAssertion.calledWithMatch(spy, str) with self.assertRaises(Exception) as context: SinonAssertion.calledWithMatch(spy, "a", "wrong", "c") with self.assertRaises(Exception) as context: SinonAssertion.calledWithMatch(spy, int, "b", "c") with self.assertRaises(Exception) as context: SinonAssertion.calledWithMatch(spy, str, int)
def test002_arg_stub(self): stub = SinonStub(os, "system") SinonAssertion.notCalled(stub)
def test003_arg_expectation(self): mock = SinonMock(os) exp = mock.expects("system") SinonAssertion.notCalled(exp)
def test121_neverCalledWithMatch_kwargs(self): spy = SinonSpy(C_func) sinon.g.C_func(a="a", b="b", c="c") with self.assertRaises(Exception) as context: SinonAssertion.neverCalledWithMatch(spy, a=str, b=str, c=str) SinonAssertion.neverCalledWithMatch(spy, a=int, b=str, c=str)
def test005_arg_bool(self): with self.assertRaises(Exception) as context: SinonAssertion.notCalled(True)
def test071_neverCalledWith_kwargs(self): spy = SinonSpy(C_func) sinon.g.C_func(a="a", b="b", c="c") with self.assertRaises(Exception) as context: SinonAssertion.neverCalledWith(spy, a="a", b="b", c="c") SinonAssertion.neverCalledWith(spy, a="wrong", b="b", c="c")
def test010_notCalled(self): spy = SinonSpy(os, "system") SinonAssertion.notCalled(spy) os.system("cd") with self.assertRaises(Exception) as context: SinonAssertion.notCalled(spy)
def test082_calledWithExactly_both(self): spy = SinonSpy(C_func) sinon.g.C_func("a", b="b", c="c") SinonAssertion.calledWithExactly(spy, "a", b="b", c="c") with self.assertRaises(Exception) as context: SinonAssertion.calledWithExactly(spy, "wrong", b="b", c="c")