Skip to content

Commit

Permalink
fixes #1783 (#1810)
Browse files Browse the repository at this point in the history
* fixes #1783

* fixed #1783

* Fixed issue of adding the my updates to UNRELEASED section

* added yarn.lock to desired location

* added test for changes I made

* added test function

* updated test case

---------

Co-authored-by: Sankalp Sanand <[email protected]>
  • Loading branch information
AdityaRaj23 and kessler-frost authored Nov 2, 2023
1 parent 9540267 commit 7cfee65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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 @@ def get_named_params(func, args, kwargs):
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
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

0 comments on commit 7cfee65

Please sign in to comment.