Example #1
0
 def test_file_not_found_exception_path(self):
     """A FileNotFoundException reports the path of the missing file."""
     csv_file = os.path.join(self._testdir, 'file.csv')
     actual = ''
     try:
         read_csv_file(csv_file)
     except FileNotFoundException, err:
         actual = err.parameter
Example #2
0
 def test_file_read_exception_path(self):
     """A FileReadException reports the path of the missing file."""
     csv_file = os.path.join(self._testdir, 'file.csv')
     actual = ''
     with open(csv_file, 'wb') as fp:
         fp.write("A,B\n1,2\n".encode('utf-16'))
     try:
         read_csv_file(csv_file)
     except FileReadException, err:
         actual = err.parameter
Example #3
0
 def test_missing_data_is_blank(self):
     """Blank values are added to missing data fields."""
     csv_file = os.path.join(self._testdir, 'file.csv')
     with open(csv_file, 'wb') as fp:
         fp.write("A,B,C\n1,2\n".encode('utf-8'))
     result = read_csv_file(csv_file)
     self.assertEqual(result[0]['C'], '')
Example #4
0
 def test_file_read_dos_line_endings(self):
     """A csv file with dos line endings can be read"""
     csv_file = os.path.join(self._testdir, 'file.csv')
     with open(csv_file, 'wb') as fp:
         fp.write("A,B\r\n1,2\r\n".encode('utf-8'))
     result = read_csv_file(csv_file)
     self.assertEqual(result,  [{ 'A': u'1', 'B': u'2'}])
Example #5
0
    def test_resources_values_quotes(self):
        """Check the resource file values do not contain quotes.

        This test is used to verify that no spaces were added between entries
        and the commas separating them (in case the file was edited manually),
        otherwise the string contains the quotes used to delimit it.
        """
        for file in self.files:
            for entry in read_csv_file(file):
                self.assertTrue('"' not in ','.join(entry.values()))
Example #6
0
    def load_species(self, table, filename):
        """Update the species table with the records from the file.

        arguments:
            table (dict): maps BirdLife common name to the equivalent species
                used by eBird.
            filename (str): the path to a csv formatted file.
        """
        species_table = read_csv_file(filename)
        for entry in species_table:
            key = entry['BirdLife common name']
            table[key] = entry
Example #7
0
 def test_load_resources(self):
     """All the resource files can be loaded."""
     for file in self.files:
         table = read_csv_file(file)
         self.assertTrue(table)