Exemple #1
0
def test_taxonomy_check_invalid_file_path():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    categorization_project_id = CONFIG["projects"]["minimal_categorization"]
    project = client.projects.by_resource_id(categorization_project_id)
    filepath = "/does_not_exist/temp_taxonomy.csv"

    with pytest.raises(IOError):
        csv.from_taxonomy(project, filepath)
Exemple #2
0
def test_taxonomy_check_invalid_project_type():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    master_project_id = CONFIG["projects"]["minimal_mastering"]
    project = client.projects.by_resource_id(master_project_id)
    filepath = os.path.join(get_toolbox_root_dir(),
                            "tests/data_io/temp_taxonomy.csv")

    with pytest.raises(TypeError):
        csv.from_taxonomy(project,
                          filepath,
                          csv_delimiter=",",
                          flatten_delimiter=",")
Exemple #3
0
def test_invalid_delimiters():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    categorization_project_id = CONFIG["projects"]["minimal_categorization"]
    project = client.projects.by_resource_id(categorization_project_id)
    filepath = os.path.join(get_toolbox_root_dir(),
                            "tests/data_io/temp_taxonomy.csv")

    with pytest.raises(ValueError):
        csv.from_taxonomy(project,
                          filepath,
                          csv_delimiter=",",
                          flatten_delimiter=",")
Exemple #4
0
def test_taxonomy_existing_file():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    categorization_project_id = CONFIG["projects"]["minimal_categorization"]
    project = client.projects.by_resource_id(categorization_project_id)
    filepath = os.path.join(get_toolbox_root_dir(),
                            "tests/data_io/temp_taxonomy2.csv")
    f = open(filepath, "w")
    f.write("Temporary file")
    f.close()

    with pytest.raises(FileExistsError):
        csv.from_taxonomy(project, filepath, overwrite=False)
    os.remove(filepath)
Exemple #5
0
def test_taxonomy_missing():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    categorization_project_id = CONFIG["projects"][
        "categorization_no_taxonomy"]
    project = client.projects.by_resource_id(categorization_project_id)

    with tempfile.TemporaryDirectory() as tempdir:
        filepath = Path(tempdir) / "tests/data_io/temp_taxonomy_missing.csv"

        with pytest.raises(RuntimeError):
            csv.from_taxonomy(project,
                              filepath,
                              csv_delimiter=",",
                              flatten_delimiter="|")
Exemple #6
0
def test_taxonomy_export_csv():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    categorization_project_id = CONFIG["projects"]["minimal_categorization"]
    project = client.projects.by_resource_id(categorization_project_id)
    filepath = os.path.join(get_toolbox_root_dir(),
                            "tests/data_io/temp_taxonomy.csv")
    records_written = csv.from_taxonomy(project, filepath, csv_delimiter=",")
    list_written = list(io.open(filepath))
    list_ref = TAXONOMY_DATA

    assert len(list_ref) == len(list_written)
    assert len(list_ref) == records_written

    for i in range(len(list_ref)):
        assert list_ref[i] == list_written[i]
    os.remove(filepath)
Exemple #7
0
def test_taxonomy_overwrite_file():
    client = utils.client.create(**CONFIG["toolbox_test_instance"])
    categorization_project_id = CONFIG["projects"]["minimal_categorization"]
    project = client.projects.by_resource_id(categorization_project_id)
    filepath = os.path.join(get_toolbox_root_dir(),
                            "tests/data_io/temp_taxonomy3.csv")

    f = open(filepath, "w")
    f.write("Temporary file")
    f.close()

    records_written = csv.from_taxonomy(project, filepath, overwrite=True)
    list_ref = TAXONOMY_DATA
    list_written = list(io.open(filepath))

    assert records_written == len(list_ref)
    for i in range(len(list_ref)):
        assert list_ref[i] == list_written[i]
    os.remove(filepath)