コード例 #1
0
ファイル: test_matchers.py プロジェクト: endeepak/pungi
    def test_toHaveBeenCalledTimes(self):
        obj = TempClass()
        spyOn(obj, "hello")

        obj.hello()
        obj.hello()

        expect(obj.hello).toHaveBeenCalled(times=2)
        self.assertRaises(AssertionError, expect(obj.hello).toHaveBeenCalled, times=1)
コード例 #2
0
ファイル: test_matchers.py プロジェクト: endeepak/pungi
    def test_ToRaiseExceptionWithMessage(self):
        def raise_ex():
            raise CustomException("<(^_^)>")

        def dont_raise_ex():
            pass

        expect(raise_ex).toRaise(Exception, "<(^_^)>")
        expect(dont_raise_ex).notToRaise(Exception)

        self.assertRaises(AssertionError, expect(dont_raise_ex).toRaise, Exception, "<(^_^)>")
        self.assertRaises(AssertionError, expect(raise_ex).toRaise, Exception, "[(-.-)]")
        self.assertRaises(AssertionError, expect(raise_ex).notToRaise, Exception)
コード例 #3
0
ファイル: test_matchers.py プロジェクト: endeepak/pungi
    def test_toHaveBeenCalled(self):
        obj = TempClass()
        spyOn(obj, "hello")
        spyOn(obj, "hi")
        obj.hello()

        expect(obj.hello).toHaveBeenCalled()
        expect(obj.hi).notToHaveBeenCalled()

        self.assertRaises(AssertionError, expect(obj.hello).notToHaveBeenCalled)
        self.assertRaises(AssertionError, expect(obj.hi).toHaveBeenCalled)
コード例 #4
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_ToRaise(self):
        def raise_ex():
            raise CustomException

        def dont_raise_ex():
            pass

        expect(raise_ex).toRaise()
        expect(dont_raise_ex).notToRaise()

        self.assertRaises(AssertionError, expect(dont_raise_ex).toRaise)
        self.assertRaises(AssertionError, expect(raise_ex).notToRaise)
コード例 #5
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toHaveBeenCalledBefore(self):
        obj = TempClass()
        spyOn(obj, 'hello')
        spyOn(obj, 'hi')

        obj.hi()
        obj.hello()

        expect(obj.hi).toHaveBeenCalledBefore(obj.hello)
        expect(obj.hello).notToHaveBeenCalledBefore(obj.hi)

        self.assertRaises(AssertionError,
                          expect(obj.hi).notToHaveBeenCalledBefore, obj.hello)
        self.assertRaises(AssertionError,
                          expect(obj.hello).toHaveBeenCalledBefore, obj.hi)
コード例 #6
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toContain_for_String(self):
        expect("abcd").toContain("b")
        expect("abcd").notToContain("f")

        self.assertRaises(AssertionError, expect("abcd").toContain, "f")
        self.assertRaises(AssertionError, expect("abcd").notToContain, "b")
コード例 #7
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toContain_for_Array(self):
        expect([1, 2, 3]).toContain(2)
        expect([1, 2, 3]).notToContain(4)

        self.assertRaises(AssertionError, expect([1, 2, 3]).toContain, 4)
        self.assertRaises(AssertionError, expect([1, 2, 3]).notToContain, 2)
コード例 #8
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toBeFalsy(self):
        expect(True).notToBeFalsy()
        expect(1).notToBeFalsy()
        expect('foo').notToBeFalsy()
        expect([False]).notToBeFalsy()
        expect({'foo': False}).notToBeFalsy()
        expect(False).toBeFalsy()
        expect(None).toBeFalsy()
        expect(0).toBeFalsy()
        expect('').toBeFalsy()
        expect([]).toBeFalsy()
        expect({}).toBeFalsy()

        self.assertRaises(AssertionError, expect(True).toBeFalsy)
        self.assertRaises(AssertionError, expect('foo').toBeFalsy)
        self.assertRaises(AssertionError, expect([False]).toBeFalsy)
        self.assertRaises(AssertionError, expect({'foo': False}).toBeFalsy)
        self.assertRaises(AssertionError, expect(False).notToBeFalsy)
        self.assertRaises(AssertionError, expect(None).notToBeFalsy)
        self.assertRaises(AssertionError, expect(0).notToBeFalsy)
        self.assertRaises(AssertionError, expect('').notToBeFalsy)
        self.assertRaises(AssertionError, expect([]).notToBeFalsy)
        self.assertRaises(AssertionError, expect({}).notToBeFalsy)
コード例 #9
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toMatch(self):
        expect("abcd").toMatch(".*b.*")
        expect("abcd").notToMatch(".*g.*")

        self.assertRaises(AssertionError, expect("abcd").toMatch, ".*g.*")
        self.assertRaises(AssertionError, expect("abcd").notToMatch, ".*b.*")
