Skip to content
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

fixes #1783 #1810

Merged
merged 13 commits into from
Nov 2, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed unassigned variable names
- Contributing guidelines steps for installing for the first time
- Updated gitignore to ignore yarn files and folders for latest version of yarn
- Fixed the bug that caused ValueError error when using KEYWORD_ONLY parameter in electron func
- changed code at line 218 in covalent/_shared_files/utils.py

### Operations

Expand Down
5 changes: 4 additions & 1 deletion covalent/_shared_files/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@
elif param.kind == param.VAR_POSITIONAL:
for i in range(ind, len(args)):
named_args[f"arg[{i}]"] = args[i]
elif param.kind in [param.KEYWORD_ONLY, param.VAR_KEYWORD]:
elif param.kind == param.VAR_KEYWORD:
for key, value in kwargs.items():
if key != param_name:
named_kwargs[key] = value
elif param.kind == param.KEYWORD_ONLY:
if param_name in kwargs:
named_kwargs[param_name] = kwargs[param_name]

if len(args) > len(named_args):
raise ValueError(
Expand Down Expand Up @@ -254,12 +257,12 @@
if src_uri.startswith(scheme_prefix):
src_path = src_uri[len(scheme_prefix) :]
else:
raise TypeError(f"{src_uri} is not a valid URI")

Check warning on line 260 in covalent/_shared_files/utils.py

View check run for this annotation

Codecov / codecov/patch

covalent/_shared_files/utils.py#L260

Added line #L260 was not covered by tests
# src_path = src_uri
if dest_uri.startswith(scheme_prefix):
dest_path = dest_uri[len(scheme_prefix) :]
else:
raise TypeError(f"{dest_uri} is not a valid URI")

Check warning on line 265 in covalent/_shared_files/utils.py

View check run for this annotation

Codecov / codecov/patch

covalent/_shared_files/utils.py#L265

Added line #L265 was not covered by tests

shutil.copyfile(src_path, dest_path)

Expand Down
14 changes: 13 additions & 1 deletion tests/covalent_tests/shared_files/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pytest

from covalent._shared_files.config import get_config
from covalent._shared_files.utils import filter_null_metadata, format_server_url
from covalent._shared_files.utils import filter_null_metadata, format_server_url, get_named_params


@pytest.mark.parametrize(
Expand All @@ -37,6 +37,18 @@ def test_filter_null_metadata(meta_dict, expected):
assert filtered == expected


def test_get_named_params():
"""Tests the changes I made in covalent/covalent/_shared_files/utils.py for fixing ValueError in when using KEYWORD_ONLU parameter in electron func"""

def test_func(a, *, b):
return a + b

named_args, named_kwargs = get_named_params(test_func, [1], {"b": 2})

assert named_args == {"a": 1}
assert named_kwargs == {"b": 2}


def test_format_server_url():
"""Test the convenience function to format server urls."""

Expand Down
Loading