Beispiel #1
0
 def test_eq(self):
     self.assertEqual(1, any(int))
     self.assertEqual(True, any(bool))
     self.assertEqual(1.1, any(float))
     self.assertEqual('1', any(str))
     self.assertEqual({}, any(dict))
     self.assertEqual([1], any(list))
     self.assertNotEqual(True, any(int))
     self.assertNotEqual('1', any(int))
Beispiel #2
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)])
Beispiel #3
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)
Beispiel #4
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(1, to=any(int))
        expect(obj.hello).toHaveBeenCalledWith(any(int), 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))