Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jun 24, 2024
1 parent 3f0c05e commit c342aef
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 129 deletions.
20 changes: 5 additions & 15 deletions tests/test_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def test_annotation_limit(self, namespace, limit, admin, n_projects):
@pytest.mark.parametrize("admin", ["private_test"])
def test_order_by(self, namespace, admin, order_by, first_name):
with PEPDBAgentContextManager(add_data=True) as agent:
result = agent.annotation.get(
namespace=namespace, admin=admin, order_by=order_by
)
result = agent.annotation.get(namespace=namespace, admin=admin, order_by=order_by)
assert result.results[0].name == first_name

@pytest.mark.parametrize(
Expand Down Expand Up @@ -164,9 +162,7 @@ def test_name_search(self, namespace, query, found_number):
)
def test_name_search_private(self, namespace, query, found_number):
with PEPDBAgentContextManager(add_data=True) as agent:
result = agent.annotation.get(
namespace=namespace, query=query, admin="private_test"
)
result = agent.annotation.get(namespace=namespace, query=query, admin="private_test")
assert len(result.results) == found_number

@pytest.mark.parametrize(
Expand Down Expand Up @@ -250,9 +246,7 @@ def test_search_filter_zero_prj(self, namespace, query, found_number):
["namespace1", "ame", 2],
],
)
def test_search_incorrect_filter_by_string(
self, namespace, query, found_number
):
def test_search_incorrect_filter_by_string(self, namespace, query, found_number):
with PEPDBAgentContextManager(add_data=True) as agent:
date_now = datetime.datetime.now() - datetime.timedelta(days=2)
date_old = date_now - datetime.timedelta(days=2)
Expand Down Expand Up @@ -308,9 +302,7 @@ def test_get_annotation_by_rp_enpty_list(self):
["namespace1", "ame", 2],
],
)
def test_search_incorrect_incorrect_pep_type(
self, namespace, query, found_number
):
def test_search_incorrect_incorrect_pep_type(self, namespace, query, found_number):
with PEPDBAgentContextManager(add_data=True) as agent:

