def test30_same(self): m = SinonMatcher.same("100") self.assertTrue(m.mtest("100")) m = SinonMatcher.same(100) self.assertTrue(m.mtest(100)) m = SinonMatcher.same(os.system) self.assertTrue(m.mtest(os.system))
def test060_and_match(self): spy = SinonSpy() stub = SinonStub() m = SinonMatcher.instanceOf(spy).and_match( SinonMatcher.instanceOf(stub)) self.assertFalse(m.mtest(spy)) self.assertTrue(m.mtest(stub))
def test003_constructor_strcmp_regex(self): m = SinonMatcher("(\w*) (\w*)", strcmp="regex") self.assertFalse(m.mtest("match")) self.assertTrue(m.mtest("ch st")) self.assertTrue(m.mtest("match string")) self.assertTrue(m.mtest("match string++")) self.assertTrue(m.mtest("match strig"))
def test210_calledWith_Match_args(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") self.assertTrue(spy.calledWith(SinonMatcher(str))) self.assertFalse(spy.calledWith(SinonMatcher(str), SinonMatcher(int))) self.assertTrue(spy.calledWith(SinonMatcher(str), SinonMatcher(str))) self.assertTrue( spy.calledWith(SinonMatcher(str), SinonMatcher(str), "c"))
def test216_calledWith_Match_combination(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", c="c") self.assertTrue(spy.calledWith(SinonMatcher(str))) self.assertFalse(spy.calledWith(SinonMatcher(str), SinonMatcher(int))) self.assertFalse(spy.calledWith(SinonMatcher(str), b=SinonMatcher(str))) self.assertTrue( spy.calledWith(SinonMatcher(str), SinonMatcher(str), c="c"))
def test213_calledWith_Match_kwargs(self): spy = SinonSpy(C_func) sinon.g.C_func(a="a", b="b", c="c") self.assertTrue(spy.calledWith(a=SinonMatcher(str))) self.assertFalse( spy.calledWith(a=SinonMatcher(str), b=SinonMatcher(int))) self.assertTrue( spy.calledWith(a=SinonMatcher(str), b=SinonMatcher(str))) self.assertTrue( spy.calledWith(a=SinonMatcher(str), b=SinonMatcher(str), c="c"))
def test004_constructor_func(self): def custom_test_func(a, b, c): return a+b+c m = SinonMatcher(custom_test_func, is_custom_func=True) self.assertEqual(m.mtest(1,2,3), 6) m = SinonMatcher("(\w*) (\w*)", strcmp="regex") self.assertFalse(m.mtest("match"))
def test002_constructor_strcmp_string(self): m = SinonMatcher("match string", strcmp="default") self.assertTrue(m.mtest("match")) self.assertTrue(m.mtest("ch st")) self.assertTrue(m.mtest("match string")) self.assertFalse(m.mtest("match string++")) self.assertFalse(m.mtest("match strig"))
def test42_typeOf_value(self): m = SinonMatcher.typeOf(int) self.assertFalse(m.mtest("1")) # string is not a number self.assertTrue(m.mtest(1)) # number is a number
def test221_alwaysCalledWith_matcher(self): spy = SinonSpy(C_func) sinon.g.C_func("a", "b", "c") self.assertFalse(spy.alwaysCalledWith(str)) self.assertTrue(spy.alwaysCalledWith(SinonMatcher(str)))
def test061_or_match(self): m = SinonMatcher.typeOf(int).or_match(SinonMatcher.typeOf(str)) self.assertTrue(m.mtest("1")) self.assertTrue(m.mtest(1)) self.assertFalse(m.mtest()) self.assertFalse(m.mtest([1, "1"]))
def test001_constructor_number(self): m = SinonMatcher(1) self.assertTrue(m.mtest(1)) self.assertFalse(m.mtest(2))
def test51_instanceOf_instance(self): spy = SinonSpy() stub = SinonStub() m = SinonMatcher.instanceOf(spy) self.assertTrue(m.mtest(spy)) self.assertTrue(m.mtest(stub))
def test50_instanceOf_class(self): fto = ForTestOnly() with self.assertRaises(Exception) as context: m = SinonMatcher.instanceOf(ForTestOnly)
def test40_typeOf_class(self): # This is a silly test, normal condition will not use this kinda cases. fto = ForTestOnly() m = SinonMatcher.typeOf(type) self.assertTrue(m.mtest(ForTestOnly)) # class is a type self.assertFalse(m.mtest(fto)) # instance is not a type
def test005_constructor_func_invalid(self): something = "Not Function" with self.assertRaises(Exception) as context: m = SinonMatcher(something, is_custom_func=True)
def test41_typeOf_instance(self): fto = ForTestOnly() m = SinonMatcher.typeOf(ForTestOnly) self.assertFalse(m.mtest(ForTestOnly)) self.assertTrue(m.mtest(fto))
def test006_constructor_strcmp_invalid(self): something = 123 with self.assertRaises(Exception) as context: m = SinonMatcher(something, strcmp="default")
def test43_typeOf_invalid_type(self): with self.assertRaises(Exception) as context: m = SinonMatcher.typeOf(123)