Example #1
0
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']
Example #2
0
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']
Example #3
0
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
Example #4
0
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']
Example #5
0
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']
Example #6
0
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']
Example #7
0
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
Example #8
0
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 get_output_as_csv(dataset, engines, tmpdir, db):
    """Install dataset and return the output as a string version of the csv."""
    workdir = tmpdir.mkdtemp()
    workdir.chdir()

    # Since we are writing scripts to the .retriever directory,
    # we don't have to change to the main source directory in order
    # to have the scripts loaded
    script_module = get_script_module(dataset["name"])
    script_module.download(engines)
    script_module.engine.final_cleanup()
    script_module.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_2list(csv_file)
    os.chdir(retriever_root_dir)
    return obs_out
Example #10
0
def get_output_as_csv(dataset, engines, tmpdir, db):
    """Install dataset and return the output as a string version of the csv."""
    workdir = tmpdir.mkdtemp()
    workdir.chdir()

    # Since we are writing scripts to the .retriever directory,
    # we don't have to change to the main source directory in order
    # to have the scripts loaded
    script_module = get_script_module(dataset["name"])
    script_module.download(engines)
    script_module.engine.final_cleanup()
    script_module.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_2list(csv_file)
    os.chdir(retriever_root_dir)
    return obs_out