Пример #1
0
 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))
Пример #2
0
 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))
Пример #3
0
 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"))
Пример #4
0
 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"))
Пример #5
0
 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"))
Пример #6
0
 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"))
Пример #7
0
 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"))
Пример #8
0
 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"))
Пример #9
0
 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
Пример #10
0
 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)))
Пример #11
0
 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"]))
Пример #12
0
 def test001_constructor_number(self):
     m = SinonMatcher(1)
     self.assertTrue(m.mtest(1))
     self.assertFalse(m.mtest(2))
Пример #13
0
 def test51_instanceOf_instance(self):
     spy = SinonSpy()
     stub = SinonStub()
     m = SinonMatcher.instanceOf(spy)
     self.assertTrue(m.mtest(spy))
     self.assertTrue(m.mtest(stub))
Пример #14
0
 def test50_instanceOf_class(self):
     fto = ForTestOnly()
     with self.assertRaises(Exception) as context:
         m = SinonMatcher.instanceOf(ForTestOnly)
Пример #15
0
 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
Пример #16
0
 def test005_constructor_func_invalid(self):
     something = "Not Function"
     with self.assertRaises(Exception) as context:
         m = SinonMatcher(something, is_custom_func=True)
Пример #17
0
 def test41_typeOf_instance(self):
     fto = ForTestOnly()
     m = SinonMatcher.typeOf(ForTestOnly)
     self.assertFalse(m.mtest(ForTestOnly))
     self.assertTrue(m.mtest(fto))
Пример #18
0
 def test006_constructor_strcmp_invalid(self):
     something = 123
     with self.assertRaises(Exception) as context:
         m = SinonMatcher(something, strcmp="default")
Пример #19
0
 def test43_typeOf_invalid_type(self):
     with self.assertRaises(Exception) as context:
         m = SinonMatcher.typeOf(123)