def get_tables(year, month): from config import InterimCSV import csv2df.specification as spec import csv2df.reader as reader parsed_tables = [] csv_path = InterimCSV(year, month).path with reader.open_csv(csv_path) as csvfile: for csv_segment, pdef in reader.Reader(csvfile, spec.SPEC).items(): tables = extract_tables(csv_segment, pdef) parsed_tables.extend(tables) return parsed_tables
import csv2df.specification as spec import csv2df.reader as reader parsed_tables = [] csv_path = InterimCSV(year, month).path with reader.open_csv(csv_path) as csvfile: for csv_segment, pdef in reader.Reader(csvfile, spec.SPEC).items(): tables = extract_tables(csv_segment, pdef) parsed_tables.extend(tables) return parsed_tables if __name__ == "__main__": from config import InterimCSV, LATEST_DATE import csv2df.reader as reader import csv2df.specification as spec year, month = LATEST_DATE csv_path = InterimCSV(year, month).path with reader.open_csv(csv_path) as csvfile: parsed_tables = [] for csv_segment, pdef in reader.Reader(csvfile, spec.SPEC).items(): tables = extract_tables(csv_segment, pdef) parsed_tables.extend(tables) for t in tables: print() print(t) tables = get_tables(year, month)
def test_on_Path_runs_with_no_error(self, temp_path): assert open_csv(temp_path)
def test_on_Path_provides_readable_input(self, temp_path): with open_csv(temp_path) as f: assert f.readlines() == ["abc\n", "123"]
def test_on_string_argument_raises_TypeError(self): path_string = "abc.csv" with pytest.raises(TypeError): open_csv(path_string)
def test_open_is_called(self): assert open_csv(self.path_good) is True
def test_error_on_wrong_instance(self): with pytest.raises(TypeError): open_csv(self.path_bad)
'period': 4, 'value': 2044, 'year': 2000 }] checker = Validator(dfa, dfq, dfm) for c in check_points: assert checker.is_included(c) # Example 3 Read actual data by month and year year, month = 2017, 5 # 3.1 Access to csv file using path helper from config import PathHelper from csv2df.specification import SPEC csv_path = PathHelper.locate_csv(year, month) with open_csv(csv_path) as csvfile: dfa1, dfq1, dfm1 = get_dataframes(csvfile, SPEC) # 3.2 Access to csv file using Vintage class (identical to 3.1) from csv2df.runner import Vintage vint = Vintage(year, month) dfa2, dfq2, dfm2 = vint.dfs() assert dfa1.equals(dfa2) assert dfq1.equals(dfq2) assert dfm1.equals(dfm2) # validation assert vint.validate()
def __init__(self, year, month, helper=PathHelper): self.year, self.month = year, month self.folder_path = helper.get_processed_folder(year, month) csv_path = helper.locate_csv(year, month) with open_csv(csv_path) as csvfile: self.dfa, self.dfq, self.dfm = get_dataframes(csvfile)