예제 #1
0
 def test_overwrite_although_file_exists(self, write_line, exists):
     exists.return_value = True
     csvfile.CsvFile('ANY_FILE_NAME', ['ANY_COLUMN', 'OTHER_COLUMN'],
                     overwrite=True)
     exists.assert_called_once_with('ANY_FILE_NAME')
     write_line.assert_called_once_with('ANY_COLUMN,OTHER_COLUMN\n',
                                        'ANY_FILE_NAME', 'w')
예제 #2
0
 def setUp(self):
     with mock.patch('os.path.exists') as exists:
         with mock.patch('flexp.utils.read_line') as read_line:
             exists.return_value = True
             read_line.return_value = 'ANY_COLUMN,OTHER_COLUMN\n'
             self.csv = csvfile.CsvFile('ANY_FILE_NAME',
                                        ['ANY_COLUMN', 'OTHER_COLUMN'])
     self.write_line = mock.patch('flexp.utils.write_line').start()
     logging.disable(logging.CRITICAL)  # We don't want logging in tests
예제 #3
0
    def test_init_creates_file_not_exists(self, write_line, exists):
        exists.return_value = False
        csv = csvfile.CsvFile('ANY_FILE_NAME', ['ANY_COLUMN', 'OTHER_COLUMN'])
        write_line.assert_called_once_with('ANY_COLUMN,OTHER_COLUMN\n',
                                           'ANY_FILE_NAME', 'w')
        exists.assert_called_once_with('ANY_FILE_NAME')

        self.assertEqual(csv.filename, 'ANY_FILE_NAME')
        self.assertListEqual(csv.column_names, ['ANY_COLUMN', 'OTHER_COLUMN'])
예제 #4
0
 def setUp(self):
     with mock.patch('os.path.exists') as exists:
         with mock.patch('flexp.utils.read_line') as read_line:
             exists.return_value = True
             read_line.return_value = 'ANY_COLUMN,OTHER_COLUMN\n'
             self.csv = csvfile.CsvFile('ANY_FILE_NAME',
                                        ['ANY_COLUMN', 'OTHER_COLUMN'])
     self.write_line = mock.patch('flexp.utils.write_line').start()
     self.csv._validate_columns = mock.patch.object(
         self.csv, '_validate_columns').start()
예제 #5
0
    def test_init_doesnt_create_file_if_exists(self, write_line, read_line,
                                               exists):
        read_line.return_value = 'ANY_COLUMN,OTHER_COLUMN\n'
        exists.return_value = True
        csv = csvfile.CsvFile('ANY_FILE_NAME', ['ANY_COLUMN', 'OTHER_COLUMN'])
        write_line.assert_not_called()
        exists.assert_called_once_with('ANY_FILE_NAME')

        self.assertEqual(csv.filename, 'ANY_FILE_NAME')
        self.assertListEqual(csv.column_names, ['ANY_COLUMN', 'OTHER_COLUMN'])