Add tests for output.Output and output.File
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import pytest
|
||||
from omicron.ssg.site import Site
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def thin_site(tmp_path):
|
||||
(tmp_path / "config.yml").write_text("name: test\ntemplate: plain\n")
|
||||
return Site(tmp_path)
|
||||
@@ -0,0 +1,29 @@
|
||||
from pathlib import Path
|
||||
from omicron.ssg.output.file import File
|
||||
|
||||
|
||||
def test_write_copies_content(thin_site, tmp_path):
|
||||
source = tmp_path / "source.txt"
|
||||
source.write_text("hello")
|
||||
dest_dir = thin_site.output_path / "assets"
|
||||
dest_dir.mkdir(parents=True)
|
||||
|
||||
file = File(thin_site, Path("assets/copy.txt"), source)
|
||||
file.write()
|
||||
|
||||
dest = dest_dir / "copy.txt"
|
||||
assert dest.read_text() == "hello"
|
||||
|
||||
|
||||
def test_write_overwrites_existing_destination(thin_site, tmp_path):
|
||||
dest = thin_site.output_path / "copy.txt"
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
dest.write_text("old")
|
||||
|
||||
source = tmp_path / "source.txt"
|
||||
source.write_text("new")
|
||||
|
||||
file = File(thin_site, Path("copy.txt"), source)
|
||||
file.write()
|
||||
|
||||
assert dest.read_text() == "new"
|
||||
@@ -0,0 +1,36 @@
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from omicron.ssg.output.file import File
|
||||
from omicron.ssg.output.output import OutputError
|
||||
from omicron.ssg.site import Site
|
||||
|
||||
|
||||
def test_absolute_destination_raises(thin_site, tmp_path):
|
||||
with pytest.raises(OutputError):
|
||||
File(thin_site, Path("/copy.txt"), tmp_path / "source.txt")
|
||||
|
||||
|
||||
def test_non_normalized_destination_raises(thin_site, tmp_path):
|
||||
with pytest.raises(OutputError):
|
||||
File(thin_site, Path("assets/../copy.txt"), tmp_path / "source.txt")
|
||||
|
||||
|
||||
def test_site_raises_after_garbage_collection(tmp_path):
|
||||
(tmp_path / "config.yml").write_text("name: test\ntemplate: plain\n")
|
||||
site = Site(tmp_path)
|
||||
file = File(site, Path("copy.txt"), tmp_path / "source.txt")
|
||||
|
||||
del site
|
||||
|
||||
with pytest.raises(ReferenceError):
|
||||
file.site
|
||||
|
||||
|
||||
def test_url(thin_site, tmp_path):
|
||||
file = File(thin_site, Path("assets/copy.txt"), tmp_path / "source.txt")
|
||||
assert file.url == "/assets/copy.txt"
|
||||
|
||||
|
||||
def test_url_strips_index_html(thin_site, tmp_path):
|
||||
file = File(thin_site, Path("posts/index.html"), tmp_path / "source.txt")
|
||||
assert file.url == "/posts"
|
||||
Reference in New Issue
Block a user