Esempio n. 1
0
 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)
Esempio n. 2
0
 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
Esempio n. 3
0
 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")
Esempio n. 4
0
 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")
Esempio n. 5
0
 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")
Esempio n. 6
0
 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")
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
    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)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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)
Esempio n. 15
0
 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)
Esempio n. 16
0
 def test001_arg_spy(self):
     spy = SinonSpy(os, "system")
     SinonAssertion.notCalled(spy)
Esempio n. 17
0
 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")
Esempio n. 18
0
 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")
Esempio n. 19
0
 def test004_arg_string(self):
     with self.assertRaises(Exception) as context:
         SinonAssertion.notCalled("1234")
Esempio n. 20
0
 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)
Esempio n. 21
0
 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")
Esempio n. 22
0
 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)
Esempio n. 23
0
 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)
Esempio n. 24
0
 def test002_arg_stub(self):
     stub = SinonStub(os, "system")
     SinonAssertion.notCalled(stub)
Esempio n. 25
0
 def test003_arg_expectation(self):
     mock = SinonMock(os)
     exp = mock.expects("system")
     SinonAssertion.notCalled(exp)
Esempio n. 26
0
 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)
Esempio n. 27
0
 def test005_arg_bool(self):
     with self.assertRaises(Exception) as context:
         SinonAssertion.notCalled(True)
Esempio n. 28
0
 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")
Esempio n. 29
0
 def test010_notCalled(self):
     spy = SinonSpy(os, "system")
     SinonAssertion.notCalled(spy)
     os.system("cd")
     with self.assertRaises(Exception) as context:
         SinonAssertion.notCalled(spy)
Esempio n. 30
0
 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")