コード例 #10
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toHaveBeenCalledWith(self):
        obj = TempClass()
        spyOn(obj, 'hello')
        spyOn(obj, 'hi')
        obj.hello(1, to=2)

        expect(obj.hello).toHaveBeenCalledWith(1, to=2)
        expect(obj.hello).toHaveBeenCalledWith(Any(int), to=Any(int))
        expect(obj.hi).notToHaveBeenCalledWith(1, to=2)
        expect(obj.hi).notToHaveBeenCalledWith(Any(bool), to=Any(bool))

        self.assertRaises(AssertionError,
                          expect(obj.hello).notToHaveBeenCalledWith, 1, to=2)
        self.assertRaises(AssertionError,
                          expect(obj.hello).notToHaveBeenCalledWith, Any(int),
                          to=Any(int))
        self.assertRaises(AssertionError,
                          expect(obj.hi).toHaveBeenCalledWith, 1, to=2)
        self.assertRaises(AssertionError,
                          expect(obj.hi).toHaveBeenCalledWith, Any(bool),
                          to=Any(bool))
コード例 #11
0
ファイル: test_expect.py プロジェクト: endeepak/pungi
 def test_not_to_be_when_assertion_passes(self):
     expect(True).notToBe(False)
コード例 #12
0
ファイル: test_string.py プロジェクト: endeepak/pungi
 def test_pp_of_args_and_kwargs(self):
     expect(string.pp(1, a='a')).toBe("1, a='a'")
コード例 #13
0
ファイル: test_string.py プロジェクト: endeepak/pungi
 def test_pp_of_kwargs(self):
     expect(string.pp(a=1, b=2)).toBe("a=1, b=2")
コード例 #14
0
ファイル: test_matchers.py プロジェクト: endeepak/pungi
    def test_toBe(self):
        obj = CustomException("Test")
        obj.data = {"foo": [{"bar": [True]}]}
        ex = CustomException("Test")
        ex.data = {"foo": [{"bar": [True]}]}

        expect(True).toBe(True)
        expect(obj).toBe(obj)
        expect(True).notToBe(False)
        expect(True).notToBe(1)
        expect(obj).notToBe(ex)
        expect(True).notToBe(any(bool))

        self.assertRaises(AssertionError, expect(True).toBe, False)
        self.assertRaises(AssertionError, expect(True).toBe, 1)
        self.assertRaises(AssertionError, expect(obj).toBe, ex)
        self.assertRaises(AssertionError, expect(True).toBe, any(bool))
        self.assertRaises(AssertionError, expect(True).notToBe, True)
        self.assertRaises(AssertionError, expect(obj).notToBe, obj)
コード例 #15
0
ファイル: test_string.py プロジェクト: endeepak/pungi
 def test_humanize_camelcase_word(self):
     expect(string.humanize("SomeOne")).toBe("some one")
     expect(string.humanize("SomeOneElse")).toBe("some one else")
コード例 #16
0
ファイル: test_expect.py プロジェクト: endeepak/pungi
 def test_to_be_when_assertion_fails(self):
     self.assertRaises(AssertionError, expect(True).toBe, False)
コード例 #17
0
ファイル: test_expect.py プロジェクト: endeepak/pungi
 def test_to_be_when_assertion_passes(self):
     expect(True).toBe(True)
コード例 #18
0
ファイル: test_expect.py プロジェクト: endeepak/pungi
 def test_not_to_be_when_assertion_fails(self):
     self.assertRaises(AssertionError, expect(True).notToBe, True)
コード例 #19
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toBeLessThan(self):
        expect(1).toBeLessThan(2)
        expect(2).notToBeLessThan(1)

        self.assertRaises(AssertionError, expect(2).toBeLessThan, 1)
        self.assertRaises(AssertionError, expect(1).notToBeLessThan, 2)
