-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DATAUP-765: assertify tests #3389
Changes from all commits
ecf0c31
9c2ec3d
3487342
7840bf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ def test_my_function(self): | |
config = ConfigTests() | ||
_job_state_data = TEST_JOBS | ||
|
||
def __init__(self, client_name=None, token=None): | ||
def __init__(self, client_name=None, token=None) -> None: | ||
if token is not None: | ||
assert isinstance(token, str) | ||
self.client_name = client_name | ||
|
@@ -326,9 +326,7 @@ def log_gen(log_params, total_lines=MAX_LOG_LINES): | |
lines = [] | ||
if skip < total_lines: | ||
for i in range(total_lines - skip): | ||
lines.append( | ||
{"is_error": 0, "line": "This is line {}".format(i + skip)} | ||
) | ||
lines.append({"is_error": 0, "line": f"This is line {i + skip}"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use f-string |
||
return {"last_line_number": max(total_lines, skip), "lines": lines} | ||
|
||
if job_id == JOB_COMPLETED: | ||
|
@@ -355,6 +353,7 @@ def log_gen(log_params, total_lines=MAX_LOG_LINES): | |
def sync_call(self, call, params): | ||
if call == "NarrativeService.list_objects_with_sets": | ||
return self._mock_ns_list_objects_with_sets(params) | ||
return None | ||
|
||
def _mock_ns_list_objects_with_sets(self, params): | ||
""" | ||
|
@@ -374,7 +373,7 @@ def _mock_ns_list_objects_with_sets(self, params): | |
if params.get("workspaces"): | ||
ws_name = params["workspaces"][0] | ||
dp_id = 999 | ||
dp_ref = "{}/{}".format(ws_id, dp_id) | ||
dp_ref = f"{ws_id}/{dp_id}" | ||
|
||
data = { | ||
"data": [ | ||
|
@@ -511,10 +510,7 @@ def _mock_ns_list_objects_with_sets(self, params): | |
data["data"] = list( | ||
filter( | ||
lambda x: any( | ||
[ | ||
x["object_info"][2].lower().startswith(t.lower()) | ||
for t in types | ||
] | ||
x["object_info"][2].lower().startswith(t.lower()) for t in types | ||
), | ||
data["data"], | ||
) | ||
|
@@ -535,7 +531,8 @@ def get_failing_mock_client(client_name, token=None): | |
|
||
|
||
class FailingMockClient: | ||
def __init__(self, token=None): | ||
def __init__(self, token=None) -> None: | ||
# nothing to do here | ||
pass | ||
|
||
def check_workspace_jobs(self, params): | ||
|
@@ -590,7 +587,7 @@ class assert_obj_method_called: | |
) | ||
""" | ||
|
||
def __init__(self, target, method_name, call_status=True): | ||
def __init__(self, target, method_name, call_status=True) -> None: | ||
self.target = target | ||
self.method_name = method_name | ||
self.call_status = call_status | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,10 @@ | |
""" | ||
import copy | ||
import os | ||
import re | ||
from unittest import mock | ||
|
||
import pytest | ||
import re | ||
from biokbase.narrative.common.url_config import URLS | ||
from biokbase.workspace.client import Workspace | ||
|
||
from biokbase.narrative.app_util import ( | ||
app_param, | ||
check_tag, | ||
|
@@ -19,10 +16,11 @@ | |
map_outputs_from_state, | ||
transform_param_value, | ||
) | ||
|
||
from biokbase.narrative.tests.conftest import narrative_vcr as vcr | ||
from biokbase.narrative.common.url_config import URLS | ||
from biokbase.narrative.tests import util | ||
from biokbase.narrative.tests.conftest import narrative_vcr as vcr | ||
from biokbase.narrative.upa import is_upa | ||
from biokbase.workspace.client import Workspace | ||
|
||
config = util.ConfigTests() | ||
user_name = config.get("users", "test_user") | ||
|
@@ -74,7 +72,7 @@ def set_ws_name(ws_name): | |
] | ||
|
||
|
||
@pytest.mark.parametrize("result,path,expected", get_result_sub_path_cases) | ||
@pytest.mark.parametrize(("result", "path", "expected"), get_result_sub_path_cases) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ruff prefers tuples to comma-separated strings, obviously! |
||
def test_get_result_sub_path(result, path, expected): | ||
assert get_result_sub_path(result, path) == expected | ||
|
||
|
@@ -275,7 +273,7 @@ def test_map_outputs_from_state_bad_spec(workspace_name): | |
] | ||
|
||
|
||
@pytest.mark.parametrize("field_type,spec_add,expect_add", app_param_cases) | ||
@pytest.mark.parametrize(("field_type", "spec_add", "expect_add"), app_param_cases) | ||
def test_app_param(field_type, spec_add, expect_add): | ||
spec_param = copy.deepcopy(base_app_param) | ||
expected = copy.deepcopy(base_expect) | ||
|
@@ -307,7 +305,8 @@ def test_app_param(field_type, spec_add, expect_add): | |
|
||
|
||
@pytest.mark.parametrize( | ||
"transform_type,value,spec_param,expected", transform_param_value_simple_cases | ||
("transform_type", "value", "spec_param", "expected"), | ||
transform_param_value_simple_cases, | ||
) | ||
def test_transform_param_value_simple(transform_type, value, spec_param, expected): | ||
assert transform_param_value(transform_type, value, spec_param) == expected | ||
|
@@ -328,7 +327,7 @@ def test_transform_param_value_fail(): | |
] | ||
|
||
|
||
@pytest.mark.parametrize("value,expected", textsubdata_cases) | ||
@pytest.mark.parametrize(("value", "expected"), textsubdata_cases) | ||
def test_transform_param_value_textsubdata(value, expected): | ||
spec = {"type": "textsubdata"} | ||
assert transform_param_value(None, value, spec) == expected | ||
|
@@ -506,9 +505,6 @@ def get_workspace(_): | |
|
||
|
||
class RefChainWorkspace: | ||
def __init__(self): | ||
pass | ||
|
||
def get_object_info3(self, params): | ||
""" | ||
Makes quite a few assumptions about input, as it's used for a specific test. | ||
|
@@ -568,7 +564,7 @@ def get_ref_path_mock_ws(name="workspace"): | |
) | ||
@mock.patch("biokbase.narrative.app_util.clients.get", get_ref_path_mock_ws) | ||
def test_transform_param_value_upa_path(tf_type): | ||
upa_path = f"69375/2/2;67729/2/2" | ||
upa_path = "69375/2/2;67729/2/2" | ||
assert transform_param_value(tf_type, upa_path, None) == upa_path | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in typing and method descriptions to help me whilst I was converting the tests.