-
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.
fix: Fixed bugs for analyzing packages and api data creation. (#27)
### Summary of Changes * Fixed a bug in `_get_api.py` which prevented analyzing packages with different path lengths. * Fixed a bug in `_ast_visitor.py` for the api data creation, in which the id of modules did not correctly represent their path. * Adjusted test snapshots --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
0651f5b
commit 80215a3
Showing
5 changed files
with
138 additions
and
15 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
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
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,75 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
# noinspection PyProtectedMember | ||
from safeds_stubgen.api_analyzer._api import API | ||
|
||
# noinspection PyProtectedMember | ||
from safeds_stubgen.api_analyzer._ast_visitor import MyPyAstVisitor | ||
from safeds_stubgen.docstring_parsing import PlaintextDocstringParser | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("qname", "expected_id", "package_name"), | ||
[ | ||
( | ||
"some.path.package_name.src.data", | ||
"package_name/src/data", | ||
"package_name", | ||
), | ||
( | ||
"some.path.package_name", | ||
"package_name", | ||
"package_name", | ||
), | ||
( | ||
"some.path.no_package", | ||
"", | ||
"package_name", | ||
), | ||
( | ||
"", | ||
"", | ||
"package_name", | ||
), | ||
( | ||
"some.package_name.package_name.src.data", | ||
"package_name/package_name/src/data", | ||
"package_name", | ||
), | ||
( | ||
"some.path.package_name.src.package_name", | ||
"package_name/src/package_name", | ||
"package_name", | ||
), | ||
( | ||
"some.package_name.package_name.src.package_name", | ||
"package_name/package_name/src/package_name", | ||
"package_name", | ||
), | ||
], | ||
ids=[ | ||
"With unneeded data", | ||
"Without unneeded data", | ||
"No package name in qname", | ||
"No qname", | ||
"Package name twice in qname 1", | ||
"Package name twice in qname 2", | ||
"Package name twice in qname 3", | ||
], | ||
) | ||
def test__create_module_id(qname: str, expected_id: str, package_name: str) -> None: | ||
api = API( | ||
distribution="dist_name", | ||
package=package_name, | ||
version="1.3", | ||
) | ||
|
||
visitor = MyPyAstVisitor(PlaintextDocstringParser(), api) | ||
if not expected_id: | ||
with pytest.raises(ValueError, match="Package name could not be found in the qualified name of the module."): | ||
visitor._create_module_id(qname) | ||
else: | ||
module_id = visitor._create_module_id(qname) | ||
assert module_id == expected_id |