def test_sort_csv(): """Test md5 sum calculation""" data_file = create_file("User,Country,Age\nBen,US,24\nAlex,US,25\nAlex,PT,25") out_file = sort_csv(data_file) obs_out = file_2string(out_file) os.remove(out_file) assert obs_out == "User,Country,Age\nAlex,PT,25\nAlex,US,25\nBen,US,24\n"
def test_sort_csv(): """Test md5 sum calculation""" data_file = create_file( "User,Country,Age\nBen,US,24\nAlex,US,25\nAlex,PT,25") out_file = sort_csv(data_file) obs_out = file_2string(out_file) assert obs_out == "User,Country,Age\nAlex,PT,25\nAlex,US,25\nBen,US,24\n"
def test_sort_file(): """Test md5 sum calculation""" data_file = create_file("Ben,US,24\nAlex,US,25\nAlex,PT,25") out_file = sort_file(data_file) obs_out = file_2string(out_file) os.remove(out_file) assert obs_out == 'Alex,PT,25\nAlex,US,25\nBen,US,24\n'
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_2string(output_json) os.remove(output_json) assert obs_out == 'User,Country,Age\nAlex,US,25\n'
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, "test/output_json.csv", header_values=["User", "Country", "Age"]) obs_out = file_2string(output_json) assert obs_out == 'User,Country,Age\nAlex,US,25'
def test_xml2csv(): """Test xml2csv function creates a xml file and tests the md5 sum calculation""" xml_file = create_file("<root>\n<row>\n" "<User>Alex</User>\n" "<Country>US</Country>\n" "<Age>25</Age>\n</row>\n" "<row>\n<User>Ben</User>\n" "<Country>US</Country>S\n" "<Age>24</Age>\n" "</row>\n</root>", 'output.xml') output_xml = xml2csv(xml_file, "output_xml.csv", header_values=["User", "Country", "Age"]) obs_out = file_2string(output_xml) os.remove(output_xml) assert obs_out == "User,Country,Age\nAlex,US,25\nBen,US,24\n"
def test_xml2csv(): """Test xml2csv function creates a xml file and tests the md5 sum calculation""" xml_file = create_file( "<root>\n<row>\n" "<User>Alex</User>\n" "<Country>US</Country>\n" "<Age>25</Age>\n</row>\n" "<row>\n<User>Ben</User>\n" "<Country>US</Country>S\n" "<Age>24</Age>\n" "</row>\n</root>", 'output.xml') output_xml = xml2csv(xml_file, "output_xml.csv", header_values=["User", "Country", "Age"]) obs_out = file_2string(output_xml) os.remove(output_xml) assert obs_out == "User,Country,Age\nAlex,US,25\nBen,US,24\n"
def get_output_as_csv(dataset, engines, tmpdir, db): """Install dataset and return the output as a string version of the csv The string version of the csv output returned by this function can be compared directly to the expect_out values in the dataset test dictionaries. """ workdir = tmpdir.mkdtemp() workdir.chdir() script_module = get_script_module(dataset["name"]) script_module.SCRIPT.download(engines) script_module.SCRIPT.engine.final_cleanup() script_module.SCRIPT.engine.to_csv() # get filename and append .csv csv_file = engines.opts['table_name'].format(db=db, table=dataset["name"]) # csv engine already has the .csv extension if engines.opts["engine"] != 'csv': csv_file += '.csv' obs_out = file_2string(csv_file) os.chdir(retriever_root_dir) return obs_out
def test_crosstab_from_csv(): crosstab_module = get_script_module('crosstab') crosstab_module.SCRIPT.download(csv_engine) crosstab_module.SCRIPT.engine.disconnect() obs_out = file_2string("crosstab_crosstab.txt") assert obs_out == crosstab['expect_out']
def test_csv_from_csv(): simple_csv_module = get_script_module('simple_csv') simple_csv_module.SCRIPT.download(csv_engine) simple_csv_module.SCRIPT.engine.disconnect() obs_out = file_2string("simple_csv_simple_csv.txt") assert obs_out == simple_csv['expect_out']