Esempio n. 1
0
 def test016_verify_once_with_returns(self):
     mock = SinonMock(ForTestOnly)
     fto = ForTestOnly()
     self.assertEqual(fto.func1(), "func1")
     expectation = mock.expects("func1").once().returns(None)  #spy + stub
     self.assertEqual(fto.func1(), None)
     self.assertTrue(mock.verify())
Esempio n. 2
0
 def test040_verify_reference_error(self):
     mock = SinonMock(ForTestOnly)
     fto = ForTestOnly()
     self.assertEqual(fto.func1(), "func1")
     expectation = mock.expects("func1").once().returns(None)  #spy + stub
     expectation.restore()
     self.assertFalse(mock.verify())
Esempio n. 3
0
 def test033_withExactArgs_kwargs(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     expectation.withArgs(opt="1")
     fto.func1(opt="1")
     self.assertTrue(expectation.verify())
Esempio n. 4
0
 def test012_verify_one(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1").twice().atLeast(1).atMost(3)
     fto = ForTestOnly()
     fto.func1()
     fto.func1()
     self.assertTrue(mock.verify())  # chain conditions
Esempio n. 5
0
 def test015_verify_once_with_throws(self):
     mock = SinonMock(ForTestOnly)
     fto = ForTestOnly()
     self.assertEqual(fto.func1(), "func1")
     expectation = mock.expects("func1").once().throws()  #spy + stub
     with self.assertRaises(Exception) as context:
         fto.func1()
     self.assertTrue(mock.verify())
Esempio n. 6
0
 def test040_withExactArgs_args(self):
     # Todo: source code use a dirty to pass this case, it should be fixed in the future
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     expectation.withExactArgs("1")
     fto.func1("1")
     self.assertTrue(expectation.verify())
Esempio n. 7
0
 def test030_withArgs_args_module(self):
     # Todo: source code use a dirty to pass this case, it should be fixed in the future
     mock = SinonMock(os)
     expectation = mock.expects("getenv")
     expectation.withArgs("SHELL")
     self.assertFalse(expectation.verify())
     os.getenv("SHELL")
     self.assertTrue(expectation.verify())
Esempio n. 8
0
 def test013_verify_multi(self):
     mock = SinonMock(ForTestOnly)
     expectation1 = mock.expects("func1").once()
     expectation2 = mock.expects("func2").atMost(1)
     fto = ForTestOnly()
     fto.func1()
     fto.func2()
     self.assertTrue(mock.verify())
Esempio n. 9
0
 def test021_once_exactly(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     expectation.once().exactly(1)
     self.assertFalse(expectation.verify())
     fto.func1()
     self.assertTrue(expectation.verify())
Esempio n. 10
0
 def test002_atMost(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     fto.func1()
     expectation.atMost(1)
     self.assertTrue(expectation.verify())
     expectation.atMost(1).atMost(2).atMost(3)
     self.assertTrue(expectation.verify())
     expectation.atMost(0)
     self.assertFalse(expectation.verify())
Esempio n. 11
0
 def test010_atLeast(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     self.assertTrue(expectation.verify())
     expectation.atLeast(0)
     self.assertTrue(expectation.verify())
     expectation.atLeast(-1)
     self.assertTrue(expectation.verify())
     expectation.atLeast(1)
     self.assertFalse(expectation.verify())
Esempio n. 12
0
 def test010_verify_one(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     self.assertTrue(mock.verify())  #no condition
Esempio n. 13
0
 def test007_constructor_redeclare_function(self):
     mock = SinonMock(A_object)
     exp1 = mock.expects("A_func")
     with self.assertRaises(Exception) as context:
         exp2 = mock.expects("A_func")
Esempio n. 14
0
 def test006_constructor_redeclare_module(self):
     mock = SinonMock(A_object)
     mock = SinonMock(A_object)  #nothing will happen
Esempio n. 15
0
 def test005_constructor_instance(self):
     fto = ForTestOnly()
     mock = SinonMock(fto)
     expectation = mock.expects("func1")
Esempio n. 16
0
 def test004_constructor_empty(self):
     mock = SinonMock()
Esempio n. 17
0
 def test003_constructor_function(self):
     with self.assertRaises(Exception) as context:
         mock = SinonMock(B_func)
Esempio n. 18
0
 def test001_constructor_inside_module(self):
     mock = SinonMock(A_object)
     expectation = mock.expects("A_func")
Esempio n. 19
0
 def test014_verify_empty(self):
     mock = SinonMock(ForTestOnly)
     self.assertTrue(mock.verify())  #no condition
Esempio n. 20
0
 def test020_never_exactly(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     expectation.never().exactly(0)
     self.assertTrue(expectation.verify())
Esempio n. 21
0
 def test011_verify_one(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1").once()
     fto = ForTestOnly()
     fto.func1()
     self.assertTrue(mock.verify())  # once condition
Esempio n. 22
0
 def test002_constructor_outside_module(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
Esempio n. 23
0
 def test003_arg_expectation(self):
     mock = SinonMock(os)
     exp = mock.expects("system")
     SinonAssertion.notCalled(exp)
Esempio n. 24
0
 def test030_verify_false(self):
     mock = SinonMock(ForTestOnly)
     fto = ForTestOnly()
     self.assertEqual(fto.func1(), "func1")
     expectation = mock.expects("func1").once().returns(None)  #spy + stub
     self.assertFalse(mock.verify())