コード例 #20
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toEqual(self):
        obj1 = CustomException('Test')
        obj1.data = {'foo': [{'bar': [True]}]}
        obj2 = CustomException('test')
        obj2.data = {'foo': [{'bar': [True]}]}
        obj3 = CustomException('Test')
        obj3.data = {'foo': [{'bar': [1]}]}
        ex = CustomException('Test')
        ex.data = {'foo': [{'bar': [True]}]}

        expect(True).toEqual(True)
        expect('foo').toEqual('foo')
        expect([True, False]).toEqual([True, False])
        expect([[True]]).toEqual([[True]])
        expect({'foo': [{'bar': [True]}]}).toEqual({'foo': [{'bar': [True]}]})
        expect(obj1).toEqual(ex)
        expect([True]).toEqual([Any(bool)])
        expect(True).notToEqual(False)
        expect('foo').notToEqual('bar')
        expect({'foo': [{'bar': [True]}]}).notToEqual(\
                {'foo': [{'bar': [False]}]})
        expect([True, False]).notToEqual([False, True])
        expect([True, False]).notToEqual([1, 0])
        expect([[True]]).notToEqual([[False]])
        expect(CustomException('Test')).notToEqual(ex)
        expect(obj2).notToEqual(ex)
        expect(obj3).notToEqual(ex)
        expect(True).notToEqual(Any(int))

        self.assertRaises(AssertionError, expect(True).toEqual, False)
        self.assertRaises(AssertionError, expect('foo').toEqual, 'bar')
        self.assertRaises(AssertionError,
                expect({'foo': [{'bar': [True]}]}).toEqual,
                {'foo': [{'bar': [False]}]})
        self.assertRaises(AssertionError,
                expect([True, False]).toEqual, [False, True])
        self.assertRaises(AssertionError, expect([True, False]).toEqual, [1, 0])
        self.assertRaises(AssertionError, expect([[True]]).toEqual, [[False]])
        self.assertRaises(AssertionError,
                expect(CustomException('Test')).toEqual, ex)
        self.assertRaises(AssertionError, expect(obj2).toEqual, ex)
        self.assertRaises(AssertionError, expect(obj3).toEqual, ex)
        self.assertRaises(AssertionError, expect(True).toEqual, Any(int))
        self.assertRaises(AssertionError, expect(True).notToEqual, True)
        self.assertRaises(AssertionError,
                expect([True, False]).notToEqual, [True, False])
        self.assertRaises(AssertionError, expect('foo').notToEqual, 'foo')
        self.assertRaises(AssertionError, expect([[True]]).notToEqual, [[True]])
        self.assertRaises(AssertionError,
                expect({'foo': [{'bar': [True]}]}).notToEqual,
                {'foo': [{'bar': [True]}]})
        self.assertRaises(AssertionError, expect(obj1).notToEqual, ex)
        self.assertRaises(AssertionError,
                expect([True]).notToEqual, [Any(bool)])
コード例 #21
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toBe(self):
        obj = CustomException('Test')
        obj.data = {'foo': [{'bar': [True]}]}
        ex = CustomException('Test')
        ex.data = {'foo': [{'bar': [True]}]}

        expect(True).toBe(True)
        expect(obj).toBe(obj)
        expect(True).notToBe(False)
        expect(True).notToBe(1)
        expect(obj).notToBe(ex)
        expect(True).notToBe(Any(bool))

        self.assertRaises(AssertionError, expect(True).toBe, False)
        self.assertRaises(AssertionError, expect(True).toBe, 1)
        self.assertRaises(AssertionError, expect(obj).toBe, ex)
        self.assertRaises(AssertionError, expect(True).toBe, Any(bool))
        self.assertRaises(AssertionError, expect(True).notToBe, True)
        self.assertRaises(AssertionError, expect(obj).notToBe, obj)
コード例 #22
0
ファイル: test_string.py プロジェクト: endeepak/pungi
 def test_pp_of_multiple_args(self):
     expect(string.pp(1, 2)).toBe("1, 2")
     expect(string.pp(1, [2, 3])).toBe("1, [2, 3]")
コード例 #23
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_ToRaiseExceptionInstance(self):
        def raise_ex():
            ex = CustomException("<(^_^)>")
            ex.code = 1
            raise ex

        def dont_raise_ex():
            pass

        class TempException(Exception):
            pass

        ex = CustomException("<(^_^)>")
        ex.code = 1
        e = Exception("<(^_^)>")
        e.code = 1
        temp_ex = TempException("<(^_^)>")
        temp_ex.code = 1
        expect(raise_ex).toRaise(ex)
        expect(raise_ex).toRaise(e)
        expect(dont_raise_ex).notToRaise(ex)
        expect(raise_ex).notToRaise(temp_ex)
        expect(raise_ex).notToRaise(CustomException("<(^_^)>"))

        self.assertRaises(AssertionError, expect(dont_raise_ex).toRaise, ex)
        self.assertRaises(AssertionError, expect(raise_ex).toRaise, temp_ex)
        self.assertRaises(AssertionError, expect(raise_ex).toRaise,
                                                    CustomException("<(^_^)>"))
        self.assertRaises(AssertionError, expect(raise_ex).notToRaise, ex)
        self.assertRaises(AssertionError, expect(raise_ex).notToRaise, e)
