コード例 #1
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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'
        )
コード例 #2
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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'
        )
コード例 #3
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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')
コード例 #4
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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'
        )
コード例 #5
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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')
コード例 #6
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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')
コード例 #7
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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')
コード例 #8
0
ファイル: dictCmpTests.py プロジェクト: kangyijie5473/lepv
    def test_two_dicts_not_equal_not_contains_not_contained(self):

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

        dict_2 = {"project": {"k1": "v2222", "k2": "v1"}, "project2": "lepv2"}

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, 2,
            'if there is no inclusion relationship, the result should be 2')
コード例 #9
0
ファイル: dictCmpTests.py プロジェクト: kangyijie5473/lepv
    def test_two_dicts_contained(self):

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

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

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, -1,
            'if the second dict contains the first, the result should be -1')
コード例 #10
0
ファイル: dictCmpTests.py プロジェクト: kangyijie5473/lepv
    def test_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,
            'The first deep dict contains second, the result should be 1')
コード例 #11
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    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'
        )
コード例 #12
0
    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("")
コード例 #13
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")
コード例 #14
0
ファイル: dictCmpTests.py プロジェクト: kangyijie5473/lepv
    def test_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 dict contains second, the result should be 1')
コード例 #15
0
ファイル: dictCmpTests.py プロジェクト: zhanglianpin/lepv
    def test_compare_two_flat_dicts_contained(self):

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

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

        comp_result = DictUtil.compare(dict_1, dict_2)
        self.assertEqual(
            comp_result, -1,
            'If the second flat dict contains the first, the result should be -1'
        )