mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
replaced args with cleandir where possible, removed tempdir
This commit is contained in:
@@ -1 +1 @@
|
||||
__VERSION__ = '0.0.6'
|
||||
__VERSION__ = '0.0.7'
|
||||
|
||||
@@ -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,14 +61,11 @@ author = a. u. thor
|
||||
os.mkdir(f'{dir}/{d}')
|
||||
with open(f'{dir}/config.ini', 'w') as fh:
|
||||
fh.write(config)
|
||||
yield dir
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cleandir(tempdir):
|
||||
# change directory
|
||||
old_cwd = os.getcwd()
|
||||
os.chdir(tempdir)
|
||||
yield
|
||||
os.chdir(dir)
|
||||
yield dir
|
||||
# and change back afterwards
|
||||
os.chdir(old_cwd)
|
||||
|
||||
|
||||
|
||||
@@ -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 '<title>blog title</title>' in feed
|
||||
@@ -60,7 +60,7 @@ def test_feed(args):
|
||||
assert '<link href="https://example.com/dest2.html"' in feed
|
||||
|
||||
|
||||
def test_generate_feed_with_description(args):
|
||||
def test_generate_feed_with_description(cleandir):
|
||||
# if a description is provided, it will be used as the summary in
|
||||
# the feed, otherwise we simply use the title of the article
|
||||
articles = [[
|
||||
@@ -72,9 +72,9 @@ def test_generate_feed_with_description(args):
|
||||
'content': 'content',
|
||||
}
|
||||
]]
|
||||
blag.generate_feed(articles, args.output_dir, ' ', ' ', ' ', ' ')
|
||||
blag.generate_feed(articles, 'build', ' ', ' ', ' ', ' ')
|
||||
|
||||
with open(f'{args.output_dir}/atom.xml') as fh:
|
||||
with open('build/atom.xml') as fh:
|
||||
feed = fh.read()
|
||||
|
||||
assert '<title>title</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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user