Example #1
0
 def test_single_row(self):
     from fixed2csv import main
     contents = ("01  Otis Taylor                         "
                 "Ran So Hard the Sun Went Down               "
                 "3:52")
     expected = '01,Otis Taylor,Ran So Hard the Sun Went Down,3:52\n'
     columns = '0:2,4:38,40:82,84:88'
     with make_file(contents) as fixed_file, make_file('') as csv_file:
         main([fixed_file, csv_file, '--cols=' + columns])
         self.assertEqual(open(csv_file).read(), expected)
Example #2
0
 def test_data_with_commas_and_quotes(self):
     from fixed2csv import main
     contents = dedent("""
         22  David Allan Coe  Willie, Waylon, And Me   3:26
         23  The Band         A title with "quotes"    0:42
         24  Bob Dylan        House Of The Risin' Sun  5:20
     """).lstrip()
     expected = ('22,David Allan Coe,"Willie, Waylon, And Me",3:26\n'
                 '23,The Band,"A title with ""quotes""",0:42\n'
                 "24,Bob Dylan,House Of The Risin' Sun,5:20\n")
     columns = '0:2,4:19,21:44,46:50'
     with make_file(contents) as fixed_file, make_file('') as csv_file:
         main(['--cols=' + columns, fixed_file, csv_file])
         self.assertEqual(open(csv_file).read(), expected)
Example #3
0
 def test_multiple_rows_and_columns(self):
     from fixed2csv import main
     contents = dedent("""
         2012  Lexus             LFA
         2009  GMC               Yukon XL 1500
         1965  Ford              Mustang
         2005  Hyundai           Sonata
         1995  Mercedes-Benz     C-Class
     """).lstrip()
     expected = ("2012,Lexus,LFA\n"
                 "2009,GMC,Yukon XL 1500\n"
                 "1965,Ford,Mustang\n"
                 "2005,Hyundai,Sonata\n"
                 "1995,Mercedes-Benz,C-Class\n")
     columns = '0:4,6:19,24:37'
     with make_file(contents) as fixed_file, make_file('') as csv_file:
         main(['--cols=' + columns, fixed_file, csv_file])
         self.assertEqual(open(csv_file).read(), expected)