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
|
@pytest.fixture
|
||||||
def tempdir():
|
def cleandir():
|
||||||
|
"""Create a temporary workind directory and cwd.
|
||||||
|
|
||||||
|
"""
|
||||||
config = """
|
config = """
|
||||||
[main]
|
[main]
|
||||||
base_url = https://example.com/
|
base_url = https://example.com/
|
||||||
@@ -58,15 +61,12 @@ author = a. u. thor
|
|||||||
os.mkdir(f'{dir}/{d}')
|
os.mkdir(f'{dir}/{d}')
|
||||||
with open(f'{dir}/config.ini', 'w') as fh:
|
with open(f'{dir}/config.ini', 'w') as fh:
|
||||||
fh.write(config)
|
fh.write(config)
|
||||||
|
# change directory
|
||||||
|
old_cwd = os.getcwd()
|
||||||
|
os.chdir(dir)
|
||||||
yield dir
|
yield dir
|
||||||
|
# and change back afterwards
|
||||||
|
os.chdir(old_cwd)
|
||||||
@pytest.fixture
|
|
||||||
def cleandir(tempdir):
|
|
||||||
old_cwd = os.getcwd()
|
|
||||||
os.chdir(tempdir)
|
|
||||||
yield
|
|
||||||
os.chdir(old_cwd)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import pytest
|
|||||||
from blag import blag
|
from blag import blag
|
||||||
|
|
||||||
|
|
||||||
def test_generate_feed(args):
|
def test_generate_feed(cleandir):
|
||||||
articles = []
|
articles = []
|
||||||
blag.generate_feed(articles, args.output_dir, ' ', ' ', ' ', ' ')
|
blag.generate_feed(articles, 'build', ' ', ' ', ' ', ' ')
|
||||||
assert os.path.exists(f'{args.output_dir}/atom.xml')
|
assert os.path.exists('build/atom.xml')
|
||||||
|
|
||||||
|
|
||||||
def test_feed(args):
|
def test_feed(cleandir):
|
||||||
articles = [
|
articles = [
|
||||||
[
|
[
|
||||||
'dest1.html',
|
'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')
|
'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()
|
feed = fh.read()
|
||||||
|
|
||||||
assert '<title>blog title</title>' in feed
|
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
|
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
|
# if a description is provided, it will be used as the summary in
|
||||||
# the feed, otherwise we simply use the title of the article
|
# the feed, otherwise we simply use the title of the article
|
||||||
articles = [[
|
articles = [[
|
||||||
@@ -72,9 +72,9 @@ def test_generate_feed_with_description(args):
|
|||||||
'content': 'content',
|
'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()
|
feed = fh.read()
|
||||||
|
|
||||||
assert '<title>title</title>' in feed
|
assert '<title>title</title>' in feed
|
||||||
@@ -176,7 +176,7 @@ def test_environment_factory():
|
|||||||
assert env.globals['test'] == 'me'
|
assert env.globals['test'] == 'me'
|
||||||
|
|
||||||
|
|
||||||
def test_process_markdown(args, page_template, article_template):
|
def test_process_markdown(cleandir, page_template, article_template):
|
||||||
page1 = """\
|
page1 = """\
|
||||||
title: some page
|
title: some page
|
||||||
|
|
||||||
@@ -203,14 +203,14 @@ foo bar
|
|||||||
convertibles = []
|
convertibles = []
|
||||||
for i, txt in enumerate((page1, article1, article2)):
|
for i, txt in enumerate((page1, article1, article2)):
|
||||||
i = str(i)
|
i = str(i)
|
||||||
with open(f'{args.input_dir}/{i}', 'w') as fh:
|
with open(f'content/{i}', 'w') as fh:
|
||||||
fh.write(txt)
|
fh.write(txt)
|
||||||
convertibles.append([i, i])
|
convertibles.append([i, i])
|
||||||
|
|
||||||
articles, pages = blag.process_markdown(
|
articles, pages = blag.process_markdown(
|
||||||
convertibles,
|
convertibles,
|
||||||
args.input_dir,
|
'content',
|
||||||
args.output_dir,
|
'build',
|
||||||
page_template,
|
page_template,
|
||||||
article_template
|
article_template
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,19 +3,19 @@ import time
|
|||||||
from blag import devserver
|
from blag import devserver
|
||||||
|
|
||||||
|
|
||||||
def test_get_last_modified(tempdir):
|
def test_get_last_modified(cleandir):
|
||||||
# take initial time
|
# take initial time
|
||||||
t1 = devserver.get_last_modified([tempdir])
|
t1 = devserver.get_last_modified(['content'])
|
||||||
|
|
||||||
# wait a bit, create a file and measure again
|
# wait a bit, create a file and measure again
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
with open(f'{tempdir}/test', 'w') as fh:
|
with open('content/test', 'w') as fh:
|
||||||
fh.write('boo')
|
fh.write('boo')
|
||||||
t2 = devserver.get_last_modified([tempdir])
|
t2 = devserver.get_last_modified(['content'])
|
||||||
|
|
||||||
# wait a bit and take time again
|
# wait a bit and take time again
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
t3 = devserver.get_last_modified([tempdir])
|
t3 = devserver.get_last_modified(['content'])
|
||||||
|
|
||||||
assert t2 > t1
|
assert t2 > t1
|
||||||
assert t2 == t3
|
assert t2 == t3
|
||||||
|
|||||||
Reference in New Issue
Block a user