def test_import_csv_to_traced_data_iterable(self): file_path = "tests/traced_data/resources/csv_import_data.csv" with open(file_path, "r") as f: exported = list(generate_traced_data_iterable()) imported = list(TracedDataCSVIO.import_csv_to_traced_data_iterable("test_user", f)) self.assertEqual(len(exported), len(imported)) for x, y in zip(exported, imported): self.assertSetEqual(set(x.items()), set(y.items()))
help="CSV file containing demographics of CAPYEI students. ") parser.add_argument("json_output_path", metavar="json-output-path", help="Path to serialized TracedData JSON file") args = parser.parse_args() user = args.user phone_uuid_path = args.phone_uuid_table_path demog_dataset_path = args.demog_dataset_path json_output_path = args.json_output_path with open(phone_uuid_path, "r") as f: phone_uuids = PhoneNumberUuidTable.load(f) with open(demog_dataset_path, "r") as f: traced_demog = TracedDataCSVIO.import_csv_to_traced_data_iterable( user, f) traced_demog = list(traced_demog) for td in traced_demog: uuid_dict = { "avf_phone_id": phone_uuids.add_phone(td["final_phone"]) } td.append_data( uuid_dict, Metadata(user, Metadata.get_call_location(), time.time())) # Write the UUIDs out to a file with open(phone_uuid_path, "w") as f: phone_uuids.dump(f) # Output TracedData to JSON. IOUtils.ensure_dirs_exist(json_output_path)