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())
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())
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())
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
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())
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())
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())
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())
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())
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())
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())
def test010_verify_one(self): mock = SinonMock(ForTestOnly) expectation = mock.expects("func1") fto = ForTestOnly() self.assertTrue(mock.verify()) #no condition
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")
def test006_constructor_redeclare_module(self): mock = SinonMock(A_object) mock = SinonMock(A_object) #nothing will happen
def test005_constructor_instance(self): fto = ForTestOnly() mock = SinonMock(fto) expectation = mock.expects("func1")
def test004_constructor_empty(self): mock = SinonMock()
def test003_constructor_function(self): with self.assertRaises(Exception) as context: mock = SinonMock(B_func)
def test001_constructor_inside_module(self): mock = SinonMock(A_object) expectation = mock.expects("A_func")
def test014_verify_empty(self): mock = SinonMock(ForTestOnly) self.assertTrue(mock.verify()) #no condition
def test020_never_exactly(self): mock = SinonMock(ForTestOnly) expectation = mock.expects("func1") fto = ForTestOnly() expectation.never().exactly(0) self.assertTrue(expectation.verify())
def test011_verify_one(self): mock = SinonMock(ForTestOnly) expectation = mock.expects("func1").once() fto = ForTestOnly() fto.func1() self.assertTrue(mock.verify()) # once condition
def test002_constructor_outside_module(self): mock = SinonMock(ForTestOnly) expectation = mock.expects("func1")
def test003_arg_expectation(self): mock = SinonMock(os) exp = mock.expects("system") SinonAssertion.notCalled(exp)
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())