with pytest.raises(ValueError):
Expand All @@ -322,9 +314,7 @@ def test_search_incorrect_incorrect_pep_type(
["namespace1", "ame", 2],
],
)
def test_project_list_without_annotation(
self, namespace, query, found_number
):
def test_project_list_without_annotation(self, namespace, query, found_number):
with PEPDBAgentContextManager(add_data=True) as agent:
result = agent.annotation.get_projects_list(
namespace=namespace,
Expand Down
16 changes: 4 additions & 12 deletions tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,10 @@ def test_count_project_one(self, namespace, name):
def test_remove_from_favorite(self, namespace, name):
with PEPDBAgentContextManager(add_data=True) as agent:
agent.user.add_project_to_favorites("namespace1", namespace, name, "default")
agent.user.add_project_to_favorites(
"namespace1", namespace, "amendments2", "default"
)
agent.user.add_project_to_favorites("namespace1", namespace, "amendments2", "default")
result = agent.user.get_favorites("namespace1")
assert result.count == len(result.results) == 2
agent.user.remove_project_from_favorites(
"namespace1", namespace, name, "default"
)
agent.user.remove_project_from_favorites("namespace1", namespace, name, "default")
result = agent.user.get_favorites("namespace1")
assert result.count == len(result.results) == 1

Expand All @@ -114,9 +110,7 @@ def test_remove_from_favorite(self, namespace, name):
def test_remove_from_favorite_error(self, namespace, name):
with PEPDBAgentContextManager(add_data=True) as agent:
with pytest.raises(ProjectNotInFavorites):
agent.user.remove_project_from_favorites(
"namespace1", namespace, name, "default"
)
agent.user.remove_project_from_favorites("namespace1", namespace, name, "default")

@pytest.mark.parametrize(
"namespace, name",
Expand All @@ -128,9 +122,7 @@ def test_favorites_duplication_error(self, namespace, name):
with PEPDBAgentContextManager(add_data=True) as agent:
agent.user.add_project_to_favorites("namespace1", namespace, name, "default")
with pytest.raises(ProjectAlreadyInFavorites):
agent.user.add_project_to_favorites(
"namespace1", namespace, name, "default"
)
agent.user.add_project_to_favorites("namespace1", namespace, name, "default")

@pytest.mark.parametrize(
"namespace, name",
Expand Down
31 changes: 9 additions & 22 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class TestProject:
def test_create_project(self):
with PEPDBAgentContextManager(add_data=False) as agent:
prj = peppy.Project(list_of_available_peps()["namespace3"]["subtables"])
agent.project.create(
prj, namespace="test", name="imply", overwrite=True
)
agent.project.create(prj, namespace="test", name="imply", overwrite=True)
assert True

def test_create_project_from_dict(self):
Expand Down Expand Up @@ -49,9 +47,7 @@ def test_create_project_from_dict(self):
)
def test_get_project(self, namespace, name):
with PEPDBAgentContextManager(add_data=True) as agent:
kk = agent.project.get(
namespace=namespace, name=name, tag="default", raw=False
)
kk = agent.project.get(namespace=namespace, name=name, tag="default", raw=False)
ff = peppy.Project(get_path_to_example_file(namespace, name))
assert kk == ff

Expand Down Expand Up @@ -108,7 +104,8 @@ def test_get_samples_raw(self, namespace, name):
orgiginal_prj = peppy.Project(get_path_to_example_file(namespace, name))

assert (
prj_samples == orgiginal_prj.to_dict(extended=True, orient="records")["_sample_dict"]
prj_samples
== orgiginal_prj.to_dict(extended=True, orient="records")["_sample_dict"]
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -205,9 +202,7 @@ def test_fork_projects(self, namespace, name):
fork_tag="new_tag",
)

assert agent.project.exists(
namespace="new_namespace", name="new_name", tag="new_tag"
)
assert agent.project.exists(namespace="new_namespace", name="new_name", tag="new_tag")
result = agent.annotation.get(
namespace="new_namespace", name="new_name", tag="new_tag"
)
Expand All @@ -234,13 +229,9 @@ def test_parent_project_delete(self, namespace, name):
fork_tag="new_tag",
)

assert agent.project.exists(
namespace="new_namespace", name="new_name", tag="new_tag"
)
assert agent.project.exists(namespace="new_namespace", name="new_name", tag="new_tag")
agent.project.delete(namespace=namespace, name=name, tag="default")
assert agent.project.exists(
namespace="new_namespace", name="new_name", tag="new_tag"
)
assert agent.project.exists(namespace="new_namespace", name="new_name", tag="new_tag")

@pytest.mark.parametrize(
"namespace, name",
Expand All @@ -263,13 +254,9 @@ def test_child_project_delete(self, namespace, name):
fork_tag="new_tag",
)

assert agent.project.exists(
namespace="new_namespace", name="new_name", tag="new_tag"
)
assert agent.project.exists(namespace="new_namespace", name="new_name", tag="new_tag")
assert agent.project.exists(namespace=namespace, name=name, tag="default")
agent.project.delete(
namespace="new_namespace", name="new_name", tag="new_tag"
)
agent.project.delete(namespace="new_namespace", name="new_name", tag="new_tag")
assert agent.project.exists(namespace=namespace, name=name, tag="default")

@pytest.mark.parametrize(
Expand Down
14 changes: 6 additions & 8 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .utils import PEPDBAgentContextManager


@pytest.mark.skipif(
not PEPDBAgentContextManager().db_setup(),
reason="DB is not setup",
Expand Down Expand Up @@ -39,9 +40,7 @@ def test_retrieve_raw_sample(self, namespace, name, sample_name):
["namespace2", "custom_index", "frog_1"],
],
)
def test_retrieve_sample_with_modified_sample_id(
self, namespace, name, sample_name
):
def test_retrieve_sample_with_modified_sample_id(self, namespace, name, sample_name):
with PEPDBAgentContextManager(add_data=True) as agent:
one_sample = agent.sample.get(namespace, name, sample_name, raw=False)
assert isinstance(one_sample, peppy.Sample)
Expand Down Expand Up @@ -141,7 +140,9 @@ def test_project_timestamp_was_changed(self, namespace, name, sample_name):
)
annotation2 = agent.annotation.get(namespace, name, "default")

