Skip to content

Commit

Permalink
Upgrade to Betty 0.4.0a13 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra authored Oct 14, 2024
1 parent d373ced commit 30240c8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 35 deletions.
26 changes: 10 additions & 16 deletions betty_nginx/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Integrate Betty with `nginx <https://nginx.org/>`_."""

from typing import Self

from betty.assertion import (
OptionalField,
assert_record,
Expand All @@ -12,8 +10,7 @@
assert_str,
)
from betty.config import Configuration
from betty.serde.dump import Dump, minimize
from betty.typing import Void, Voidable
from betty.serde.dump import Dump
from typing_extensions import override


Expand Down Expand Up @@ -57,11 +54,6 @@ def www_directory_path(self) -> str | None:
def www_directory_path(self, www_directory_path: str | None) -> None:
self._www_directory_path = www_directory_path

@override
def update(self, other: Self) -> None:
self._https = other._https
self._www_directory_path = other._www_directory_path

@override
def load(self, dump: Dump) -> None:
assert_record(
Expand All @@ -70,19 +62,21 @@ def load(self, dump: Dump) -> None:
assert_or(assert_bool(), assert_none()) | assert_setattr(self, "https"),
),
OptionalField(
"www_directory_path",
assert_str() | assert_setattr(self, "www_directory_path"),
"www_directory",
assert_or(
assert_none(),
assert_str() | assert_setattr(self, "www_directory_path"),
),
),
)(dump)

@override
def dump(self) -> Voidable[Dump]:
dump = {
def dump(self) -> Dump:
return {
"https": self.https,
"www_directory_path": (
Void
"www_directory": (
None
if self.www_directory_path is None
else str(self.www_directory_path)
),
}
return minimize(dump, True)
2 changes: 1 addition & 1 deletion betty_nginx/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def start(self) -> None:
isolated_project.configuration.configuration_file_path = (
self._project.configuration.configuration_file_path
)
isolated_project.configuration.update(self._project.configuration)
isolated_project.configuration.load(self._project.configuration.dump())
isolated_project.configuration.debug = True

# Work around https://github.com/bartfeenstra/betty/issues/1056.
Expand Down
2 changes: 1 addition & 1 deletion betty_nginx/tests/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from betty_nginx import Nginx


class TestNginx(ExtensionTestBase):
class TestNginx(ExtensionTestBase[Nginx]):
@override
def get_sut_class(self) -> type[Nginx]:
return Nginx
Expand Down
27 changes: 12 additions & 15 deletions betty_nginx/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,26 @@ async def test_load_with_https(self, https: bool | None) -> None:
sut.load(dump)
assert sut.https == https

async def test_load_with_www_directory_path(self, tmp_path: Path) -> None:
www_directory_path = str(tmp_path)
@pytest.mark.parametrize(
"www_directory",
[
None,
"/var/www",
],
)
async def test_load_with_www_directory(self, www_directory: str | None) -> None:
dump: Dump = {
"www_directory_path": www_directory_path,
"www_directory": www_directory,
}
sut = NginxConfiguration()
sut.load(dump)
assert sut.www_directory_path == www_directory_path
assert sut.www_directory_path == www_directory

async def test_dump_with_minimal_configuration(self) -> None:
sut = NginxConfiguration()
expected = {
"https": None,
"www_directory": None,
}
assert sut.dump() == expected

Expand All @@ -60,16 +67,6 @@ async def test_dump_with_www_directory_path(self, tmp_path: Path) -> None:
sut.www_directory_path = www_directory_path
expected = {
"https": None,
"www_directory_path": www_directory_path,
"www_directory": www_directory_path,
}
assert sut.dump() == expected

async def test_update(self, tmp_path: Path) -> None:
www_directory_path = str(tmp_path)
sut = NginxConfiguration()
other = NginxConfiguration()
other.https = True
other.www_directory_path = www_directory_path
sut.update(other)
assert sut.https is True
assert sut.www_directory_path == www_directory_path
2 changes: 1 addition & 1 deletion betty_nginx/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def server(
async with App.new_temporary() as app, app, Project.new_temporary(
app
) as project:
project.configuration.update(configuration)
project.configuration.load(configuration.dump())
async with project:
await generate.generate(project)
async with await DockerizedNginxServer.new_for_project(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authors = [
]
requires-python = '~= 3.11'
dependencies = [
'betty ~= 0.4.0a12',
'betty == 0.4.0a13',
'docker ~= 7.1',
]
classifiers = [
Expand Down

0 comments on commit 30240c8

Please sign in to comment.