def test_is_csv_file_func(self): f = 'csv_files/1.csv' with CSVParser(f, 'rt') as cp: assert cp.is_csv_file(f) == True f = 'csv_files/5.csv' with CSVParser(f, 'rt'): self.assertRaises(NotValidCSVFileError)
def test_field_names(self): with CSVParser('csv_files/1.csv', 'rt') as cp: expected = [ 'mon', 'tue', 'some_column1', 'wed', 'thu', 'fri', 'description' ] cp.get_field_names() == expected
def test_csv_parser(self): csvp = CSVParser('1.txt') assert csvp.filename == '1.txt' assert csvp.mode == 'rt'
def test_current_file_func(self): with CSVParser('csv_files/1.csv', 'rt') as cp: assert cp.get_current_file == 'csv_files/1.csv'
def test_file_exists(self): with CSVParser('csv'): self.assertRaises(FileNotFoundError)
def test_file_invalid_csv(self): with CSVParser('a.txt'): self.assertRaises(NotValidCSVFileError)
import sys from csvparser import CSVParser # from models import Table from utils import create_session session = create_session('db.sqlite3') FILE_NAME = sys.argv[1] with open(FILE_NAME, 'r', encoding='utf8') as csv_file: csv_parser = CSVParser(csv_file, session=session) csv_parser.parse() print('Done!')