From 72971408b21bcb7e911d65d5f2db0f9cc2dae6d6 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Mon, 29 Mar 2021 12:40:13 +0200 Subject: [PATCH] added tests for build and main --- tests/conftest.py | 17 ++++++++++++++ tests/test_blag.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 88689a7..148e4fa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -49,3 +49,20 @@ def tempdir(): for d in 'content', 'build', 'static', 'templates': mkdir(f'{dir}/{d}') yield dir + + +@pytest.fixture +def args(tempdir): + + class NameSpace: + def __init__(self, **kwargs): + for name in kwargs: + 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', + ) + yield args diff --git a/tests/test_blag.py b/tests/test_blag.py index dfc75b5..d3c7804 100644 --- a/tests/test_blag.py +++ b/tests/test_blag.py @@ -233,3 +233,58 @@ foo bar assert isinstance(dst, str) assert isinstance(context, dict) assert 'content' in context + + +def test_build(args): + page1 = """\ +title: some page + +some text +foo bar + """ + + article1 = """\ +title: some article1 +date: 2020-01-01 +tags: foo, bar + +some text +foo bar + """ + + article2 = """\ +title: some article2 +date: 2021-01-01 +tags: baz + +some text +foo bar + """ + + # write some convertibles + convertibles = [] + for i, txt in enumerate((page1, article1, article2)): + i = str(i) + with open(f'{args.input_dir}/{i}.md', 'w') as fh: + fh.write(txt) + convertibles.append([i, i]) + + # some static files + with open(f'{args.static_dir}/test', 'w') as fh: + fh.write('hello') + + os.mkdir(f'{args.input_dir}/testdir') + with open(f'{args.input_dir}/testdir/test', 'w') as fh: + fh.write('hello') + + 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)