Skip to content

Commit

Permalink
♻️ Refactor of names, and
Browse files Browse the repository at this point in the history
  • Loading branch information
AlTosterino committed Mar 29, 2024
1 parent 9ced498 commit 7e421d0
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 201 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ LINT_PATHS = \
$(SRC_PATH) \
$(TESTS_PATH)

sync-deps:
poetry install

update-deps:
poetry update

lint:
poetry run black $(LINT_PATHS)
poetry run ruff check $(LINT_PATHS) --fix
Expand All @@ -16,4 +22,4 @@ lint-ci:
poetry run mypy $(LINT_PATHS)

test:
poetry run pytest
poetry run pytest -p no:warnings
327 changes: 168 additions & 159 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/adrpy/entrypoints/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import typer
from adrpy.injection import lidi
from adrpy.shared_kernel.dtos import CreateADRDTO, InitializeADRDTO
from adrpy.shared_kernel.dtos import CreateAdrDto, InitializeAdrDto
from adrpy.shared_kernel.settings import Settings
from adrpy.use_cases.creating import CreatingADR
from adrpy.use_cases.initializing import InitializingADR
from adrpy.use_cases.create import CreateAdr
from adrpy.use_cases.initialize import InitializeAdr

app = typer.Typer()

Expand All @@ -27,8 +27,8 @@ def init(
if path:
new_settings = Settings(initial_adr_dir=path)
lidi.bind(Settings, new_settings, singleton=True)
dto = InitializeADRDTO(path=path)
InitializingADR().execute(dto=dto)
dto = InitializeAdrDto(path=path)
InitializeAdr().execute(dto=dto)


@app.command()
Expand All @@ -40,8 +40,8 @@ def new(
"""
Create new ADR with given NAME
"""
dto = CreateADRDTO(name=name)
CreatingADR().execute(dto=dto)
dto = CreateAdrDto(name=name)
CreateAdr().execute(dto=dto)


def cli_entrypoint() -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/adrpy/repositories/adr/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_next_ordinal_number(self) -> int:
ordinal_number = 0
for path in self.settings.adr_dir.glob("*.md"):
filename = path.stem
maybe_number_prefix = re.findall("\d+", filename)
maybe_number_prefix = re.findall(r"\d+", filename)
if not maybe_number_prefix:
continue
if (prefix_as_int := int(maybe_number_prefix[0])) > ordinal_number:
Expand Down
4 changes: 2 additions & 2 deletions src/adrpy/shared_kernel/dtos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


@dataclass(frozen=True)
class InitializeADRDTO:
class InitializeAdrDto:
path: Path | None
adr_template_name: str = field(default=AppTemplates.INITIAL_ADR, init=False)


@dataclass(frozen=True)
class CreateADRDTO:
class CreateAdrDto:
name: str
adr_template_name: str = field(default=AppTemplates.NEW_ADR, init=False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from adrpy.injection import lidi
from adrpy.repositories.adr.base import BaseADRRepository
from adrpy.services.template.base import BaseTemplateService
from adrpy.shared_kernel.dtos import CreateADRDTO
from adrpy.shared_kernel.dtos import CreateAdrDto


@dataclass
class CreatingADR:
class CreateAdr:
template_service = lidi.resolve(BaseTemplateService)
adr_repository = lidi.resolve(BaseADRRepository)

def execute(self, dto: CreateADRDTO) -> None:
def execute(self, dto: CreateAdrDto) -> None:
template = self.adr_repository.get_template(name=dto.adr_template_name)
rendered_template = self.template_service.render(
template_file=template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
from adrpy.injection import lidi
from adrpy.repositories.adr.base import BaseADRRepository
from adrpy.services.template.base import BaseTemplateService
from adrpy.shared_kernel.dtos import InitializeADRDTO
from adrpy.shared_kernel.dtos import InitializeAdrDto
from adrpy.shared_kernel.settings import Settings


@dataclass
class InitializingADR:
class InitializeAdr:
template_service = lidi.resolve(BaseTemplateService)
file_service = lidi.resolve(BaseADRRepository)
settings = lidi.resolve(Settings)
INITIAL_ADR_NAME: str = field(init=False, default="0001-record-architecture-decisions")

def execute(self, dto: InitializeADRDTO) -> None:
def execute(self, dto: InitializeAdrDto) -> None:
app_template = self.file_service.get_template(name=dto.adr_template_name)
rendered_template = self.template_service.render(
template_file=app_template, data={"date_created": datetime.now(), "status": "ACCEPTED"}
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import shutil
from typing import Iterator

import pytest
from adrpy.injection import setup_injection
from lidipy import Lidi

from tests.fixtures.repository import TEST_DIRECTORY

pytest_plugins = ["tests.fixtures"]


@pytest.fixture
def lidi() -> Lidi:
from adrpy.injection import lidi

setup_injection()
yield lidi


@pytest.fixture(autouse=True)
def remove_test_file() -> Iterator[None]:
yield
shutil.rmtree(TEST_DIRECTORY, ignore_errors=True)
File renamed without changes.
23 changes: 23 additions & 0 deletions tests/fixtures/repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pathlib import Path
from typing import Iterator

import pytest
from adrpy.repositories.adr.base import BaseADRRepository
from adrpy.repositories.adr.repository import ADRFileRepository
from adrpy.shared_kernel.settings import Settings
from lidipy import Lidi

TEST_DIRECTORY = Path(__file__).parent / "testdir"
TEST_FILENAME = "testfile"
TEST_FILENAME_WITH_EXTENSION = "testfile.md"


@pytest.fixture()
def repo_service(lidi: Lidi) -> Iterator[BaseADRRepository]:
original_repo = lidi.resolve(BaseADRRepository)
original_settings = lidi.resolve(Settings)
new_settings = Settings(initial_adr_dir=TEST_DIRECTORY)
lidi.bind(BaseADRRepository, ADRFileRepository(settings=new_settings))
yield lidi.resolve(BaseADRRepository)
lidi.bind(BaseADRRepository, original_repo)
lidi.bind(Settings, original_settings)
Empty file.
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
from pathlib import Path
from typing import Iterator

import pytest
from adrpy.repositories.adr.repository import ADRFileRepository, BaseADRRepository
from adrpy.shared_kernel.constants import AppTemplates
from adrpy.shared_kernel.settings import Settings
from adrpy.shared_kernel.value_objects.template import RenderedTemplate
from lidipy import Lidi

TEST_DIRECTORY = Path(__file__).parent / "testdir"
TEST_FILENAME = "testfile"
TEST_FILENAME_WITH_EXTENSION = "testfile.md"


@pytest.fixture()
def repo_service(lidi: Lidi) -> Iterator[BaseADRRepository]:
original_repo = lidi.resolve(BaseADRRepository)
original_settings = lidi.resolve(Settings)
new_settings = Settings(initial_adr_dir=TEST_DIRECTORY)
lidi.bind(BaseADRRepository, ADRFileRepository(settings=new_settings))
yield lidi.resolve(BaseADRRepository)
lidi.bind(BaseADRRepository, original_repo)
lidi.bind(Settings, original_settings)


@pytest.fixture(scope="module", autouse=True)
def remove_test_file() -> Iterator[None]:
yield
import shutil

shutil.rmtree(TEST_DIRECTORY, ignore_errors=True)
from tests.fixtures.repository import TEST_DIRECTORY, TEST_FILENAME, TEST_FILENAME_WITH_EXTENSION


def test_should_create_file(repo_service: BaseADRRepository) -> None:
Expand Down

0 comments on commit 7e421d0

Please sign in to comment.