예제 #1
0
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
 def test_not_to_be_when_assertion_passes(self):
     expect(True).notToBe(False)
예제 #12
0
 def test_pp_of_args_and_kwargs(self):
     expect(string.pp(1, a='a')).toBe("1, a='a'")
예제 #13
0
 def test_pp_of_kwargs(self):
     expect(string.pp(a=1, b=2)).toBe("a=1, b=2")
예제 #14
0
    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
 def test_humanize_camelcase_word(self):
     expect(string.humanize("SomeOne")).toBe("some one")
     expect(string.humanize("SomeOneElse")).toBe("some one else")
예제 #16
0
 def test_to_be_when_assertion_fails(self):
     self.assertRaises(AssertionError, expect(True).toBe, False)
예제 #17
0
 def test_to_be_when_assertion_passes(self):
     expect(True).toBe(True)
예제 #18
0
 def test_not_to_be_when_assertion_fails(self):
     self.assertRaises(AssertionError, expect(True).notToBe, True)
예제 #19
0
    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
    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
    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
 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
    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
    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
    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
 def test_pp_with_no_args(self):
     expect(string.pp()).toBe("")
예제 #27
0
    def test_toBeNone(self):
        expect(None).toBeNone()
        expect('foo').notToBeNone()

        self.assertRaises(AssertionError, expect('foo').toBeNone)
        self.assertRaises(AssertionError, expect(None).notToBeNone)
예제 #28
0
 def test_pp_of_single_arg(self):
     expect(string.pp('1')).toBe("'1'")
     expect(string.pp(1)).toBe("1")