generated from br3ndonland/template-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f1ccf2
commit 344f3e4
Showing
7 changed files
with
87 additions
and
19 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,14 @@ | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
import toml | ||
|
||
|
||
def load_pyproject(pyproject_path: Path = Path("pyproject.toml")) -> Dict[str, Any]: | ||
"""Load pyproject.toml into a dictionary, with a default dict as a fallback.""" | ||
try: | ||
return dict(toml.load(pyproject_path)) | ||
except Exception: | ||
return { | ||
"tool": {"poetry": {"name": "algorythms", "description": "", "version": ""}} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[mypy] | ||
disallow_untyped_defs = True | ||
files = **/*.py | ||
plugins = pydantic.mypy |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
from pathlib import Path | ||
|
||
from algorythms import settings | ||
from algorythms.examples.parse_pyproject_toml import load_pyproject | ||
|
||
|
||
def test_load_pyproject() -> None: | ||
"""Assert that pyproject.toml is successfully loaded and parsed.""" | ||
pyproject = load_pyproject(pyproject_path=Path("pyproject.toml")) | ||
assert pyproject == settings.pyproject | ||
assert str(pyproject["tool"]["poetry"]["name"]) == settings.title | ||
assert str(pyproject["tool"]["poetry"]["description"]) == settings.description | ||
assert str(pyproject["tool"]["poetry"]["version"]) == settings.version | ||
|
||
|
||
def test_load_pyproject_error() -> None: | ||
"""Assert that default dict is loaded when pyproject.toml is not found.""" | ||
pyproject = load_pyproject(pyproject_path=Path("pyproject.toml")) | ||
pyproject_default = load_pyproject(pyproject_path=Path("error")) | ||
assert pyproject != pyproject_default | ||
assert pyproject_default == { | ||
"tool": {"poetry": {"name": "algorythms", "description": "", "version": ""}} | ||
} |
This file was deleted.
Oops, something went wrong.