mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
Merge branch 'master' into split_archive
This commit is contained in:
@@ -8,18 +8,18 @@ import os
|
||||
import pytest
|
||||
from jinja2 import Environment, Template
|
||||
|
||||
from blag import blag
|
||||
from blag import blag, quickstart
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def environment() -> Iterator[Environment]:
|
||||
def environment(cleandir: str) -> Iterator[Environment]:
|
||||
site = {
|
||||
'base_url': 'site base_url',
|
||||
'title': 'site title',
|
||||
'description': 'site description',
|
||||
'author': 'site author',
|
||||
}
|
||||
env = blag.environment_factory(globals_=dict(site=site))
|
||||
env = blag.environment_factory('templates', globals_=dict(site=site))
|
||||
yield env
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ def tag_template(environment: Environment) -> Iterator[Template]:
|
||||
|
||||
@pytest.fixture
|
||||
def cleandir() -> Iterator[str]:
|
||||
"""Create a temporary workind directory and cwd."""
|
||||
"""Create a temporary working directory and cwd."""
|
||||
config = """
|
||||
[main]
|
||||
base_url = https://example.com/
|
||||
@@ -65,13 +65,14 @@ author = a. u. thor
|
||||
"""
|
||||
|
||||
with TemporaryDirectory() as dir:
|
||||
for d in 'content', 'build', 'static', 'templates':
|
||||
for d in 'content', 'build', 'static':
|
||||
os.mkdir(f'{dir}/{d}')
|
||||
with open(f'{dir}/config.ini', 'w') as fh:
|
||||
fh.write(config)
|
||||
# change directory
|
||||
old_cwd = os.getcwd()
|
||||
os.chdir(dir)
|
||||
quickstart.copy_templates()
|
||||
yield dir
|
||||
# and change back afterwards
|
||||
os.chdir(old_cwd)
|
||||
|
||||
@@ -179,9 +179,9 @@ author = a. u. thor
|
||||
assert config_parsed['base_url'] == 'https://example.com/'
|
||||
|
||||
|
||||
def test_environment_factory() -> None:
|
||||
def test_environment_factory(cleandir: str) -> None:
|
||||
globals_: dict[str, object] = {'foo': 'bar', 'test': 'me'}
|
||||
env = blag.environment_factory(globals_=globals_)
|
||||
env = blag.environment_factory("templates", globals_=globals_)
|
||||
assert env.globals['foo'] == 'bar'
|
||||
assert env.globals['test'] == 'me'
|
||||
|
||||
@@ -301,6 +301,23 @@ foo bar
|
||||
assert os.path.exists(f'{args.output_dir}/tags/bar.html')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'template',
|
||||
[
|
||||
'page.html',
|
||||
'article.html',
|
||||
'index.html',
|
||||
'archive.html',
|
||||
'tags.html',
|
||||
'tag.html',
|
||||
]
|
||||
)
|
||||
def test_missing_template_raises(template: str, args: Namespace) -> None:
|
||||
os.remove(f'templates/{template}')
|
||||
with pytest.raises(SystemExit):
|
||||
blag.build(args)
|
||||
|
||||
|
||||
def test_main(cleandir: str) -> None:
|
||||
blag.main(['build'])
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# remove when we don't support py38 anymore
|
||||
from __future__ import annotations
|
||||
import os
|
||||
|
||||
from pytest import MonkeyPatch
|
||||
|
||||
@@ -27,3 +28,13 @@ def test_quickstart(cleandir: str, monkeypatch: MonkeyPatch) -> None:
|
||||
assert 'title = foo' in data
|
||||
assert 'description = foo' in data
|
||||
assert 'author = foo' in data
|
||||
|
||||
for template in (
|
||||
"archive.html",
|
||||
"article.html",
|
||||
"base.html",
|
||||
"page.html",
|
||||
"tag.html",
|
||||
"tags.html",
|
||||
):
|
||||
assert os.path.exists(f'templates/{template}')
|
||||
|
||||
Reference in New Issue
Block a user