Code Duplication    Length = 23-23 lines in 2 locations

tests/test_benedict.py 1 location

@@ 510-532 (lines=23) @@
507
        self.assertTrue(isinstance(d, benedict))
508
        self.assertEqual(d, { 'a': 1, 'b': 2, 'c': 3, })
509
510
    def test_from_csv_with_valid_data(self):
511
        s = """id,name,age,height,weight
512
1,Alice,20,62,120.6
513
2,Freddie,21,74,190.6
514
3,Bob,17,68,120.0
515
4,François,32,75,110.05
516
"""
517
        r = {
518
            'values': [
519
                { 'id':'1', 'name':'Alice', 'age':'20', 'height':'62', 'weight':'120.6', },
520
                { 'id':'2', 'name':'Freddie', 'age':'21', 'height':'74', 'weight':'190.6', },
521
                { 'id':'3', 'name':'Bob', 'age':'17', 'height':'68', 'weight':'120.0', },
522
                { 'id':'4', 'name':'François', 'age':'32', 'height':'75', 'weight':'110.05', },
523
            ],
524
        }
525
        # static method
526
        d = benedict.from_csv(s)
527
        self.assertTrue(isinstance(d, dict))
528
        self.assertEqual(d, r)
529
        # constructor
530
        d = benedict(s, format='csv')
531
        self.assertTrue(isinstance(d, dict))
532
        self.assertEqual(d, r)
533
534
    def test_from_json(self):
535
        j = '{"a": 1, "b": 2, "c": 3}'

tests/test_io_dict.py 1 location

@@ 159-181 (lines=23) @@
156
157
# CSV
158
159
    def test_from_csv_with_valid_data(self):
160
        s = """id,name,age,height,weight
161
1,Alice,20,62,120.6
162
2,Freddie,21,74,190.6
163
3,Bob,17,68,120.0
164
4,François,32,75,110.05
165
"""
166
        r = {
167
            'values': [
168
                { 'id':'1', 'name':'Alice', 'age':'20', 'height':'62', 'weight':'120.6', },
169
                { 'id':'2', 'name':'Freddie', 'age':'21', 'height':'74', 'weight':'190.6', },
170
                { 'id':'3', 'name':'Bob', 'age':'17', 'height':'68', 'weight':'120.0', },
171
                { 'id':'4', 'name':'François', 'age':'32', 'height':'75', 'weight':'110.05', },
172
            ],
173
        }
174
        # static method
175
        d = IODict.from_csv(s)
176
        self.assertTrue(isinstance(d, dict))
177
        self.assertEqual(d, r)
178
        # constructor
179
        d = IODict(s, format='csv')
180
        self.assertTrue(isinstance(d, dict))
181
        self.assertEqual(d, r)
182
183
    # def test_from_csv_with_invalid_data(self):
184
    #     s = 'Lorem ipsum est in ea occaecat nisi officia.'