コード例 #24
0
ファイル: test_matchers.py プロジェクト: endeepak/pungi
    def test_toBeTruthy(self):
        expect(True).toBeTruthy()
        expect(1).toBeTruthy()
        expect("foo").toBeTruthy()
        expect([False]).toBeTruthy()
        expect({"foo": False}).toBeTruthy()
        expect(False).notToBeTruthy()
        expect(None).notToBeTruthy()
        expect(0).notToBeTruthy()
        expect("").notToBeTruthy()
        expect([]).notToBeTruthy()
        expect({}).notToBeTruthy()

        self.assertRaises(AssertionError, expect(False).toBeTruthy)
        self.assertRaises(AssertionError, expect(None).toBeTruthy)
        self.assertRaises(AssertionError, expect(0).toBeTruthy)
        self.assertRaises(AssertionError, expect("").toBeTruthy)
        self.assertRaises(AssertionError, expect([]).toBeTruthy)
        self.assertRaises(AssertionError, expect({}).toBeTruthy)
        self.assertRaises(AssertionError, expect(True).notToBeTruthy)
        self.assertRaises(AssertionError, expect("foo").notToBeTruthy)
        self.assertRaises(AssertionError, expect([False]).notToBeTruthy)
        self.assertRaises(AssertionError, expect({"foo": False}).notToBeTruthy)
コード例 #25
0
ファイル: test_matchers.py プロジェクト: endeepak/pungi
    def test_toEqual(self):
        obj1 = CustomException("Test")
        obj1.data = {"foo": [{"bar": [True]}]}
        obj2 = CustomException("test")
        obj2.data = {"foo": [{"bar": [True]}]}
        obj3 = CustomException("Test")
        obj3.data = {"foo": [{"bar": [1]}]}
        ex = CustomException("Test")
        ex.data = {"foo": [{"bar": [True]}]}

        expect(True).toEqual(True)
        expect("foo").toEqual("foo")
        expect([True, False]).toEqual([True, False])
        expect([[True]]).toEqual([[True]])
        expect({"foo": [{"bar": [True]}]}).toEqual({"foo": [{"bar": [True]}]})
        expect(obj1).toEqual(ex)
        expect([True]).toEqual([any(bool)])
        expect(True).notToEqual(False)
        expect("foo").notToEqual("bar")
        expect({"foo": [{"bar": [True]}]}).notToEqual({"foo": [{"bar": [False]}]})
        expect([True, False]).notToEqual([False, True])
        expect([True, False]).notToEqual([1, 0])
        expect([[True]]).notToEqual([[False]])
        expect(CustomException("Test")).notToEqual(ex)
        expect(obj2).notToEqual(ex)
        expect(obj3).notToEqual(ex)
        expect(True).notToEqual(any(int))

        self.assertRaises(AssertionError, expect(True).toEqual, False)
        self.assertRaises(AssertionError, expect("foo").toEqual, "bar")
        self.assertRaises(AssertionError, expect({"foo": [{"bar": [True]}]}).toEqual, {"foo": [{"bar": [False]}]})
        self.assertRaises(AssertionError, expect([True, False]).toEqual, [False, True])
        self.assertRaises(AssertionError, expect([True, False]).toEqual, [1, 0])
        self.assertRaises(AssertionError, expect([[True]]).toEqual, [[False]])
        self.assertRaises(AssertionError, expect(CustomException("Test")).toEqual, ex)
        self.assertRaises(AssertionError, expect(obj2).toEqual, ex)
        self.assertRaises(AssertionError, expect(obj3).toEqual, ex)
        self.assertRaises(AssertionError, expect(True).toEqual, any(int))
        self.assertRaises(AssertionError, expect(True).notToEqual, True)
        self.assertRaises(AssertionError, expect([True, False]).notToEqual, [True, False])
        self.assertRaises(AssertionError, expect("foo").notToEqual, "foo")
        self.assertRaises(AssertionError, expect([[True]]).notToEqual, [[True]])
        self.assertRaises(AssertionError, expect({"foo": [{"bar": [True]}]}).notToEqual, {"foo": [{"bar": [True]}]})
        self.assertRaises(AssertionError, expect(obj1).notToEqual, ex)
        self.assertRaises(AssertionError, expect([True]).notToEqual, [any(bool)])
コード例 #26
0
ファイル: test_string.py プロジェクト: endeepak/pungi
 def test_pp_with_no_args(self):
     expect(string.pp()).toBe("")
コード例 #27
0
ファイル: test_matchers.py プロジェクト: logeen/pungi
    def test_toBeNone(self):
        expect(None).toBeNone()
        expect('foo').notToBeNone()

        self.assertRaises(AssertionError, expect('foo').toBeNone)
        self.assertRaises(AssertionError, expect(None).notToBeNone)
コード例 #28
0
ファイル: test_string.py プロジェクト: endeepak/pungi
 def test_pp_of_single_arg(self):
     expect(string.pp('1')).toBe("'1'")
     expect(string.pp(1)).toBe("1")