Exemple #1
0
    def test_compare_two_deep_dicts_with_list_contains(self):

        dict_actual = {
            "data1": [{
                "Overhead": "45.17%",
                "Command": "uwsgi",
                "Shared Object": "libpython3.5m.so.1.0",
                "Symbol": "[.] 0x000000000011c525"
            }, {
                "Overhead": "1.25%",
                "Command": "uwsgi",
                "Shared Object": "_socket.cpython-35m-x86_64-linux-gnu.so",
                "Symbol": "[.] 0x0000000000006b00"
            }],
            "data2":
            "lepv"
        }

        dict_expected = {
            "data1": [{
                "Overhead": "45.17%",
                "Command": "uwsgi",
                "Shared Object": "libpython3.5m.so.1.0",
                "Symbol": "[.] 0x000000000011c525"
            }],
        }

        comp_result = DictUtil.compare(dict_actual, dict_expected)
        self.assertEqual(
            comp_result, 1,
            'If the first deep dict with list contains the second, the result should be 1'
        )
Exemple #2
0
    def test_compare_two_deep_dicts_with_list_not_equal_not_contains_not_contained(
            self):

        dict_actual = {
            "data1": [
                {
                    "Overhead": "45.17%",
                    "Command": "uwsgi",
                    "Shared Object": "libpython3.5m.so.1.0",
                    "Symbol": "[.] 0x000000000011c525"
                },
            ],
            "data2":
            "lepv"
        }

        dict_expected = {
            "data1": [{
                "Overhead": "1.25%",
                "Command": "uwsgi",
                "Shared Object": "_socket.cpython-35m-x86_64-linux-gnu.so",
                "Symbol": "[.] 0x0000000000006b00"
            }],
            "data2":
            "lepv"
        }

        comp_result = DictUtil.compare(dict_actual, dict_expected)
        self.assertEqual(
            comp_result, 2,
            'If two deep dicts with list are no inclusion relationship, the result should be 2'
        )
Exemple #3
0
    def test_compare_two_null_dicts_should_equal(self):
        dict_1 = None
        dict_2 = None

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 0,
            'The comparison result of two null dicts should be 0')
Exemple #4
0
    def test_compare_empty_dict_being_contained(self):
        dict_1 = {"project": "lepv"}
        dict_2 = {}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 1,
            'Empty dict should be considered "contained" by any non-empty dict'
        )
Exemple #5
0
    def test_compare_two_empty_dicts_should_equal(self):

        dict_1 = {}
        dict_2 = {}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 0,
            'The comparison result of two empty dicts should be 0')
Exemple #6
0
    def test_compare_two_deep_dicts_with_arrays(self):
        with open('./dict_data/a.json') as json_file:
            expected_json = json.load(json_file)

        with open('./dict_data/b.json') as json_file:
            same_json = json.load(json_file)

        comp_result = DictUtil.compare(expected_json, same_json)
        self.assertEqual(comp_result, 0,
                         'Two identical dicts with deep arrays should equal')
Exemple #7
0
    def test_compare_two_flat_dicts_equal(self):

        dict_1 = {"project": "lepv"}

        dict_2 = {"project": "lepv"}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 0,
            'The comparison result of two identical flat dicts should be 0')
Exemple #8
0
    def test_compare_two_deep_dicts_contains(self):

        dict_1 = {"project1": {"k1": "v1", "k2": "v2"}, "project2": "lepv2"}

        dict_2 = {"project1": {"k1": "v1"}, "project2": "lepv2"}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 1,
            'If the first deep dict contains the second, the result should be 1'
        )
Exemple #9
0
    def test_compare_two_deep_dicts_not_equal_not_contains_not_contained(self):

        dict_1 = {"project1": {"k1": "v1"}, "project2": "lepv2"}

        dict_2 = {"project1": {"k1": "v2", "k2": "v1"}, "project2": "lepv2"}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 2,
            'If two deep dicts are no inclusion relationship, the result should be 2'
        )
Exemple #10
0
    def test_compare_two_flat_dicts_not_equal_not_contains_not_contained(self):

        dict_1 = {"project1": "lepv1", "project2": "lepv2"}

        dict_2 = {"project3": "lepv3", "project4": "lepv4"}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 2,
            'If two flat dicts are no inclusion relationship, the result should be 2'
        )
Exemple #11
0
    def test_flame_burner(self):
        with open('data/perf_script_output.txt') as perf_script_output_file:
            perf_script_output_lines = perf_script_output_file.readlines()

        with open('data/perf_script_burned_data.json') as burned_json_file:
            expected_burned_json = json.load(burned_json_file)

        burner = FlameBurner()
        actual_burned_data = burner.burn(perf_script_output_lines)

        compare_result = DictUtil.compare(expected_burned_json, actual_burned_data)
        self.assertEqual(compare_result, 0, "Expected and Actual does not match")
Exemple #12
0
    def test_compare_two_flat_dicts_contains(self):

        dict_1 = {
            "project1": "lepv1",
            "project2": "lepv2",
            "project3": "lepv3"
        }

        dict_2 = {"project1": "lepv1", "project2": "lepv2"}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 1,
            'If the first flat dict contains the second, the result should be 1'
        )
    def validate(self, expected, actual, expectedMatchType):

        print("Actual:")
        pprint(actual)

        compare_result = DictUtil.compare(actual, expected)

        if expectedMatchType == 'equals':
            self.assertEqual(compare_result, 0,
                             "Expected and Actual does not match")
        elif expectedMatchType == 'contains':
            self.assertIn(compare_result, [0, 1],
                          "Actual does not contain the expected")
        else:
            print("")