コード例 #1
0
    def test_skip_nested(self):
        dictionary = {
            "a": "1",
            "b": {
                "c": 2,
                "d": "3"
            },
            "e": {
                "f": {
                    "g": "4"
                }
            }
        }

        expected = {"a": "1", "b__d": "3", "e__f__g": "4"}
        actual = flatten(dictionary, skip=["c"])
        assert actual == expected
コード例 #2
0
 def test_one_level_two(self):
     dictionary = {"a": {"b": 1, "c": 2}}
     assert {"a__b": 1, "a__c": 2} == flatten(dictionary)
コード例 #3
0
 def test_one_level(self):
     dictionary = {"a": {"b": 1}}
     assert {"a__b": 1} == flatten(dictionary)
コード例 #4
0
 def test_trivial_two(self):
     dictionary = {"a": 1, "b": 2}
     flat_dict = flatten(dictionary)
     assert {"a": 1, "b": 2} == flat_dict
コード例 #5
0
 def test_trivial(self):
     assert {"a": 1} == flatten({"a": 1})
コード例 #6
0
 def test_skip(self):
     dictionary = {"a": 1, "b": 2}
     flat_dict = flatten(dictionary, skip="b")
     assert {"a": 1} == flat_dict
コード例 #7
0
 def test_two_level_two(self):
     dictionary = {"a": {"b": {"c": 1}, "d": 2}}
     assert {"a__b__c": 1, "a__d": 2} == flatten(dictionary)
コード例 #8
0
 def test_two_level(self):
     dictionary = {"a": {"b": {"c": 1}}}
     assert {"a__b__c": 1} == flatten(dictionary)