Пример #1
0
    def test_cmp_obj_attrs(self):
        """Test cmp_obj_attrs."""

        # pylint: disable=attribute-defined-outside-init

        class O(object):
            pass

        a = O()
        a.b = 1
        a.c = 2

        a1 = O()
        a1.b = 1
        a1.c = 2

        b = O()
        b.b = 1
        b.c = 3

        # a class should have it's own attributes
        assert util.cmp_obj_attrs(a, a, ["b", "c"])
        assert util.cmp_obj_attrs(a1, a1, ["b", "c"])
        assert util.cmp_obj_attrs(b, b, ["b", "c"])

        # a and a1 should have the same attributes
        assert util.cmp_obj_attrs(a, a1, ["b", "c"])
        assert util.cmp_obj_attrs(a1, a, ["b", "c"])
        assert util.cmp_obj_attrs(a1, a, ["c", "b"])

        # missing attributes are considered a mismatch
        assert not util.cmp_obj_attrs(a, a1, ["b", "c", "d"])

        # empty attribute list is not a mismatch
        assert util.cmp_obj_attrs(a, b, [])

        # attributes of a and b differ
        assert not util.cmp_obj_attrs(a, b, ["b", "c"])
        assert not util.cmp_obj_attrs(b, a, ["b", "c"])
        assert not util.cmp_obj_attrs(b, a, ["c", "b"])
Пример #2
0
    def cmp_obj_attrs_test(self):
        """Test cmp_obj_attrs."""

        # pylint: disable=attribute-defined-outside-init

        class O(object):
            pass

        a = O()
        a.b = 1
        a.c = 2

        a1 = O()
        a1.b = 1
        a1.c = 2

        b = O()
        b.b = 1
        b.c = 3

        # a class should have it's own attributes
        self.assertTrue(util.cmp_obj_attrs(a, a, ["b", "c"]))
        self.assertTrue(util.cmp_obj_attrs(a1, a1, ["b", "c"]))
        self.assertTrue(util.cmp_obj_attrs(b, b, ["b", "c"]))

        # a and a1 should have the same attributes
        self.assertTrue(util.cmp_obj_attrs(a, a1, ["b", "c"]))
        self.assertTrue(util.cmp_obj_attrs(a1, a, ["b", "c"]))
        self.assertTrue(util.cmp_obj_attrs(a1, a, ["c", "b"]))

        # missing attributes are considered a mismatch
        self.assertFalse(util.cmp_obj_attrs(a, a1, ["b", "c", "d"]))

        # empty attribute list is not a mismatch
        self.assertTrue(util.cmp_obj_attrs(a, b, []))

        # attributes of a and b differ
        self.assertFalse(util.cmp_obj_attrs(a, b, ["b", "c"]))
        self.assertFalse(util.cmp_obj_attrs(b, a, ["b", "c"]))
        self.assertFalse(util.cmp_obj_attrs(b, a, ["c", "b"]))