test: migrate from pytest in favor of ward
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1296103c8f
commit
c7127e4a5d
3 changed files with 191 additions and 152 deletions
|
|
@ -3,14 +3,15 @@ import tempfile
|
|||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from halig.config import get_config, Config, EncryptionKeysConfig
|
||||
from halig.exceptions import ConfigFileDoesNotExist, ConfigFileIsInvalid
|
||||
|
||||
from ward import fixture, test, raises
|
||||
|
||||
@pytest.fixture()
|
||||
|
||||
@fixture()
|
||||
def tmpfile():
|
||||
_tmpfile = NamedTemporaryFile(delete=False)
|
||||
with open(_tmpfile.name, "w") as file:
|
||||
|
|
@ -18,37 +19,42 @@ def tmpfile():
|
|||
Path(_tmpfile.name).unlink()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@fixture()
|
||||
def tmpdir():
|
||||
tmpdir = Path(tempfile.mkdtemp())
|
||||
yield tmpdir
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
|
||||
def test_get_config_raises_config_file_does_not_exist():
|
||||
with pytest.raises(ConfigFileDoesNotExist):
|
||||
@test("get config raises ConfigFileDoesNotExist")
|
||||
def _():
|
||||
with raises(ConfigFileDoesNotExist):
|
||||
get_config(Path("/foobar"))
|
||||
|
||||
|
||||
def test_get_config_with_empty_file_raises_invalid_config_file():
|
||||
with pytest.raises(ConfigFileIsInvalid):
|
||||
@test("get config raises ConfigFileIsInvalid")
|
||||
def _():
|
||||
with raises(ConfigFileIsInvalid):
|
||||
with NamedTemporaryFile() as f:
|
||||
get_config(Path(f.name))
|
||||
|
||||
|
||||
def test_get_config_raises_invalid_config_file_00(tmpfile):
|
||||
@test("get config raises ConfigFileIsInvalid from invalid file contents")
|
||||
def _(tmpfile=tmpfile):
|
||||
tmpfile.write("foobar")
|
||||
with pytest.raises(ConfigFileIsInvalid):
|
||||
with raises(ConfigFileIsInvalid):
|
||||
get_config(Path(tmpfile.name))
|
||||
|
||||
|
||||
def test_get_config_raises_invalid_config_file_01(tmpfile):
|
||||
@test("get config raises ConfigFileIsInvalid from pydantic validation")
|
||||
def _(tmpfile=tmpfile):
|
||||
yaml.dump({"foo": "bar"}, tmpfile, Dumper=yaml.SafeDumper)
|
||||
with pytest.raises(ConfigFileIsInvalid):
|
||||
with raises(ConfigFileIsInvalid):
|
||||
get_config(Path(tmpfile.name))
|
||||
|
||||
|
||||
def test_get_config(tmpdir):
|
||||
@test("get config returns a correct config instance")
|
||||
def _(tmpdir=tmpdir):
|
||||
notes_root_path = Path(tmpdir / "notes")
|
||||
notes_root_path.mkdir(exist_ok=True)
|
||||
age_binary_path = Path(tmpdir / "age")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue