From 9cdecdccf70664cc293e5cba7130d80d215fc1e1 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Mon, 29 Mar 2021 13:17:40 +0200 Subject: [PATCH] replaced args with cleandir where possible, removed tempdir --- blag/version.py | 2 +- tests/conftest.py | 18 +++++++++--------- tests/test_blag.py | 26 +++++++++++++------------- tests/test_devserver.py | 10 +++++----- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/blag/version.py b/blag/version.py index 5726675..b282d03 100644 --- a/blag/version.py +++ b/blag/version.py @@ -1 +1 @@ -__VERSION__ = '0.0.6' +__VERSION__ = '0.0.7' diff --git a/tests/conftest.py b/tests/conftest.py index 221f0af..221078c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -44,7 +44,10 @@ def tag_template(environment): @pytest.fixture -def tempdir(): +def cleandir(): + """Create a temporary workind directory and cwd. + + """ config = """ [main] base_url = https://example.com/ @@ -58,15 +61,12 @@ author = a. u. thor 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) yield dir - - -@pytest.fixture -def cleandir(tempdir): - old_cwd = os.getcwd() - os.chdir(tempdir) - yield - os.chdir(old_cwd) + # and change back afterwards + os.chdir(old_cwd) @pytest.fixture diff --git a/tests/test_blag.py b/tests/test_blag.py index b50af7f..c4e19a6 100644 --- a/tests/test_blag.py +++ b/tests/test_blag.py @@ -7,13 +7,13 @@ import pytest from blag import blag -def test_generate_feed(args): +def test_generate_feed(cleandir): articles = [] - blag.generate_feed(articles, args.output_dir, ' ', ' ', ' ', ' ') - assert os.path.exists(f'{args.output_dir}/atom.xml') + blag.generate_feed(articles, 'build', ' ', ' ', ' ', ' ') + assert os.path.exists('build/atom.xml') -def test_feed(args): +def test_feed(cleandir): articles = [ [ 'dest1.html', @@ -34,9 +34,9 @@ def test_feed(args): ] - blag.generate_feed(articles, args.output_dir, 'https://example.com/', + blag.generate_feed(articles, 'build', 'https://example.com/', 'blog title', 'blog description', 'blog author') - with open(f'{args.output_dir}/atom.xml') as fh: + with open('build/atom.xml') as fh: feed = fh.read() assert 'blog title' in feed @@ -60,7 +60,7 @@ def test_feed(args): assert 'title' in feed @@ -176,7 +176,7 @@ def test_environment_factory(): assert env.globals['test'] == 'me' -def test_process_markdown(args, page_template, article_template): +def test_process_markdown(cleandir, page_template, article_template): page1 = """\ title: some page @@ -203,14 +203,14 @@ foo bar convertibles = [] for i, txt in enumerate((page1, article1, article2)): i = str(i) - with open(f'{args.input_dir}/{i}', 'w') as fh: + with open(f'content/{i}', 'w') as fh: fh.write(txt) convertibles.append([i, i]) articles, pages = blag.process_markdown( convertibles, - args.input_dir, - args.output_dir, + 'content', + 'build', page_template, article_template ) diff --git a/tests/test_devserver.py b/tests/test_devserver.py index 9ae182a..f06d45c 100644 --- a/tests/test_devserver.py +++ b/tests/test_devserver.py @@ -3,19 +3,19 @@ import time from blag import devserver -def test_get_last_modified(tempdir): +def test_get_last_modified(cleandir): # take initial time - t1 = devserver.get_last_modified([tempdir]) + t1 = devserver.get_last_modified(['content']) # wait a bit, create a file and measure again time.sleep(0.1) - with open(f'{tempdir}/test', 'w') as fh: + with open('content/test', 'w') as fh: fh.write('boo') - t2 = devserver.get_last_modified([tempdir]) + t2 = devserver.get_last_modified(['content']) # wait a bit and take time again time.sleep(0.1) - t3 = devserver.get_last_modified([tempdir]) + t3 = devserver.get_last_modified(['content']) assert t2 > t1 assert t2 == t3