def testEqualityNamedParamsNotEqual(self): """Methods with the same name and diffnamed params should not be equal.""" expected_method = mox.MockMethod("testMethod", [], False) expected_method._named_params = {"input1": "test", "input2": "params"} self.mock_method._named_params = {"input1": "test2", "input2": "params2"} self.failIfEqual(self.mock_method, expected_method)
def testEqualityParamsNotEqual(self): """Methods with the same name and different params should not be equal.""" expected_method = mox.MockMethod("testMethod", [], False) expected_method._params = [1, 2, 3] self.mock_method._params = ['a', 'b', 'c'] self.failIfEqual(self.mock_method, expected_method)
def testNoParameters(self): method = mox.MockMethod('NoParameters', [], False, CheckCallTestClass.NoParameters) method() self.assertRaises(AttributeError, method, 1) self.assertRaises(AttributeError, method, 1, 2) self.assertRaises(AttributeError, method, a=1) self.assertRaises(AttributeError, method, 1, b=2)
def testManyErrors(self): method1 = mox.MockMethod("testMethod", [], False) method1(1, 2).AndReturn('output') method2 = mox.MockMethod("testMethod", [], False) method2(a=1, b=2, c="only named") method3 = mox.MockMethod("testMethod2", [], False) method3().AndReturn(44) method4 = mox.MockMethod("testMethod", [], False) method4(1, 2).AndReturn('output') e = mox.ExpectedMethodCallsError([method1, method2, method3, method4]) self.assertEqual( "Verify: Expected methods never called:\n" " 0. testMethod(1, 2) -> 'output'\n" " 1. testMethod(a=1, b=2, c='only named') -> None\n" " 2. testMethod2() -> 44\n" " 3. testMethod(1, 2) -> 'output'", str(e))
def testOneError(self): method = mox.MockMethod("testMethod", [], False) method(1, 2).AndReturn('output') e = mox.ExpectedMethodCallsError([method]) self.assertEqual( "Verify: Expected methods never called:\n" " 0. testMethod(1, 2) -> 'output'", str(e))
def testEqualityNamedParamsEqual(self): """Methods with the same name and same named params should be equal.""" named_params = {"input1": "test", "input2": "params"} expected_method = mox.MockMethod("testMethod", [], False) expected_method._named_params = named_params self.mock_method._named_params = named_params self.assertEqual(self.mock_method, expected_method)
def testEqualityParamsEqual(self): """Methods with the same name and parameters should be equal.""" params = [1, 2, 3] expected_method = mox.MockMethod("testMethod", [], False) expected_method._params = params self.mock_method._params = params self.assertEqual(self.mock_method, expected_method)
def testStrConversion(self): method = mox.MockMethod("f", [], False) method(1, 2, "st", n1=8, n2="st2") self.assertEqual(str(method), ("f(1, 2, 'st', n1=8, n2='st2') -> None")) method = mox.MockMethod("testMethod", [], False) method(1, 2, "only positional") self.assertEqual(str(method), "testMethod(1, 2, 'only positional') -> None") method = mox.MockMethod("testMethod", [], False) method(a=1, b=2, c="only named") self.assertEqual(str(method), "testMethod(a=1, b=2, c='only named') -> None") method = mox.MockMethod("testMethod", [], False) method() self.assertEqual(str(method), "testMethod() -> None") method = mox.MockMethod("testMethod", [], False) method(x="only 1 parameter") self.assertEqual(str(method), "testMethod(x='only 1 parameter') -> None") method = mox.MockMethod("testMethod", [], False) method().AndReturn('return_value') self.assertEqual(str(method), "testMethod() -> 'return_value'") method = mox.MockMethod("testMethod", [], False) method().AndReturn(('a', {1: 2})) self.assertEqual(str(method), "testMethod() -> ('a', {1: 2})")
def testOneDefaultValue(self): method = mox.MockMethod('OneDefaultValue', [], False, CheckCallTestClass.OneDefaultValue) method() method(1) method(a=1) self.assertRaises(AttributeError, method, b=1) self.assertRaises(AttributeError, method, 1, 2) self.assertRaises(AttributeError, method, 1, a=2) self.assertRaises(AttributeError, method, 1, b=2)
def testArgs(self): method = mox.MockMethod('Args', [], False, CheckCallTestClass.Args) self.assertRaises(AttributeError, method) self.assertRaises(AttributeError, method, 1) method(1, 2) method(a=1, b=2) method(1, 2, 3) method(1, 2, 3, 4) self.assertRaises(AttributeError, method, 1, 2, a=3) self.assertRaises(AttributeError, method, 1, 2, c=3)
def testOneParameter(self): method = mox.MockMethod('OneParameter', [], False, CheckCallTestClass.OneParameter) self.assertRaises(AttributeError, method) method(1) method(a=1) self.assertRaises(AttributeError, method, b=1) self.assertRaises(AttributeError, method, 1, 2) self.assertRaises(AttributeError, method, 1, a=2) self.assertRaises(AttributeError, method, 1, b=2)
def testObjectEquality(self): """Equality of objects should work without a Comparator""" instA = TestClass(); instB = TestClass(); params = [instA, ] expected_method = mox.MockMethod("testMethod", [], False) expected_method._params = params self.mock_method._params = [instB, ] self.assertEqual(self.mock_method, expected_method)
def testKwargs(self): method = mox.MockMethod('Kwargs', [], False, CheckCallTestClass.Kwargs) self.assertRaises(AttributeError, method) method(1) method(1, 2) method(a=1, b=2) method(b=2, a=1) self.assertRaises(AttributeError, method, 1, 2, 3) self.assertRaises(AttributeError, method, 1, 2, a=3) method(1, 2, c=3) method(a=1, b=2, c=3) method(c=3, a=1, b=2) method(a=1, b=2, c=3, d=4) self.assertRaises(AttributeError, method, 1, 2, 3, 4)
def testTwoParameters(self): method = mox.MockMethod('TwoParameters', [], False, CheckCallTestClass.TwoParameters) self.assertRaises(AttributeError, method) self.assertRaises(AttributeError, method, 1) self.assertRaises(AttributeError, method, a=1) self.assertRaises(AttributeError, method, b=1) method(1, 2) method(1, b=2) method(a=1, b=2) method(b=2, a=1) self.assertRaises(AttributeError, method, b=2, c=3) self.assertRaises(AttributeError, method, a=1, b=2, c=3) self.assertRaises(AttributeError, method, 1, 2, 3) self.assertRaises(AttributeError, method, 1, 2, 3, 4) self.assertRaises(AttributeError, method, 3, a=1, b=2)
def testTwoDefaultValues(self): method = mox.MockMethod('TwoDefaultValues', [], False, CheckCallTestClass.TwoDefaultValues) self.assertRaises(AttributeError, method) self.assertRaises(AttributeError, method, c=3) self.assertRaises(AttributeError, method, 1) self.assertRaises(AttributeError, method, 1, d=4) self.assertRaises(AttributeError, method, 1, d=4, c=3) method(1, 2) method(a=1, b=2) method(1, 2, 3) method(1, 2, 3, 4) method(1, 2, c=3) method(1, 2, c=3, d=4) method(1, 2, d=4, c=3) method(d=4, c=3, a=1, b=2) self.assertRaises(AttributeError, method, 1, 2, 3, 4, 5) self.assertRaises(AttributeError, method, 1, 2, e=9) self.assertRaises(AttributeError, method, a=1, b=2, e=9)
def setUp(self): self.expected_method = mox.MockMethod("testMethod", [], False)(['original']) self.mock_method = mox.MockMethod("testMethod", [self.expected_method], True)
def testEqualityNoParamsEqual(self): """Methods with the same name and without params should be equal.""" expected_method = mox.MockMethod("testMethod", [], False) self.assertEqual(self.mock_method, expected_method)
def testEqualityNoParamsNotEqual(self): """Methods with different names and without params should not be equal.""" expected_method = mox.MockMethod("otherMethod", [], False) self.failIfEqual(self.mock_method, expected_method)