Beispiel #1
0
 def test_missing_data(self):
     contents = dedent("""
         2012  Lexus             LFA
               Ford              Mustang
         2005  Hyundai           Sonata
         1995  Mercedes-Benz
     """).lstrip()
     columns = [(0, 4), (6, 19), (24, 31)]
     expected = [
         ["2012", "Lexus", "LFA"],
         ["", "Ford", "Mustang"],
         ["2005", "Hyundai", "Sonata"],
         ["1995", "Mercedes-Benz", ""],
     ]
     self.assertIterableEqual(
         parse_fixed_width_file(StringIO(contents), columns), expected)
Beispiel #2
0
 def test_uneven_columns(self):
     contents = dedent("""
         2012  Lexus             LFA
         2009  GMC               Yukon XL 1500
         1965  Ford              Mustang
         2005  Hyundai           Sonata
         1995  Mercedes-Benz     C-Class
     """).lstrip()
     columns = [(0, 4), (6, 19), (24, 37)]
     expected = [
         ["2012", "Lexus", "LFA"],
         ["2009", "GMC", "Yukon XL 1500"],
         ["1965", "Ford", "Mustang"],
         ["2005", "Hyundai", "Sonata"],
         ["1995", "Mercedes-Benz", "C-Class"],
     ]
     self.assertIterableEqual(
         parse_fixed_width_file(StringIO(contents), columns), expected)
Beispiel #3
0
 def test_two_exact_columns(self):
     contents = dedent("""
         2012  Lexus
         2009  GMC
         1965  Ford
         2005  Hyundai
         1995  Mercedes-Benz
     """).lstrip()
     columns = [(0, 4), (6, 19)]
     expected = [
         ["2012", "Lexus"],
         ["2009", "GMC"],
         ["1965", "Ford"],
         ["2005", "Hyundai"],
         ["1995", "Mercedes-Benz"],
     ]
     self.assertIterableEqual(
         parse_fixed_width_file(StringIO(contents), columns), expected)