예제 #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)