Skip to content

Commit

Permalink
Format with black
Browse files Browse the repository at this point in the history
  • Loading branch information
eyvorchuk committed May 24, 2024
1 parent 79452d7 commit 4c557ca
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 46 deletions.
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def __init__(self):
}
inputs = [
LiteralInput(
"string", "String", abstract="Enter string.", data_type="string",
"string",
"String",
abstract="Enter string.",
data_type="string",
)
]
outputs = [
Expand Down
19 changes: 14 additions & 5 deletions tests/test_R.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@


@pytest.mark.parametrize(
("package"), [("base"), ("utils")],
("package"),
[("base"), ("utils")],
)
def test_get_package(package):
pkg = get_package(package)
Expand All @@ -41,7 +42,9 @@ def test_load_rdata_to_python(r_file, r_object_name):

@pytest.mark.parametrize(
("file_", "obj_name"),
[(resource_filename("tests", "data/expected_days_data.rda"), "autumn_days"),],
[
(resource_filename("tests", "data/expected_days_data.rda"), "autumn_days"),
],
)
def test_load_rdata_to_python_err(file_, obj_name):
with pytest.raises(ProcessError) as e:
Expand All @@ -53,7 +56,11 @@ def test_load_rdata_to_python_err(file_, obj_name):


@pytest.mark.parametrize(
("r_name", "py_var"), [("str_ex", "string"), ("int_ex", 300),],
("r_name", "py_var"),
[
("str_ex", "string"),
("int_ex", 300),
],
)
def test_save_python_to_rdata(r_name, py_var):
with NamedTemporaryFile(
Expand All @@ -68,14 +75,16 @@ def test_save_python_to_rdata(r_name, py_var):


@pytest.mark.parametrize(
("name"), [("hello.world"), ("r_name")],
("name"),
[("hello.world"), ("r_name")],
)
def test_r_valid_name(name):
r_valid_name(name)


@pytest.mark.parametrize(
("name"), [(".2"), ("if"), ("two words")],
("name"),
[(".2"), ("if"), ("two words")],
)
def test_r_valid_name_err(name):
with pytest.raises(ProcessError) as e:
Expand Down
19 changes: 15 additions & 4 deletions tests/test_file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@

@pytest.mark.online
@pytest.mark.parametrize(
("url"), [url_path(nc_file, "opendap"), local_path(nc_file),],
("url"),
[
url_path(nc_file, "opendap"),
local_path(nc_file),
],
)
def test_is_opendap_url(url):
if "docker" in url:
Expand All @@ -38,7 +42,8 @@ def test_is_opendap_url(url):


@pytest.mark.parametrize(
("nc_input"), [[NCInput(file=local_path(nc_file))]],
("nc_input"),
[[NCInput(file=local_path(nc_file))]],
)
def test_get_filepaths_local(nc_input):
paths = get_filepaths(nc_input)
Expand All @@ -52,7 +57,10 @@ def test_get_filepaths_local(nc_input):
("nc_input"),
[
[NCInput(url=url_path(nc_file, "opendap"))],
[NCInput(file=local_path(nc_file)), NCInput(url=url_path(nc_file, "opendap")),],
[
NCInput(file=local_path(nc_file)),
NCInput(url=url_path(nc_file, "opendap")),
],
],
)
def test_get_filepaths_online(nc_input):
Expand Down Expand Up @@ -119,7 +127,10 @@ def test_copy_http_content(http, expected):
@pytest.mark.online
@pytest.mark.parametrize(
("url_type", "url"),
[("http", url_path(nc_file, "http")), ("opendap", url_path(nc_file, "opendap")),],
[
("http", url_path(nc_file, "http")),
("opendap", url_path(nc_file, "opendap")),
],
)
def test_url_handler(url_type, url):
processed = url_handler("/tmp", url)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def run_args_collection(wps_test_process_multi_input, file, csv, argc):
("file", "argc"),
[
(
[local_path("tiny_daily_pr.nc"), local_path("tiny_daily_prsn.nc"),],
[
local_path("tiny_daily_pr.nc"),
local_path("tiny_daily_prsn.nc"),
],
{"file": 2, "csv_input": 1, "argc": 1},
)
],
Expand Down
14 changes: 11 additions & 3 deletions tests/test_output_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def test_nc_to_dataset(url):


@pytest.mark.parametrize(
("url"), [local_path("gsl.json")],
("url"),
[local_path("gsl.json")],
)
def test_json_to_dict(url):
output_dict = json_to_dict(url)
Expand Down Expand Up @@ -85,7 +86,13 @@ def test_auto_construct_outputs_online(outputs, expected_types):


@pytest.mark.parametrize(
("outputs", "expected_types"), [(["test string"], [str, str],)],
("outputs", "expected_types"),
[
(
["test string"],
[str, str],
)
],
)
def test_auto_construct_outputs_local(txt_file, outputs, expected_types):
outputs.append(f"file://{txt_file.name}")
Expand All @@ -94,7 +101,8 @@ def test_auto_construct_outputs_local(txt_file, outputs, expected_types):


@pytest.mark.parametrize(
("output"), ["https://test_metalinks.meta4"],
("output"),
["https://test_metalinks.meta4"],
)
def test_get_metalink_content(mock_metalink, output):
for file_ in get_metalink_content(output):
Expand Down
24 changes: 21 additions & 3 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,41 @@ def test_run_wps_process(wps_test_process, string):


@pytest.mark.parametrize(
"bird", [("thunderbird"), ("sandpiper"), ("osprey"), ("chickadee"),]
"bird",
[
("thunderbird"),
("sandpiper"),
("osprey"),
("chickadee"),
],
)
@pytest.mark.parametrize("expected", ["http://localhost:5000/wps"])
def test_get_target_url_local(mock_local_url, bird, expected):
assert get_target_url(bird) == expected


@pytest.mark.parametrize(
"bird", [("thunderbird"), ("sandpiper"), ("osprey"), ("chickadee"),]
"bird",
[
("thunderbird"),
("sandpiper"),
("osprey"),
("chickadee"),
],
)
@pytest.mark.parametrize("expected", ["http://docker-dev03.pcic.uvic.ca/somebird"])
def test_get_target_url_dev(mock_dev_url, bird, expected):
assert get_target_url(bird) == expected


@pytest.mark.parametrize(
"bird", [("thunderbird"), ("sandpiper"), ("osprey"), ("chickadee"),]
"bird",
[
("thunderbird"),
("sandpiper"),
("osprey"),
("chickadee"),
],
)
def test_get_target_url(bird):
assert bird in get_target_url(bird)
36 changes: 18 additions & 18 deletions wps_tools/R.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

def get_package(package):
"""
Exposes all R objects in package as Python objects after
checking that it is installed.
Exposes all R objects in package as Python objects after
checking that it is installed.
Parameters:
package (str): the name of an R package
Parameters:
package (str): the name of an R package
Returns:
Exposed R package
Returns:
Exposed R package
"""
if isinstalled(package):
return importr(package)
Expand All @@ -27,15 +27,15 @@ def get_package(package):

def load_rdata_to_python(r_file, r_object_name):
"""
Loads R objects from a .rda or .Rdata file into the embedded R
environment, then exposes that object as a Python object.
Loads R objects from a .rda or .Rdata file into the embedded R
environment, then exposes that object as a Python object.
Parameters:
r_file (str): path to an .rda or .rdata file
r_object_name (str): name of an R object from the r_file
Parameters:
r_file (str): path to an .rda or .rdata file
r_object_name (str): name of an R object from the r_file
Returns:
Exposed R object as a python object
Returns:
Exposed R object as a python object
"""
try:
robjects.r(f"load(file='{r_file}')")
Expand All @@ -55,12 +55,12 @@ def load_rdata_to_python(r_file, r_object_name):

def save_python_to_rdata(r_name, py_var, r_file):
"""
Saves a Python object as an R object to a Rdata (.rda) file
Saves a Python object as an R object to a Rdata (.rda) file
Parameters:
r_name (str): name to give the oject in the R environment
py_var (any type): python variable to save to the R environment
r_file (str): path to rdata file
Parameters:
r_name (str): name to give the oject in the R environment
py_var (any type): python variable to save to the R environment
r_file (str): path to rdata file
"""
robjects.r.assign(r_name, py_var)
robjects.r(f"save({r_name}, file='{r_file}')")
Expand Down
22 changes: 11 additions & 11 deletions wps_tools/file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_filepaths(nc_input):
Each path in nc_input is checked to determine if it is an OpenDAP url. If so,
then the url is appended to the path list. If not, then whether or not it's a valid
netcdf file is checked. If so, then the path is appended to the list. If not, then
netcdf file is checked. If so, then the path is appended to the list. If not, then
a ProcessError is raised due to an invalid input.
Parameters:
Expand Down Expand Up @@ -162,16 +162,16 @@ def build_meta_link(

def copy_http_content(http, file):
"""
This function is implemented to copy the content of a file passed
as an http address to a local file.
Parameters:
http (str): http address containing the desired content
file (file object): path to the
file that the content will be copied to
Returns:
Path to the copied file in /tmp directory
"""
This function is implemented to copy the content of a file passed
as an http address to a local file.
Parameters:
http (str): http address containing the desired content
file (file object): path to the
file that the content will be copied to
Returns:
Path to the copied file in /tmp directory
"""
file.write(get(http).content)
return file.name

Expand Down

0 comments on commit 4c557ca

Please sign in to comment.