assert annotation1.results[0].last_update_date != annotation2.results[0].last_update_date
assert (
annotation1.results[0].last_update_date != annotation2.results[0].last_update_date
)

@pytest.mark.parametrize(
"namespace, name, sample_name",
Expand Down Expand Up @@ -201,10 +202,7 @@ def test_add_sample(self, namespace, name, tag, sample_dict):
)
def test_overwrite_sample(self, namespace, name, tag, sample_dict):
with PEPDBAgentContextManager(add_data=True) as agent:
assert (
agent.project.get(namespace, name, raw=False).get_sample("pig_0h").time
== "0"
)
assert agent.project.get(namespace, name, raw=False).get_sample("pig_0h").time == "0"
agent.sample.add(namespace, name, tag, sample_dict, overwrite=True)

assert (
Expand Down
35 changes: 13 additions & 22 deletions tests/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .utils import PEPDBAgentContextManager


@pytest.mark.skipif(
not PEPDBAgentContextManager().db_setup(),
reason="DB is not setup",
Expand Down Expand Up @@ -35,9 +36,7 @@ def test_update_project_name(self, namespace, name, new_name):
)
def test_update_project_name_in_config(self, namespace, name, new_name):
with PEPDBAgentContextManager(add_data=True) as agent:
prj = agent.project.get(
namespace=namespace, name=name, raw=False, with_id=True
)
prj = agent.project.get(namespace=namespace, name=name, raw=False, with_id=True)
prj.name = new_name
agent.project.update(
namespace=namespace,
Expand Down Expand Up @@ -71,9 +70,7 @@ def test_update_project_tag(self, namespace, name, new_tag):
["namespace2", "derive", "desc5 f"],
],
)
def test_update_project_description(
self, namespace, name, new_description
):
def test_update_project_description(self, namespace, name, new_description):
with PEPDBAgentContextManager(add_data=True) as agent:
prj = agent.project.get(namespace=namespace, name=name, raw=False)
prj.description = new_description
Expand All @@ -95,13 +92,9 @@ def test_update_project_description(
["namespace1", "amendments1", "desc1 f"],
],
)
def test_update_project_description_in_config(
self, namespace, name, new_description
):
def test_update_project_description_in_config(self, namespace, name, new_description):
with PEPDBAgentContextManager(add_data=True) as agent:
prj = agent.project.get(
namespace=namespace, name=name, raw=False, with_id=True
)
prj = agent.project.get(namespace=namespace, name=name, raw=False, with_id=True)
prj.description = new_description
agent.project.update(
namespace=namespace,
Expand Down Expand Up @@ -230,13 +223,15 @@ def test_project_can_have_2_sample_names(self, namespace, name):
ensure that update works correctly
"""
with PEPDBAgentContextManager(add_data=True) as agent:
new_prj = agent.project.get(
namespace=namespace, name=name, raw=False, with_id=True
)
new_prj = agent.project.get(namespace=namespace, name=name, raw=False, with_id=True)
prj_dict = new_prj.to_dict(extended=True, orient="records")

prj_dict["_sample_dict"].append(
{"file": "data/frog23_data.txt", "protocol": "anySample3Type", "sample_name": "frog_2"}
{
"file": "data/frog23_data.txt",
"protocol": "anySample3Type",
"sample_name": "frog_2",
}
)
prj_dict["_sample_dict"].append(
{
Expand Down Expand Up @@ -282,13 +277,9 @@ def test_update_whole_project_with_id(self, namespace, name):
["namespace1", "amendments1"],
],
)
def test_update_project_with_duplicated_sample_guids(
self, namespace, name
):
def test_update_project_with_duplicated_sample_guids(self, namespace, name):
with PEPDBAgentContextManager(add_data=True) as agent:
new_prj = agent.project.get(
namespace=namespace, name=name, raw=True, with_id=True
)
new_prj = agent.project.get(namespace=namespace, name=name, raw=True, with_id=True)
new_prj["_sample_dict"].append(new_prj["_sample_dict"][0])

with pytest.raises(ProjectDuplicatedSampleGUIDsError):
Expand Down
Loading

0 comments on commit c342aef

Please sign in to comment.