Ejemplo n.º 1
0
    def test_ab(self):
        input_ = {'a': 123, 'b.a': 212, 'b.b.a': 777}

        output = {'a': 123, 
                  'b': {'a': 212, 
                        'b': {'a': 777}
                       }}
        self.assertEqual(output, solution.unflatten_dict(input_))
Ejemplo n.º 2
0
 def test_unflatten_with_three_dicts_nesting(self):
     self.assertEqual({'b': {
         'c': {
             'd': {
                 'f': 2
             }
         }
     }}, s.unflatten_dict({'b.c.d.f': 2}))
Ejemplo n.º 3
0
    def test_games_type(self):
        input_ = {'moba': 'league_of_legends', 'fps.dota': 12, 'fps.call_of_duty.battlefield': 777}

        output = {'moba': 'league_of_legends', 
                  'fps': {'dota': 12, 
                          'call_of_duty': {'battlefield': 777}
                         }}

        self.assertEqual(output, solution.unflatten_dict(input_))    
Ejemplo n.º 4
0
 def test_unflatten_with_one_dict_nesting(self):
     self.assertEqual({
         'a': 1,
         'b': {
             'c': 2
         }
     }, s.unflatten_dict({
         'a': 1,
         'b.c': 2
     }))
Ejemplo n.º 5
0
 def test_unflatten_with_two_dicts_nesting_third_level(self):
     self.assertEqual({'b': {
         'c': {
             'd': 2,
             'f': 3
         }
     }}, s.unflatten_dict({
         'b.c.d': 2,
         'b.c.f': 3
     }))
Ejemplo n.º 6
0
    def test_fruits_three_levels(self):
        input_ = {'pineapple': 1, 'apple.orange': 2, 'apple.cherry': 2,
                  'apple.peach.apricot': 1, 'apple.peach.lemon': 1,
                  'kiwi': 3}

        output = {'pineapple': 1,
                  'apple': {'orange': 2,
                            'cherry': 2,
                            'peach': {'apricot': 1,
                                      'lemon': 1}},
                  'kiwi': 3}
        self.assertEqual(s.unflatten_dict(input_), output)
Ejemplo n.º 7
0
    def test_names(self):
        input_ = {'steve': 12, 'jack.jess': 21, 'jack.karry': 31,
                  'jack.molly.peny': 33, 'jack.molly.john': 44,
                  'lily': 3}
 
        output = {'steve': 12,
                  'jack': {'jess': 21,
                            'karry': 31,
                            'molly': {'peny': 33,
                                      'john': 44}},
                  'lily': 3}
        self.assertEqual(solution.unflatten_dict(input_), output)
Ejemplo n.º 8
0
    def test_automobile_manufacturers(self):
        input_ = {'Sweden': 'Volvo', 'Germany.Wolfsburg': 'VW',
                  'Germany.Munich': 'BMW',
                  'Germany.Stuttgart.east': 'Porsche',
                  'Germany.Stuttgart.west': 'Mercedes', 'Chemnitz': 'Audi'}

        output = {'Sweden': 'Volvo',
                  'Germany': {'Wolfsburg': 'VW',
                              'Munich': 'BMW',
                              'Stuttgart': {'east': 'Porsche',
                                            'west': 'Mercedes'}},
                  'Chemnitz': 'Audi'}
        self.assertEqual(s.unflatten_dict(input_), output)
Ejemplo n.º 9
0
 def test_with_three_levels_of_nesting(self):
     self.assertEqual({
         'a': 1,
         'b': {
             'a': 2,
             'b': {
                 'a': 1
             }
         }
     }, s.unflatten_dict({
         'a': 1,
         'b.a': 2,
         'b.b.a': 1
     }))
Ejemplo n.º 10
0
 def test_three(self):
     self.assertEqual(
         {
             'one': 1,
             'three': {
                 'threeOne': {
                     'threeOneOne': 3.11
                 }
             },
             'two': {
                 'twoOne': 2.1
             }
         },
         solution.unflatten_dict({
             'three.threeOne.threeOneOne': 3.11,
             'two.twoOne': 2.1,
             'one': 1
         }))
Ejemplo n.º 11
0
 def test_with_three_levels(self):
     self.assertEqual(
         {
             'g': 103,
             'c': {
                 'd': {
                     'e': {
                         'f': 402
                     }
                 }
             },
             'a': {
                 'b': 195
             }
         }, solution.unflatten_dict({
             'g': 103,
             'a.b': 195,
             'c.d.e.f': 402
         }))
Ejemplo n.º 12
0
 def test_example(self):
     self.assertEqual(
         {
             'a': 1,
             'c': {
                 'a': 2,
                 'b': {
                     'x': 5,
                     'y': 9,
                 }
             },
             'd': [1, 2, 3]
         },
         s.unflatten_dict({
             'a': 1,
             'c.a': 2,
             'c.b.x': 5,
             'c.b.y': 9,
             'd': [1, 2, 3]
         }))
