Skip to content

Commit 62b5a3f

Browse files
authored
Merge pull request #49 from NREL/pp/duplicate_params
Fix handling of duplicate params
2 parents af6faee + 0856d67 commit 62b5a3f

File tree

5 files changed

+111
-4
lines changed

5 files changed

+111
-4
lines changed

gaps/cli/documentation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ def _parameter_npd(self):
507507
param_doc = NumpyDocString("")
508508
param_doc["Parameters"] = [
509509
p
510-
for doc in self.docs
511-
for p in doc["Parameters"]
510+
for p in self.param_docs.values()
512511
if p.name in self.template_config
513512
]
514513
return param_doc

gaps/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""GAPs Version Number. """
22

3-
__version__ = "0.6.12"
3+
__version__ = "0.6.13"

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
DEV_REQUIREMENTS = ["black", "pylint", "jupyter", "pipreqs"]
22-
TEST_REQUIREMENTS = ["pytest", "pytest-cov", "h5py"]
22+
TEST_REQUIREMENTS = ["pytest", "pytest-cov", "h5py", "flaky"]
2323
DOC_REQUIREMENTS = ["make", "ghp-import", "numpydoc", "pandoc"]
2424
DESCRIPTION = (
2525
"National Renewable Energy Laboratory's (NREL's) Geospatial Analysis "

tests/cli/test_cli.py

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def test_cli_monitor(
310310
"implement os.fork/setsid",
311311
)
312312
@pytest.mark.integration
313+
@pytest.mark.flaky(max_runs=5, min_passes=1)
313314
def test_cli_background(
314315
tmp_cwd,
315316
cli_runner,

tests/cli/test_cli_documentation.py

+107
Original file line numberDiff line numberDiff line change
@@ -624,5 +624,112 @@ def preprocessor(another_input, _a_private_input, another_input2=None):
624624
assert doc.template_config == expected_config
625625

626626

627+
def test_command_documentation_duplicate_params():
628+
"""Test `CommandDocumentation` for duplicated parameters."""
629+
630+
class TestCommand:
631+
"""A test command as a class."""
632+
633+
def __init__(
634+
self, _arg0, arg1, arg2=None, arg3="hello", max_workers=None
635+
):
636+
"""Initialize Model.
637+
638+
Extended from init.
639+
640+
Parameters
641+
----------
642+
_arg0 : int
643+
A private input.
644+
arg1 : int
645+
Arg1 for model.
646+
arg2 : float, optional
647+
Arg2 for model. By default, ``None``.
648+
arg3 : str, optional
649+
Arg3 for model. By default, ``"hello"``.
650+
max_workers : int, optional
651+
Max num workers. By default, ``None``.
652+
"""
653+
654+
def func(self, project_points, a, _private_arg1, b=1, arg3="test"):
655+
"""A test function.
656+
657+
Extended from func.
658+
659+
Parameters
660+
----------
661+
project_points : str
662+
Path to project points file.
663+
a : float
664+
An arg.
665+
b : int, optional
666+
Another arg. By default, ``1``.
667+
arg3 : str, optional
668+
Arg3 for func. By default, ``"test"``.
669+
"""
670+
671+
def preprocessor(another_input, _a_private_input, arg3="pre"):
672+
"""A sample pre-processor function
673+
674+
Extended from preprocessor.
675+
676+
Parameters
677+
----------
678+
another_input : int
679+
Another model input.
680+
arg3 : str, optional
681+
Arg3 for preprocessing. By default, ``"pre"``.
682+
"""
683+
684+
doc = CommandDocumentation(
685+
TestCommand,
686+
getattr(TestCommand, "func"),
687+
preprocessor,
688+
skip_params={"a"},
689+
is_split_spatially=True,
690+
)
691+
assert len(doc.signatures) == 3
692+
693+
docstring = doc.hpc_parameter_help
694+
assert ":max_workers:" in docstring
695+
assert "\narg1 :" in docstring
696+
assert "\narg2 :" in docstring
697+
assert "\narg3 :" in docstring
698+
assert "project_points :" in docstring
699+
assert "\nb :" in docstring
700+
assert "\nanother_input :" in docstring
701+
assert "log_directory :" in docstring
702+
assert "log_level :" in docstring
703+
704+
assert "\na :" not in docstring
705+
assert "\nself :" not in docstring
706+
assert "_private_arg1" not in docstring
707+
assert "_a_private_input" not in docstring
708+
709+
assert 'Arg3 for preprocessing. By default, ``"pre"``.' in docstring
710+
assert 'Arg3 for model. By default, ``"hello"``.' not in docstring
711+
assert 'Arg3 for func. By default, ``"test"``.' not in docstring
712+
713+
assert "Extended from init" in doc.extended_summary
714+
assert "Extended from func" not in doc.extended_summary
715+
assert "Extended from preprocessor" not in doc.extended_summary
716+
717+
exec_vals = deepcopy(DEFAULT_EXEC_VALUES)
718+
exec_vals["max_workers"] = None
719+
expected_config = {
720+
"execution_control": exec_vals,
721+
"log_directory": "./logs",
722+
"log_level": "INFO",
723+
"arg1": doc.REQUIRED_TAG,
724+
"arg2": None,
725+
"arg3": "pre",
726+
"project_points": doc.REQUIRED_TAG,
727+
"b": 1,
728+
"another_input": doc.REQUIRED_TAG,
729+
}
730+
assert doc.template_config == expected_config
731+
732+
733+
627734
if __name__ == "__main__":
628735
pytest.main(["-q", "--show-capture=all", Path(__file__), "-rapP"])

0 commit comments

Comments
 (0)