ci: add pre-commit and tests workflows
This commit is contained in:
parent
ee43046e59
commit
bdb5c984fa
13 changed files with 339 additions and 297 deletions
|
|
@ -1,6 +1,5 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pendulum
|
||||
import pytest as pytest
|
||||
|
||||
from halig import utils
|
||||
|
|
@ -24,10 +23,10 @@ def notes(notebooks_path: Path):
|
|||
dailies = work / "Dailies"
|
||||
dailies.mkdir()
|
||||
|
||||
dt = pendulum.now()
|
||||
dt = utils.now()
|
||||
for day_offset in range(10):
|
||||
dt = dt.subtract(days=day_offset)
|
||||
(dailies / f"{dt.date()}.age").touch()
|
||||
dt = dt.subtract(hours=day_offset*24)
|
||||
(dailies / f"{dt.py_datetime().date()}.age").touch()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
|
@ -56,7 +55,7 @@ def notebooks_command(settings: Settings):
|
|||
|
||||
@pytest.fixture()
|
||||
def current_note(notes, settings, encryptor) -> Path:
|
||||
note_path = settings.notebooks_root_path / f"{utils.now().date()}.age"
|
||||
note_path = settings.notebooks_root_path / f"{utils.now_as_date()}.age"
|
||||
note_path.touch()
|
||||
data = encryptor.encrypt(b"foo")
|
||||
with note_path.open("wb") as f:
|
||||
|
|
@ -67,7 +66,7 @@ def current_note(notes, settings, encryptor) -> Path:
|
|||
@pytest.fixture()
|
||||
def current_daily(notes, settings, encryptor) -> Path:
|
||||
note_path = (
|
||||
settings.notebooks_root_path / "Work" / "Dailies" / f"{utils.now().date()}.age"
|
||||
settings.notebooks_root_path / "Work" / "Dailies" / f"{utils.now_as_date()}.age"
|
||||
)
|
||||
data = encryptor.encrypt(b"foo")
|
||||
with note_path.open("wb") as f:
|
||||
|
|
|
|||
|
|
@ -71,19 +71,14 @@ def notebooks_path(tmp_path) -> Path:
|
|||
|
||||
@pytest.fixture()
|
||||
def settings(notebooks_path: Path, halig_ssh_path) -> Settings:
|
||||
return Settings(
|
||||
notebooks_root_path=notebooks_path,
|
||||
identity_paths=[halig_ssh_path / "id_ed25519"],
|
||||
recipient_paths=[halig_ssh_path / "id_ed25519.pub"]
|
||||
)
|
||||
return Settings(notebooks_root_path=notebooks_path,identity_paths=[halig_ssh_path / "id_ed25519"],recipient_paths=[halig_ssh_path / "id_ed25519.pub"])
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def settings_file_path(halig_config_path: Path, notebooks_path: Path) -> Path:
|
||||
def settings_file_path(settings, halig_config_path: Path, notebooks_path: Path) -> Path:
|
||||
yaml_file = halig_config_path / "halig.yml"
|
||||
yaml_file.touch()
|
||||
s = Settings(notebooks_root_path=notebooks_path)
|
||||
# `.dict()` doesn't serialize some fields that yaml doesn't understand
|
||||
s = Settings(notebooks_root_path=notebooks_path, identity_paths=settings.identity_paths, recipient_paths=settings.recipient_paths)
|
||||
serialized = json.loads(s.model_dump_json())
|
||||
with yaml_file.open("w") as f:
|
||||
yaml.safe_dump(serialized, f)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from halig.settings import Settings, load_from_file
|
|||
|
||||
|
||||
def test_settings_from_env(settings: Settings, notebooks_root_path_envvar):
|
||||
from_env_settings = Settings() # type: ignore[call-arg]
|
||||
from_env_settings = Settings(recipient_paths=settings.recipient_paths, identity_paths=settings.identity_paths) # type: ignore[call-arg]
|
||||
assert from_env_settings.notebooks_root_path == settings.notebooks_root_path
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue