mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 12:42:41 +00:00
added tests for build and main
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user