Example #1
0
    def test_show_diff_for_same_elements(self):
        first_row, second_row, status = diff(self.ether, self.ether)

        self.assertEqual(first_row, "__ __ __ __ __ __ __ __ __ __ __ __ __ __".split())
        self.assertEqual(
            second_row, "__ __ __ __ __ __ __ __ __ __ __ __ __ __".split()
        )
        self.assertFalse(status)
Example #2
0
    def test_diff_should_return_same_len_list_if_one_of_them_was_shorter(self):
        too_long_ether = get_hex(Ether() / "additional string")

        diff_tuple = diff(self.ether, too_long_ether)
        self.assertEqual(
            len(diff_tuple[0]), len(diff_tuple[1]), "List should be the same length"
        )

        self.assertNotEqual(len(get_hex(self.ether).split()), len(diff_tuple[0]))
        self.assertEqual(len(too_long_ether.split()), len(diff_tuple[1]))
Example #3
0
    def test_show_diff(self):
        ether_wrong = "ff ff ff ff ff ff 00 00 00 00 aa 00 90 00"
        first_row, second_row, status = diff(self.ether, ether_wrong)

        self.assertEqual(first_row, "__ __ __ __ __ __ __ __ __ __ 00 __ __ __".split())
        self.assertEqual(
            second_row, "__ __ __ __ __ __ __ __ __ __ aa __ __ __".split()
        )
        self.assertTrue(status)
        self.assertEqual(
            status,
            [
                10,
            ],
        )
Example #4
0
    def assertHexDifferentAt(first, second, positions, message):
        _, _, differences_at_position = diff(first, second)
        if len(differences_at_position) == 0:
            print("Hexs are equal")
            failure(first, second, message)

        if isinstance(positions, int):
            if len(differences_at_position) != 1 or (
                    positions not in differences_at_position):
                show_diff(first, second, index=True)
                failure(first, second, message)
        elif isinstance(positions, (list, tuple)):
            if not set(positions).issubset(
                    set(differences_at_position)) or set(positions) < set(
                        differences_at_position):
                show_diff(first, second, index=True)
                failure(first, second, message)
Example #5
0
 def test_diff_list_should_be_diff_at_6_position(self):
     result = diff(
         "ff ff ff ff ff ff 11 00 00 00 00 00 90 00",
         "ff ff ff ff ff ff 00 00 00 00 00 00 90 00",
     )
     self.assertEqual(
         result,
         (
             [
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "11",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
             ],
             [
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "00",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
             ],
             [6],
         ),
         "Results should be equal",
     )
Example #6
0
 def test_diff_list_equal(self):
     result = diff(
         "ff ff ff ff ff ff 00 00 00 00 00 00 90 00",
         "ff ff ff ff ff ff 00 00 00 00 00 00 90 00",
     )
     self.assertEqual(
         result,
         (
             [
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
             ],
             [
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
                 "__",
             ],
             [],
         ),
         "Results should be equal",
     )
Example #7
0
    def test_diff_should_return_3_elements(self):
        too_long_ether = get_hex(Ether() / "additional string")

        diff_tuple = diff(self.ether, too_long_ether)
        self.assertEqual(len(diff_tuple), 3, "_diff should return only a 3 elements")
Example #8
0
 def test_get_diff_should_be_the_same_as_diff(self):
     fun_diff = diff(self.ether, self.ether2)
     fun_get_diff = get_diff(self.ether, self.ether2)
     self.assertEqual(
         fun_diff, fun_get_diff, "The result of get_diff and diff should be the same"
     )
Example #9
0
    def test_diff_refactor(self):
        with self.assertRaises(NotImplementedError):
            diff("00 11", "00 11", "00 00")

        with self.assertRaises(NotImplementedError):
            diff("00 11")