Beispiel #1
0
    def test_ab(self):
        input_ = {'a': 123, 
                  'b': {'a': 212, 
                        'b': {'a': 777}
                       }}

        output = {'a': 123, 'b.a': 212, 'b.b.a': 777}
        self.assertEqual(output, solution.flatten_dict(input_))
Beispiel #2
0
    def test_games_type(self):
        input_ = {'moba': 'league_of_legends', 
                  'fps': {'dota': 12, 
                          'call_of_duty': {'battlefield': 777}
                         }}

        output = {'moba': 'league_of_legends', 'fps.dota': 12, 'fps.call_of_duty.battlefield': 777}
        self.assertEqual(output, solution.flatten_dict(input_))        
Beispiel #3
0
 def test_flatten_with_three_dicts_nesting(self):
     self.assertEqual({'b.c.d.f': 2},
                      s.flatten_dict({'b': {
                          'c': {
                              'd': {
                                  'f': 2
                              }
                          }
                      }}))
Beispiel #4
0
 def test_flatten_with_one_dict_nesting(self):
     self.assertEqual({
         'a': 1,
         'b.c': 2
     }, s.flatten_dict({
         'a': 1,
         'b': {
             'c': 2
         }
     }))
Beispiel #5
0
 def test_flatten_with_two_dicts_nesting_third_level(self):
     self.assertEqual({
         'b.c.d': 2,
         'b.c.f': 3
     }, s.flatten_dict({'b': {
         'c': {
             'd': 2,
             'f': 3
         }
     }}))
Beispiel #6
0
    def test_fruits_three_levels(self):
        input_ = {'pineapple': 1,
                  'apple': {'orange': 2,
                            'cherry': 2,
                            'peach': {'apricot': 1,
                                      'lemon': 1}},
                  'kiwi': 3}

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

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

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

        output = {
            'pineapple': 1,
            'apple.orange': 2,
            'apple.cherry': 2,
            'apple.peach.apricot': 1,
            'apple.peach.lemon': 1,
            'kiwi': 3
        }
        self.assertEqual(s.flatten_dict(input_), output)
Beispiel #15
0
 def test_with_three_levels(self):
     self.assertEqual({'three.threeOne.threeOneOne': 3.11,
                       'two.twoOne': 2.1, 'one': 1},
                       s.flatten_dict({'one': 1,
                       'two': {'twoOne': 2.1},
                       'three': {'threeOne': {'threeOneOne': 3.11}}}))
Beispiel #16
0
 def test_three_levels(self):
     self.assertEqual({'g': 103, 'a.b': 195, 'c.d.e.f': 402},
                       s.flatten_dict({'a': {'b': 195},
                       'c': {'d': {'e': {'f': 402}}},
                       'g': 103}))
Beispiel #17
0
 def test_flatten_with_three_dicts_nesting(self):
     self.assertEqual({'b.c.d.f': 2}, s.flatten_dict(
         {'b': {'c': {'d': {'f': 2}}}}))
Beispiel #18
0
 def test_with_three_levels_of_nesting(self):
     self.assertEqual(
         {'a': 1, 'b.a': 2, 'b.b.a': 1},
         s.flatten_dict({'a': 1, 'b': {'a': 2, 'b': {'a': 1}}})
     )
Beispiel #19
0
 def test_flatten_without_nesting(self):
     self.assertEqual({'a': 1, 'b': 2}, s.flatten_dict({'a': 1, 'b': 2}))
Beispiel #20
0
 def test_with_three_levels(self):
     self.assertEqual(
         {"three.threeOne.threeOneOne": 3.11, "two.twoOne": 2.1, "one": 1},
         solution.flatten_dict({"one": 1, "two": {"twoOne": 2.1}, "three": {"threeOne": {"threeOneOne": 3.11}}}),
     )
Beispiel #21
0
 def test_three_levels(self):
     self.assertEqual(
         {"g": 103, "a.b": 195, "c.d.e.f": 402},
         solution.flatten_dict({"a": {"b": 195}, "c": {"d": {"e": {"f": 402}}}, "g": 103}),
     )
Beispiel #22
0
 def test_flatten_without_nesting(self):
     self.assertEqual({'a': 1, 'b': 2}, s.flatten_dict({'a': 1, 'b': 2}))
Beispiel #23
0
 def test_with_already_flatten_dict(self):
     flatten = {'a': 1, 'b': 2, 'c': 3}
     self.assertEqual(flatten, s.flatten_dict(flatten))
Beispiel #24
0
 def test_with_two_levels_of_nesting(self):
     self.assertEqual(
         {'a': 1, 'b.a': 2},
         s.flatten_dict({'a': 1, 'b': {'a': 2}})
     )
Beispiel #25
0
 def test_flatten_with_one_dict_nesting(self):
     self.assertEqual({'a': 1, 'b.c': 2}, s.flatten_dict(
         {'a': 1, 'b': {'c': 2}}))
Beispiel #26
0
 def test_example_case(self):
     self.assertEqual(
         s.flatten_dict({'a': 1, 'c': {'a': 2, 'b': {'x': 5, 'y': 9}}, 'd': [1, 2, 3]}),
         {'a': 1, 'c.a': 2, 'c.b.x': 5, 'c.b.y': 9, 'd': [1, 2, 3]},
     )
Beispiel #27
0
 def test_flatten_with_two_dicts_nesting_third_level(self):
     self.assertEqual({'b.c.d': 2, 'b.c.f': 3}, s.flatten_dict(
         {'b': {'c': {'d': 2, 'f': 3}}}))