예제 #1
0
    def testCopy(self):
        """MultipleElement copy methods"""
        elem = MultipleElement(SimpleElement(check='digit'))

        # Empty
        self.assertEqual(len(elem.emptycopy()), 0)
        self.assertEqual(elem.copy().as_dict(), elem.as_dict())

        # With some content
        elem.add(3)
        elem.add(5)
        self.assertEqual(len(elem.emptycopy()), 0)
        self.assertEqual(elem.copy().as_dict(), elem.as_dict())
예제 #2
0
    def testCopy(self):
        """MultipleElement copy methods"""
        elem = MultipleElement(SimpleElement(check='digit'))

        # Empty
        self.assertEqual(len(elem.emptycopy()), 0)
        self.assertEqual(elem.copy().as_dict(), elem.as_dict())

        # With some content
        elem.add(3)
        elem.add(5)
        self.assertEqual(len(elem.emptycopy()), 0)
        self.assertEqual(elem.copy().as_dict(), elem.as_dict())
예제 #3
0
    def testDiff(self):
        """MultipleElement diff method"""

        elem = MultipleElement(SimpleElement(check='digit'))

        # (empty) <=> (empty)
        added, changed, removed = elem.diff(elem)
        self.assertTrue(len(added) == len(removed) == len(changed) == 0)

        elem.add(3)
        elem.add(9)
        elem.add(4)

        # itself
        added, changed, removed = elem.diff(elem)
        self.assertTrue(len(added) == len(removed) == len(changed) == 0)

        # elem <=> (empty)
        added, changed, removed = elem.diff(elem.emptycopy())
        self.assertTrue(len(added) == len(changed) == 0)
        self.assertEqual(removed.get(), [3, 9, 4])

        # (empty) <=> elem
        added, changed, removed = elem.emptycopy().diff(elem)
        self.assertTrue(len(removed) == len(changed) == 0)
        self.assertEqual(added.get(), [3, 9, 4])

        # Mixed
        other = elem.copy()
        other.remove(4)
        other.add(5)
        added, changed, removed = elem.diff(other)
        self.assertEqual(changed.get(), None)
        self.assertEqual(added.get(), [5])
        self.assertEqual(removed.get(), [4])
예제 #4
0
    def testDiff(self):
        """MultipleElement diff method"""

        elem = MultipleElement(SimpleElement(check='digit'))

        # (empty) <=> (empty)
        added, changed, removed = elem.diff(elem)
        self.assertTrue(len(added) == len(removed) == len(changed) == 0)

        elem.add(3)
        elem.add(9)
        elem.add(4)

        # itself
        added, changed, removed = elem.diff(elem)
        self.assertTrue(len(added) == len(removed) == len(changed) == 0)

        # elem <=> (empty)
        added, changed, removed = elem.diff(elem.emptycopy())
        self.assertTrue(len(added) == len(changed) == 0)
        self.assertEqual(removed.get(), [3, 9, 4])

        # (empty) <=> elem
        added, changed, removed = elem.emptycopy().diff(elem)
        self.assertTrue(len(removed) == len(changed) == 0)
        self.assertEqual(added.get(), [3, 9, 4])

        # Mixed
        other = elem.copy()
        other.remove(4)
        other.add(5)
        added, changed, removed = elem.diff(other)
        self.assertEqual(changed.get(), None)
        self.assertEqual(added.get(), [5])
        self.assertEqual(removed.get(), [4])
예제 #5
0
    def test_diff_key_simple_element(self):
        """MultipleElement diff method with simple elements with a specific key"""

        class MyElement(SimpleElement):
            def __init__(self, check='digit', default=None, value=None):
                SimpleElement.__init__(self, check, default, value)
            def key(self):
                return self.get() / 2

        elem = MultipleElement(MyElement())
        elem.add(7)
        elem.add(4)

        other = elem.copy()
        other.remove(7)
        other.add(6)

        added, changed, removed = elem.diff(other)
        self.assertEqual(added.get(), None)
        self.assertEqual(removed.get(), None)
        self.assertEqual(changed.get(), [6])
        self.assertEqual(changed.elements()[0].old.get(), 7)
예제 #6
0
    def test_diff_key_simple_element(self):
        """MultipleElement diff method with simple elements with a specific key"""
        class MyElement(SimpleElement):
            def __init__(self, check='digit', default=None, value=None):
                SimpleElement.__init__(self, check, default, value)

            def key(self):
                return self.get() / 2

        elem = MultipleElement(MyElement())
        elem.add(7)
        elem.add(4)

        other = elem.copy()
        other.remove(7)
        other.add(6)

        added, changed, removed = elem.diff(other)
        self.assertEqual(added.get(), None)
        self.assertEqual(removed.get(), None)
        self.assertEqual(changed.get(), [6])
        self.assertEqual(changed.elements()[0].old.get(), 7)