Exemple #1
0
def path_with_directories_and_file(tmp_path_factory):
    test_path = tmp_path_factory.mktemp("directories_with_file")
    existing_dir = test_path / EXISTING_DIRNAME
    non_existing_dir = test_path / NON_EXISTING_DIRNAME
    existing_dir.mkdir()

    d_content = {
        str(existing_dir.resolve()): {
            "comment": "test123"
        },
        str(non_existing_dir.resolve()): {
            "comment": "bla"
        },
    }
    d_expect = [
        {
            "directory": str(existing_dir.resolve()),
            "comment": "test123",
            "exists": True,
        },
        {
            "directory": str(non_existing_dir.resolve()),
            "comment": "bla",
            "exists": False,
        },
    ]
    home.cfg = get_config(test_path)
    with open(home.cfg.directories_file, "w") as dfile:
        yaml.dump(d_content, dfile)
    return test_path, d_expect
Exemple #2
0
def test_get_current_location(prov_files, test_filenames, prov_path_with_agents):
    provit.prov.cfg = get_config(prov_path_with_agents)
    prov = provit.prov.Provenance(prov_files / test_filenames["TEST_FILE"])
    prov.add(
        agents=["wikidata"], activity="testing", description="this is a testfunction"
    )
    assert str(prov.get_current_location()) == str(
        prov_files / test_filenames["TEST_FILE"]
    )
Exemple #3
0
def test_load_agent_profiles(prov_path_with_agents):
    agent.cfg = get_config(prov_path_with_agents)
    agents = agent.load_agent_profiles()
    # First we check for correct structure of returned agents_list
    assert len(agents) == 3
    assert isinstance(agents[0], agent.SoftwareAgent)
    assert isinstance(agents[1], agent.PersonAgent)
    assert isinstance(agents[2], agent.OrganizationAgent)
    # Then we check for correct properties of each agent
    for i, a in enumerate([SA, PA, OA]):
        check_attrs(agents[i], a)
Exemple #4
0
def app(path_with_directories, monkeypatch):
    test_path, _ = path_with_directories
    cfg = get_config(test_path)

    def mock_home():
        return test_path

    monkeypatch.setattr(home, "cfg", cfg)
    monkeypatch.setattr(Path, "home", mock_home)
    app = backend.create_app(cfg)
    return app
Exemple #5
0
def prov_path_with_agents(tmp_path_factory):
    prov_path = tmp_path_factory.mktemp("with_agents")
    cfg = get_config(prov_path)
    for agent_file in [
            "wikidata.yaml",
            "johndoe.yaml",
            "gephi_0.9.2.yaml",
            "invalid.yaml",
    ]:
        origin_path = Path(__file__).resolve().parent / "fixtures"
        shutil.copy(str(origin_path / agent_file), str(cfg.agents_dir))
    return prov_path
Exemple #6
0
def path_with_directories(tmp_path_factory):
    test_path = tmp_path_factory.mktemp("directories_with_file")
    existing_dir = test_path / EXISTING_DIRNAME
    non_existing_dir = test_path / NON_EXISTING_DIRNAME
    existing_dir.mkdir()

    # Add noprov file without provenance
    noprov_file = test_path / NOPROV_FILE
    noprov_file.touch()

    # Add data file with provenance
    data_file = test_path / DATA_FILE
    data_file.touch()
    data_file_prov = Provenance(data_file)
    data_file_prov.add(agents=[TEST_AGENT],
                       activity="testactivity",
                       description=TEST_ACTIVITY)
    data_file_prov.save()

    d_content = {
        str(existing_dir.resolve()): {
            "comment": "test123"
        },
        str(non_existing_dir.resolve()): {
            "comment": "bla"
        },
    }
    d_expect = [
        {
            "directory": str(existing_dir.resolve()),
            "comment": "test123",
            "exists": True,
        },
        {
            "directory": str(non_existing_dir.resolve()),
            "comment": "bla",
            "exists": False,
        },
    ]
    home.cfg = get_config(test_path)
    with open(home.cfg.directories_file, "w") as dfile:
        yaml.dump(d_content, dfile)
    return test_path, d_expect
Exemple #7
0
def test_get_agents(prov_files, test_filenames, prov_path_with_agents):
    provit.prov.cfg = get_config(prov_path_with_agents)
    prov = provit.prov.Provenance(prov_files / test_filenames["TEST_FILE"])
    prov.add(
        agents=["wikidata"], activity="testing", description="this is a testfunction"
    )
    prov.add(
        agents=["gephi_0.9.2"], activity="testing", description="this is a testfunction"
    )
    prov.add(
        agents=["johndoe"], activity="testing", description="this is a testfunction"
    )
    agent_list = prov.get_agents()
    assert len(agent_list) == 3
    assert prov.get_agents(include_primary_sources=True)["wikidata"] == {
        "slug": "wikidata",
        "uri": "http://vocab.ub.uni-leipzig.de/provit/wikidata",
        "type": "Organization",
        "name": ["Wikidata"],
        "homepage": ["https://www.wikidata.org"],
    }
Exemple #8
0
def test_agent_factory(prov_path_with_agents):
    agent.cfg = get_config(prov_path_with_agents)
    agents = agent.load_agent_profiles()
    check_attrs(agent.agent_factory("johndoe", agent.PersonAgent), PA)
Exemple #9
0
def test_load_agent_profile_invalid_agent(prov_path_with_agents):
    agent.cfg = get_config(prov_path_with_agents)
    assert agent.load_agent_profile("invalid") == None
Exemple #10
0
def test_load_agent_profiles_on_empty(tmp_path):
    agent.cfg = get_config(tmp_path)
    agents = agent.load_agent_profiles()
    print(agents)
    assert agents == []