Ejemplo n.º 13
0
    def test_automobile_manufacturers(self):
        input_ = {
            'Sweden': 'Volvo',
            'Germany.Wolfsburg': 'VW',
            'Germany.Munich': 'BMW',
            'Germany.Stuttgart.east': 'Porsche',
            'Germany.Stuttgart.west': 'Mercedes',
            'Chemnitz': 'Audi'
        }

        output = {
            'Sweden': 'Volvo',
            'Germany': {
                'Wolfsburg': 'VW',
                'Munich': 'BMW',
                'Stuttgart': {
                    'east': 'Porsche',
                    'west': 'Mercedes'
                }
            },
            'Chemnitz': 'Audi'
        }
        self.assertEqual(s.unflatten_dict(input_), output)
Ejemplo n.º 14
0
    def test_fruits_three_levels(self):
        input_ = {
            'pineapple': 1,
            'apple.orange': 2,
            'apple.cherry': 2,
            'apple.peach.apricot': 1,
            'apple.peach.lemon': 1,
            'kiwi': 3
        }

        output = {
            'pineapple': 1,
            'apple': {
                'orange': 2,
                'cherry': 2,
                'peach': {
                    'apricot': 1,
                    'lemon': 1
                }
            },
            'kiwi': 3
        }
        self.assertEqual(s.unflatten_dict(input_), output)
Ejemplo n.º 15
0
 def test_with_three_levels(self):
     self.assertEqual({'g': 103, 'c': {'d': {'e': {'f': 402}}}, 'a': {'b': 195}},
                      s.unflatten_dict({'g': 103, 'a.b': 195, 'c.d.e.f': 402}))
Ejemplo n.º 16
0
 def test_unflatten_with_two_dicts_nesting_second_level(self):
     self.assertEqual({'b': {'c': {'d': 2}, 'f': 3}}, s.unflatten_dict(
         {'b.c.d': 2, 'b.f': 3}))
Ejemplo n.º 17
0
 def test_unflatten_with_two_dicts_nesting(self):
     self.assertEqual({'b': {'c': {'d': 2}}}, s.unflatten_dict(
         {'b.c.d': 2}))
Ejemplo n.º 18
0
 def test_with_three_levels_of_nesting(self):
     self.assertEqual(
         {'a': 1, 'b': {'a': 2, 'b': {'a': 1}}},
         s.unflatten_dict({'a': 1, 'b.a': 2, 'b.b.a': 1})
     )
Ejemplo n.º 19
0
 def test_with_three_levels(self):
     self.assertEqual(
         {"g": 103, "c": {"d": {"e": {"f": 402}}}, "a": {"b": 195}},
         solution.unflatten_dict({"g": 103, "a.b": 195, "c.d.e.f": 402}),
     )
Ejemplo n.º 20
0
 def test_three(self):
     self.assertEqual(
         {"one": 1, "three": {"threeOne": {"threeOneOne": 3.11}}, "two": {"twoOne": 2.1}},
         solution.unflatten_dict({"three.threeOne.threeOneOne": 3.11, "two.twoOne": 2.1, "one": 1}),
     )
Ejemplo n.º 21
0
 def test_unflatten_without_nesting(self):
     self.assertEqual({'a': 1, 'b': 2}, s.unflatten_dict({'a': 1, 'b': 2}))
Ejemplo n.º 22
0
 def test_three(self):
     self.assertEqual({'one': 1, 'three': {'threeOne': {'threeOneOne': 3.11}},
                      'two': {'twoOne': 2.1}},
                      s.unflatten_dict({'three.threeOne.threeOneOne': 3.11,
                      'two.twoOne': 2.1, 'one': 1}))
Ejemplo n.º 23
0
 def test_with_already_unflatten_dict(self):
     unflatten = {'a': 1, 'b': 2, 'c': 3}
     self.assertEqual(unflatten, s.unflatten_dict(unflatten))
Ejemplo n.º 24
0
 def test_unflatten_without_nesting(self):
     self.assertEqual({'a': 1, 'b': 2}, s.unflatten_dict({'a': 1, 'b': 2}))
Ejemplo n.º 25
0
 def test_example(self):
     self.assertEqual(
         {'a': 1, 'c': {'a': 2, 'b': {'x': 5, 'y': 9, }}, 'd': [1, 2, 3]},
         s.unflatten_dict({'a': 1, 'c.a': 2, 'c.b.x': 5, 'c.b.y': 9, 'd': [1, 2, 3]})
     )
Ejemplo n.º 26
0
 def test_unflatten_with_one_dict_nesting(self):
     self.assertEqual({'a': 1, 'b': {'c': 2}}, s.unflatten_dict(
         {'a': 1, 'b.c': 2}))