def setup_module(): """Put raw data and scripts in appropriate .retriever directories.""" for test in tests: if not os.path.exists(os.path.join(HOME_DIR, "raw_data", test['name'])): os.makedirs(os.path.join(HOME_DIR, "raw_data", test['name'])) rd_path = os.path.join(HOME_DIR, "raw_data", test['name'], test['name'] + '.txt') create_file(test['raw_data'], rd_path) path_js = os.path.join(HOME_DIR, "scripts", test['name'] + '.json') with open(path_js, 'w') as js: json.dump(test['script'], js, indent=2) read_json(os.path.join(HOME_DIR, "scripts", test['name']))
def setup_module(): """Put raw data and scripts in appropriate .retriever directories.""" for test in tests: if not os.path.exists(os.path.join(HOME_DIR, "raw_data", test['name'])): os.makedirs(os.path.join(HOME_DIR, "raw_data", test['name'])) rd_path = os.path.join(HOME_DIR, "raw_data", test['name'], test['name'] + '.csv') create_file(test['raw_data'], rd_path) path_js = os.path.join(HOME_DIR, "scripts", test['name'] + '.json') with open(path_js, 'w') as js: json.dump(test['script'], js, indent=2) read_json(os.path.join(HOME_DIR, "scripts", test['name']))
def test_sort_file(): """Test md5 sum calculation.""" data_file = create_file(['Ben,US,24', 'Alex,US,25', 'Alex,PT,25']) out_file = sort_file(data_file) obs_out = file_2list(out_file) os.remove(out_file) assert obs_out == ['Alex,PT,25', 'Alex,US,25', 'Ben,US,24']
def test_sort_file(): """Test md5 sum calculation.""" data_file = create_file(['Ben,US,24', 'Alex,US,25', 'Alex,PT,25']) out_file = sort_file(data_file) obs_out = file_2list(out_file) os.remove(out_file) assert obs_out == ['Alex,PT,25', 'Alex,US,25', 'Ben,US,24']
def test_json2csv(test_name, json_data, header_values, row_key, expected): """Test json2csv function. Creates a json file and tests the md5 sum calculation. """ json_file = create_file(json_data, 'output.json') output_json = json2csv(json_file, "output_json.csv", header_values=header_values, row_key=row_key) obs_out = file_2list(output_json) os.remove(output_json) assert obs_out == expected
def test_json2csv(): """Test json2csv function. Creates a json file and tests the md5 sum calculation. """ json_file = create_file([ """[ {"User": "******", "Country": "US", "Age": "25"} ]"""], 'output.json') output_json = json2csv(json_file, "output_json.csv", header_values=["User", "Country", "Age"]) obs_out = file_2list(output_json) os.remove(output_json) assert obs_out == ['User,Country,Age', 'Alex,US,25']
def test_json2csv(): """Test json2csv function. Creates a json file and tests the md5 sum calculation. """ json_file = create_file([ """[ {"User": "******", "Country": "US", "Age": "25"} ]"""], 'output.json') output_json = json2csv(json_file, "output_json.csv", header_values=["User", "Country", "Age"]) obs_out = file_2list(output_json) os.remove(output_json) assert obs_out == ['User,Country,Age', 'Alex,US,25']
def test_xml2csv(): """Test xml2csv function. Creates a xml file and tests the md5 sum calculation. """ xml_file = create_file([ '<root>', '<row>', '<User>Alex</User>', '<Country>US</Country>', '<Age>25</Age>', '</row>', '<row>', '<User>Ben</User>', '<Country>US</Country>', '<Age>24</Age>', '</row>', '</root>' ], 'output.xml') output_xml = xml2csv(xml_file, "output_xml.csv", header_values=["User", "Country", "Age"]) obs_out = file_2list(output_xml) os.remove(output_xml) assert obs_out == ['User,Country,Age', 'Alex,US,25', 'Ben,US,24']
def test_xml2csv(test_name, xml_data, header_values, empty_rows, expected): """Test xml2csv function. Creates a xml file and tests the md5 sum calculation. """ xml_file = create_file(xml_data, 'output.xml') input_file = xml_file outputfile = "output_xml.csv" output_xml = xml2csv_test(input_file, outputfile, header_values, row_tag="row") obs_out = file_2list(output_xml) os.remove(output_xml) assert obs_out == expected
def test_xml2csv(): """Test xml2csv function. Creates a xml file and tests the md5 sum calculation. """ xml_file = create_file(['<root>', '<row>', '<User>Alex</User>', '<Country>US</Country>', '<Age>25</Age>', '</row>', '<row>', '<User>Ben</User>', '<Country>US</Country>', '<Age>24</Age>', '</row>', '</root>'], 'output.xml') output_xml = xml2csv(xml_file, "output_xml.csv", header_values=["User", "Country", "Age"]) obs_out = file_2list(output_xml) os.remove(output_xml) assert obs_out == ['User,Country,Age', 'Alex,US,25', 'Ben,US,24']
def test_getmd5_path(): """Test md5 sum calculation given a path to data source.""" data_file = create_file(['a,b,c', '1,2,3', '4,5,6']) exp_hash = '0bec5bf6f93c547bc9c6774acaf85e1a' assert getmd5(data=data_file, data_type='file') == exp_hash
def test_getmd5_path(): """Test md5 sum calculation given a path to data source.""" data_file = create_file(['a,b,c', '1,2,3', '4,5,6']) exp_hash = '0bec5bf6f93c547bc9c6774acaf85e1a' assert getmd5(data=data_file, data_type='file') == exp_hash