def export(data, f_type, filename): """ Write data dictionary to JSON or CSV. Calls public methods found in external modules: Export.write_json() Export.write_csv() Parameters ---------- data: dict Dictionary containing frequency data f_type: str String denoting the file format filename: str String denoting the filename Returns ------- None """ Export.write_json(data, filename) \ if f_type == "json" \ else Export.write_csv(data, filename)
def test_write_csv(self): filename = os.path.join(sys.path[0], "test_csv_writing.csv") overview = { "this": [1, 2], "is": [3, 4], "a": [5, 6], "test": [7, 8] } Export.write_csv(overview, filename) with open(filename, "r") as test_csv: reader = csv.reader(test_csv) test_dict = dict((header, []) for header in next(reader)) for row in reader: for row_index, key in enumerate(test_dict.keys()): test_dict[key].append(int(row[row_index])) assert test_dict == overview os.remove(filename)