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 'blog title' in feed @@ -62,8 +60,7 @@ def test_feed(tempdir): assert 'title' in feed @@ -179,9 +176,7 @@ def test_environment_factory(): assert env.globals['test'] == 'me' -def test_process_markdown(tempdir, page_template, article_template): - inputdir = f'{tempdir}/content' - outdir = f'{tempdir}/build' +def test_process_markdown(args, page_template, article_template): page1 = """\ title: some page @@ -208,14 +203,14 @@ foo bar convertibles = [] for i, txt in enumerate((page1, article1, article2)): i = str(i) - with open(f'{inputdir}/{i}', 'w') as fh: + with open(f'{args.input_dir}/{i}', 'w') as fh: fh.write(txt) convertibles.append([i, i]) articles, pages = blag.process_markdown( convertibles, - inputdir, - outdir, + args.input_dir, + args.output_dir, page_template, article_template ) @@ -280,11 +275,5 @@ foo bar blag.build(args) -def test_main(args): - arglist = ['build'] - arglist.append(f'--input-dir={args.input_dir}') - arglist.append(f'--output-dir={args.output_dir}') - arglist.append(f'--static-dir={args.static_dir}') - arglist.append(f'--template-dir={args.template_dir}') - - blag.main(arglist) +def test_main(cleandir): + blag.main(['build'])