Esempio n. 1
0
    def test__remove(self):
        """
        Tests the _remove method of the journaled list.
        """

        # creates a journaled list with elements from an existent
        # list and then adds some extra elements (that are not going to
        # be journalized) to test the (not jounalized) removal of them
        journaled_list = colony.JournaledList([1, 2, 3])
        journaled_list._remove(1)
        journaled_list._remove(2)
        journaled_list._remove(3)

        # retrieves the list of removes and tests it
        # against the empty list (not jounalized)
        removes = journaled_list.get_removes()
        self.assertEqual(removes, [])

        # tries to remove the first element one more time
        # (this should raise a value error, and the removes
        # list should remain the same)
        self.assert_raises(ValueError, journaled_list._remove, 1)
        self.assertEqual(removes, [])

        # verifies that the contents of the journaled list
        # are empty
        self.assertEqual(journaled_list, [])

        # retrieves the appends list, that must be empty and
        # tests it against an empty list
        appends = journaled_list.get_appends()
        self.assertEqual(appends, [])
Esempio n. 2
0
    def test_clear_jounal(self):
        """
        Tests the clear journal method of the journaled list.
        """

        # creates a journaled list with elements from an existent
        # list and then adds and removes some extra elements (that are going to
        # be journalized) to test the appending and removal of them
        journaled_list = colony.JournaledList([1, 2, 3])
        journaled_list.append(1)
        journaled_list.remove(2)
        journaled_list.remove(3)

        # retrieves the list of appends and tests it
        # against the expected values
        appends = journaled_list.get_appends()
        self.assertEqual(appends, [1])

        # retrieves the list of removes and tests it
        # against the expected values
        removes = journaled_list.get_removes()
        self.assertEqual(removes, [2, 3])

        # verifies that the journaled list contains
        # the expected values
        self.assertEqual(journaled_list, [1, 1])

        # clears the journal and verifies that both
        # the appends and removes lists are now empty
        journaled_list.clear_jounal()
        self.assertEqual(appends, [])
        self.assertEqual(removes, [])

        # verifies that the journaled list remains unmodified
        self.assertEqual(journaled_list, [1, 1])
Esempio n. 3
0
    def test__append(self):
        """
        Tests the _append method of the journaled list.
        """

        # creates a journaled list with elements from an existent
        # list and then adds some extra elements (that are not going to
        # be journalized) to test the (not jounalized) appending of them
        journaled_list = colony.JournaledList([1, 2, 3])
        journaled_list._append(4)
        journaled_list._append(5)
        journaled_list._append(6)

        # retrieves the list of appends and tests it
        # against the empty list (not jounalized)
        appends = journaled_list.get_appends()
        self.assertEqual(appends, [])

        # appends one extra value to the list
        # and re-tests the appends list
        journaled_list._append(4)
        self.assertEqual(appends, [])

        # verifies that the contents of the journaled list
        # are the expected ones
        self.assertEqual(journaled_list, [1, 2, 3, 4, 5, 6, 4])

        # retrieves the removes list, that must be empty and
        # tests it against an empty list
        removes = journaled_list.get_removes()
        self.assertEqual(removes, [])
Esempio n. 4
0
    def test_overriding(self):
        """
        Tests the overriding of remove over append operation and
        the reverse.
        """

        # creates a journaled list with elements from an existent
        # list and then adds (and removes) some extra elements (that are going to
        # be journalized) to test the overriding of them
        journaled_list = colony.JournaledList([1, 2, 3])
        journaled_list.append(1)
        journaled_list.append(1)
        journaled_list.remove(1)

        # retrieves the list of appends and tests it
        # against the expected values
        appends = journaled_list.get_appends()
        self.assertEqual(appends, [1])

        # retrieves the list of removes and tests it
        # against the expected values
        removes = journaled_list.get_removes()
        self.assertEqual(removes, [])

        # removes one value and tests the appends
        # and removes list (again)
        journaled_list.remove(1)
        self.assertEqual(appends, [])
        self.assertEqual(removes, [])

        # removes one value and tests the appends
        # and removes list (again)
        journaled_list.remove(1)
        self.assertEqual(appends, [])
        self.assertEqual(removes, [1])

        # appends two values and tests the appends
        # and removes list (again)
        journaled_list.append(1)
        journaled_list.append(1)
        self.assertEqual(appends, [1])
        self.assertEqual(removes, [])