示例#1
0
    def test_can_merge_nested_dicts(self):
        d1 = {
            "params": {
                "car": "4gheap",
                "car-params": {
                    "additional_cluster_settings": {
                        "indices.queries.cache.size": "5%",
                        "transport.tcp.compress": True
                    }
                },
                "unique-param": "foobar"
            }
        }

        d2 = {"params": {"car-params": {"data_paths": "/mnt/local_ssd"}}}

        assert dict(collections.merge_dicts(d1, d2)) == {
            "params": {
                "car-params": {
                    "additional_cluster_settings": {
                        "indices.queries.cache.size": "5%",
                        "transport.tcp.compress": True
                    },
                    "data_paths": "/mnt/local_ssd"
                },
                "car": "4gheap",
                "unique-param": "foobar"
            }
        }
示例#2
0
    def test_can_merge_randomized_empty_and_non_empty_dict(self, seed):
        random.seed(seed)

        dct = {"params": {"car-params": {"data_paths": "/mnt/local_ssd"}}}
        d1: Mapping[Any, Any] = random.choice([{}, dct])
        d2: Mapping[Any, Any] = dct if not d1 else {}

        assert dict(collections.merge_dicts(d1, d2)) == dct
示例#3
0
    def test_can_merge_nested_lists_in_dicts(self):
        d1 = {"params": {"foo": [1, 2, 3]}}

        d2 = {"params": {"foo": [3, 4, 5]}}

        assert dict(collections.merge_dicts(d1, d2)) == {
            "params": {
                "foo": [1, 2, 3, 4, 5]
            }
        }
示例#4
0
    def test_can_merge_nested_booleans_in_dicts(self):
        d1 = {"params": {"foo": True, "other": [1, 2, 3]}}

        d2 = {"params": {"foo": False}}

        assert dict(collections.merge_dicts(d1, d2)) == {
            "params": {
                # d2 wins
                "foo": False,
                "other": [1, 2, 3],
            }
        }
示例#5
0
    def test_can_merge_empty_dicts(self):
        d1: Mapping[Any, Any] = {}
        d2: Mapping[Any, Any] = {}

        assert dict(collections.merge_dicts(d1, d2)) == {}