This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extract enums from docstring's type attribute (#30)
* Extract enums from docstring's type attribute. Write tests for enum extraction * Fix mypy errors and change return type of Parameter.extract_enum method * style: apply automatic fixes of linters * Provide JSON serialization for enum sets * Cover enum type cases suggested by Lars * Create new class for parameter enums, add more tests for extracting parameter enums from docstring type * remove backslashes from enum type values * style: apply automatic fixes of linters Co-authored-by: Dushko Klincharov <klincarov@halicea.com> Co-authored-by: duklin <duklin@users.noreply.github.com> Co-authored-by: Lars Reimann <mail@larsreimann.com>
- Loading branch information
1 parent
9fd3f1b
commit 16fa220
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
from package_parser.commands.get_api._model import ParameterEnum | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"docstring_type,expected", | ||
[ | ||
('{"frobenius", "spectral"}, default="frobenius"', {"frobenius", "spectral"}), | ||
( | ||
"{'strict', 'ignore', 'replace'}, default='strict'", | ||
{"strict", "ignore", "replace"}, | ||
), | ||
( | ||
"{'linear', 'poly', 'rbf', 'sigmoid', 'cosine', 'precomputed'}, default='linear'", | ||
{"linear", "poly", "rbf", "sigmoid", "cosine", "precomputed"}, | ||
), | ||
# https://github.com/lars-reimann/sem21/pull/30#discussion_r771288528 | ||
(r"{\"frobenius\", \'spectral\'}", set()), | ||
(r"""{"frobenius'}""", set()), | ||
(r"""{'spectral"}""", set()), | ||
(r"""{'text\", \"that'}""", {'text", "that'}), | ||
(r"""{'text", "that'}""", {'text", "that'}), | ||
(r"{'text\', \'that'}", {"text', 'that"}), | ||
(r"{'text', 'that'}", {"text", "that"}), | ||
(r"""{"text\', \'that"}""", {"text', 'that"}), | ||
(r"""{"text', 'that"}""", {"text', 'that"}), | ||
(r"""{"text\", \"that"}""", {'text", "that'}), | ||
(r'{"text", "that"}', {"text", "that"}), | ||
(r"""{\"not', 'be', 'matched'}""", {", ", ", "}), | ||
("""{"gini\\", \\"entropy"}""", {'gini", "entropy'}), | ||
("""{'best\\', \\'random'}""", {"best', 'random"}), | ||
], | ||
) | ||
def test_enum_from_docstring_type(docstring_type: str, expected: Optional[set[str]]): | ||
result = ParameterEnum._from_docstring_type(docstring_type) | ||
assert result == expected |