init
This commit is contained in:
parent
359c250101
commit
da6d24c74f
13 changed files with 973 additions and 555 deletions
BIN
tests/__pycache__/test_config.cpython-313-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/test_config.cpython-313-pytest-9.0.2.pyc
Normal file
Binary file not shown.
88
tests/test_config.py
Normal file
88
tests/test_config.py
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import datetime as dt
|
||||
from pathlib import Path
|
||||
|
||||
import tomlkit
|
||||
|
||||
from forge import cli
|
||||
|
||||
|
||||
def test_parse_config_arrays(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "forge.toml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
copr = ["copr.fedorainfracloud.org/user/repo"]
|
||||
packages = ["git", "vim"]
|
||||
|
||||
[forge]
|
||||
version = "1.0"
|
||||
last_switch = ""
|
||||
|
||||
[dotfiles]
|
||||
".bashrc" = ".bashrc"
|
||||
|
||||
[options]
|
||||
backup = true
|
||||
backup_dir = "backup"
|
||||
""".strip()
|
||||
)
|
||||
|
||||
config = cli.parse_config(config_path)
|
||||
|
||||
assert config.copr == ["copr.fedorainfracloud.org/user/repo"]
|
||||
assert config.packages == ["git", "vim"]
|
||||
assert config.dotfiles == {".bashrc": ".bashrc"}
|
||||
assert config.options["backup"] is True
|
||||
assert config.legacy is False
|
||||
|
||||
|
||||
def test_parse_config_legacy_format(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "forge.toml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
[packages]
|
||||
git
|
||||
vim
|
||||
|
||||
[copr]
|
||||
copr.fedorainfracloud.org/user/repo
|
||||
|
||||
[dotfiles]
|
||||
".bashrc" = ".bashrc"
|
||||
""".strip()
|
||||
)
|
||||
|
||||
config = cli.parse_config(config_path)
|
||||
|
||||
assert config.packages == ["git", "vim"]
|
||||
assert config.copr == ["copr.fedorainfracloud.org/user/repo"]
|
||||
assert config.dotfiles == {".bashrc": ".bashrc"}
|
||||
assert config.legacy is True
|
||||
|
||||
|
||||
def test_diff_items() -> None:
|
||||
added, removed = cli.diff_items(["a", "b"], ["b", "c"])
|
||||
assert added == ["a"]
|
||||
assert removed == ["c"]
|
||||
|
||||
|
||||
def test_update_last_switch_creates_backup(tmp_path: Path) -> None:
|
||||
config_dir = tmp_path
|
||||
config_path = config_dir / "forge.toml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
[forge]
|
||||
version = "1.0"
|
||||
last_switch = ""
|
||||
""".strip()
|
||||
)
|
||||
|
||||
options = {"backup": True, "backup_dir": "backup"}
|
||||
cli.update_last_switch(config_path, options)
|
||||
|
||||
doc = tomlkit.parse(config_path.read_text())
|
||||
assert isinstance(doc["forge"]["last_switch"], dt.datetime)
|
||||
|
||||
backup_dir = config_dir / "backup"
|
||||
backups = list(backup_dir.iterdir())
|
||||
assert backups, "expected a backup of forge.toml to be created"
|
||||
assert any(path.name.startswith("forge.toml.") for path in backups)
|
||||
Loading…
Add table
Add a link
Reference in a new issue