diff --git a/tests/conftest.py b/tests/conftest.py index 148e4fa..221f0af 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,5 @@ from tempfile import TemporaryDirectory -from os import mkdir +import os import pytest @@ -45,14 +45,32 @@ def tag_template(environment): @pytest.fixture def tempdir(): + config = """ +[main] +base_url = https://example.com/ +title = title +description = description +author = a. u. thor + """ + with TemporaryDirectory() as dir: for d in 'content', 'build', 'static', 'templates': - mkdir(f'{dir}/{d}') + os.mkdir(f'{dir}/{d}') + with open(f'{dir}/config.ini', 'w') as fh: + fh.write(config) yield dir @pytest.fixture -def args(tempdir): +def cleandir(tempdir): + old_cwd = os.getcwd() + os.chdir(tempdir) + yield + os.chdir(old_cwd) + + +@pytest.fixture +def args(cleandir): class NameSpace: def __init__(self, **kwargs): @@ -60,9 +78,9 @@ def args(tempdir): setattr(self, name, kwargs[name]) args = NameSpace( - input_dir=f'{tempdir}/content', - output_dir=f'{tempdir}/build', - static_dir=f'{tempdir}/static', - template_dir=f'{tempdir}/templates', + input_dir='content', + output_dir='build', + static_dir='static', + template_dir='templates', ) yield args diff --git a/tests/test_blag.py b/tests/test_blag.py index d3c7804..b50af7f 100644 --- a/tests/test_blag.py +++ b/tests/test_blag.py @@ -7,15 +7,13 @@ import pytest from blag import blag -def test_generate_feed(tempdir): - outdir = f'{tempdir}/build' +def test_generate_feed(args): articles = [] - blag.generate_feed(articles, outdir, ' ', ' ', ' ', ' ') - assert os.path.exists(f'{outdir}/atom.xml') + blag.generate_feed(articles, args.output_dir, ' ', ' ', ' ', ' ') + assert os.path.exists(f'{args.output_dir}/atom.xml') -def test_feed(tempdir): - outdir = f'{tempdir}/build' +def test_feed(args): articles = [ [ 'dest1.html', @@ -36,9 +34,9 @@ def test_feed(tempdir): ] - blag.generate_feed(articles, outdir, 'https://example.com/', 'blog title', - 'blog description', 'blog author') - with open(f'{outdir}/atom.xml') as fh: + blag.generate_feed(articles, args.output_dir, 'https://example.com/', + 'blog title', 'blog description', 'blog author') + with open(f'{args.output_dir}/atom.xml') as fh: feed = fh.read() assert '