示例#1
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())
示例#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())
示例#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())
示例#4
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())
示例#5
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
示例#6
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())
示例#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())
示例#8
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())
示例#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())
示例#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())
示例#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())
示例#12
0
 def test003_arg_expectation(self):
     mock = SinonMock(os)
     exp = mock.expects("system")
     SinonAssertion.notCalled(exp)
示例#13
0
 def test011_verify_one(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1").once()
     fto = ForTestOnly()
     fto.func1()
     self.assertTrue(mock.verify())  # once condition
示例#14
0
 def test010_verify_one(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     self.assertTrue(mock.verify())  #no condition
示例#15
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")
示例#16
0
 def test005_constructor_instance(self):
     fto = ForTestOnly()
     mock = SinonMock(fto)
     expectation = mock.expects("func1")
示例#17
0
 def test002_constructor_outside_module(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
示例#18
0
 def test001_constructor_inside_module(self):
     mock = SinonMock(A_object)
     expectation = mock.expects("A_func")
示例#19
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())
示例#20
0
 def test020_never_exactly(self):
     mock = SinonMock(ForTestOnly)
     expectation = mock.expects("func1")
     fto = ForTestOnly()
     expectation.never().exactly(0)
     self.assertTrue(expectation.verify())