-
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.
Merge pull request #8 from AlTosterino/bug/7-init-process-does-not-work
Fix initializing ADR
- Loading branch information
Showing
12 changed files
with
345 additions
and
274 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,11 +1,11 @@ | ||
from adrpy.repositories.adr.base import BaseADRRepository | ||
from adrpy.repositories.adr.repository import ADRFileRepository | ||
from adrpy.services.template.base import BaseTemplateService | ||
from adrpy.services.template.service import MakoTemplateService | ||
from adrpy.shared_kernel.settings import Settings | ||
from lidipy import Lidi | ||
|
||
|
||
def bind_modules(lidi: Lidi) -> None: | ||
lidi.bind(BaseADRRepository, ADRFileRepository(settings=lidi.resolve(Settings))) | ||
from adrpy.repositories.adr.base import BaseADRRepository | ||
from adrpy.repositories.adr.repository import ADRFileRepository | ||
from adrpy.services.template.base import BaseTemplateService | ||
from adrpy.services.template.service import MakoTemplateService | ||
|
||
lidi.bind(BaseADRRepository, ADRFileRepository()) | ||
lidi.bind(BaseTemplateService, MakoTemplateService()) |
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,6 +1,7 @@ | ||
from adrpy.shared_kernel.settings import Settings | ||
from lidipy import Lidi | ||
|
||
|
||
def bind_settings(lidi: Lidi) -> None: | ||
from adrpy.shared_kernel.settings import Settings | ||
|
||
lidi.bind(Settings, Settings(), singleton=True) |
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
Empty file.
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,74 @@ | ||
from pathlib import Path | ||
from typing import Generator | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from adrpy.shared_kernel.settings import Settings | ||
|
||
DIR_PATH = Path(__file__).parent | ||
PYPROJECT_PATH = DIR_PATH / Path("pyproject.toml") | ||
PYPROJECT_DATA = """ | ||
[tool.adrpy] | ||
dir = "docs/adr" | ||
""" | ||
PYPROJECT_WRONG_DATA = """ | ||
[tool.adrpython] | ||
dir = "docs/adr" | ||
""" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def correct_pyproject_toml() -> Generator[None, None, None]: | ||
with open(PYPROJECT_PATH, "w") as pyproject: | ||
pyproject.write(PYPROJECT_DATA) | ||
yield | ||
Path(PYPROJECT_PATH).unlink(missing_ok=True) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def wrong_pyproject_toml() -> Generator[None, None, None]: | ||
with open(PYPROJECT_PATH, "w") as pyproject: | ||
pyproject.write(PYPROJECT_WRONG_DATA) | ||
yield | ||
Path(PYPROJECT_PATH).unlink(missing_ok=True) | ||
|
||
|
||
def test_should_get_adr_dir_from_settings_when_no_initial_dir_set() -> None: | ||
# Given | ||
settings = Settings() | ||
|
||
# When & Then | ||
assert Path.cwd() == settings.adr_dir | ||
|
||
|
||
def test_should_get_adr_dir_from_settings_when_initial_dir_set() -> None: | ||
# Given | ||
settings = Settings(initial_adr_dir=Path(__file__).parent) | ||
|
||
# When & Then | ||
assert settings.adr_dir == Path(__file__).parent | ||
|
||
|
||
def test_should_get_adr_dir_from_pyproject_toml(correct_pyproject_toml: None) -> None: | ||
# Given | ||
with patch.object(Path, "cwd") as path_cwd_mock: | ||
path_cwd_mock.return_value = DIR_PATH | ||
settings = Settings() | ||
adr_dir = settings.adr_dir | ||
|
||
# When & Then | ||
assert adr_dir == DIR_PATH / Path("docs/adr") | ||
|
||
|
||
def test_should_fallback_wrong_adr_dir_from_pyproject_toml_to_working_directory( | ||
wrong_pyproject_toml: None, | ||
) -> None: | ||
# TODO: Maybe this shouldn't fallback, but raise instead? | ||
# Given | ||
with patch.object(Path, "cwd") as path_cwd_mock: | ||
path_cwd_mock.return_value = DIR_PATH | ||
settings = Settings() | ||
adr_dir = settings.adr_dir | ||
|
||
# When & Then | ||
assert adr_dir == DIR_PATH |