Example #1
0
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']))
        create_file(test['raw_data'], os.path.join(HOME_DIR, "raw_data", test['name'], test['name'] + '.txt'))
        create_file(test['script'], os.path.join(HOME_DIR, "scripts", test['name'] + '.json'))
        compile_json(os.path.join(HOME_DIR, "scripts", test['name']))
Example #2
0
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']))
        create_file(test['raw_data'], os.path.join(HOME_DIR, "raw_data", test['name'], test['name'] + '.txt'))
        create_file(test['script'], os.path.join(HOME_DIR, "scripts", test['name'] + '.json'))
        compile_json(os.path.join(HOME_DIR, "scripts", test['name']))
Example #3
0
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)
        compile_json(os.path.join(HOME_DIR, "scripts", test['name']))
Example #4
0
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)
        compile_json(os.path.join(HOME_DIR, "scripts", test['name']))
Example #5
0
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"
Example #6
0
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"
Example #7
0
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'
Example #8
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 #9
0
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'
Example #10
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 #11
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_2string(output_json)
    os.remove(output_json)
    assert obs_out == 'User,Country,Age\nAlex,US,25\n'
Example #12
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,
                           "test/output_json.csv",
                           header_values=["User", "Country", "Age"])
    obs_out = file_2string(output_json)
    assert obs_out == 'User,Country,Age\nAlex,US,25'
Example #13
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 #14
0
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"
Example #15
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 #16
0
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"
Example #17
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 #18
0
def test_getmd5_path():
    """Test md5 sum calculation given a path to data source"""
    data_file = create_file('a,b,c\n1,2,3\n4,5,6\n')
    assert getmd5(data=data_file, data_type='file') == '0bec5bf6f93c547bc9c6774acaf85e1a'
Example #19
0
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
Example #20
0
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
Example #21
0
def test_getmd5_path():
    """Test md5 sum calculation given a path to data source"""
    data_file = create_file('a,b,c\n1,2,3\n4,5,6\n')
    assert getmd5(data=data_file,
                  data_type='file') == '0bec5bf6f93c547bc9c6774acaf85e1a'