Feat: test in tmp dir and few bug correction

This commit is contained in:
Bertrand Benjamin 2019-12-23 14:29:15 +01:00
parent 86d523d222
commit 737d64e0a8
3 changed files with 35 additions and 22 deletions

View File

@ -71,7 +71,7 @@ def feed(template, data, output="", force=0):
output_dir = output_p.parent
if output_dir and not output_dir.exists():
logger.debug(f"Creating output dir {output_dir}")
output_dir.mkdir_p()
output_dir.mkdir(exist_ok=True)
with open(output_p, "w") as output_f:
output_f.write(tpl.render(**EXPORT_DICT, **data))

View File

@ -24,7 +24,6 @@ texenv = jinja2.Environment(
line_statement_prefix='%-',
line_comment_prefix='%#',
loader=jinja2.ChoiceLoader([
# jinja2.PackageLoader("notes_tools.reports", "templates"),
jinja2.FileSystemLoader(['./']),
]),
extensions=['jinja2.ext.do']

View File

@ -3,42 +3,56 @@
from pytex import feed, pdflatex, clean
import os
from shutil import copyfile
from pathlib import Path
import pytest
TESTDIR = "tests"
GOOD_TEMPLATE = TESTDIR + "/tpl_good.tex"
WRONG_TEMPLATE = TESTDIR + "/tpl_wrong.tex"
TESTDIR = Path("tests")
GOOD_TEMPLATE = TESTDIR / "tpl_good.tex"
GOOD_DATA = {
"name": "Bob",
"repetitions": 4,
}
def test_feed_once():
output = feed(GOOD_TEMPLATE, GOOD_DATA)
os.system(f"rm {output}")
def test_feed_twice():
output1 = feed(GOOD_TEMPLATE, GOOD_DATA)
output2 = feed(GOOD_TEMPLATE, GOOD_DATA)
os.system(f"rm {output1}")
os.system(f"rm {output2}")
@pytest.fixture()
def prepare_templates(tmpdir):
wdir = tmpdir
good_tpl = Path(GOOD_TEMPLATE)
copyfile(good_tpl, wdir / good_tpl.name)
prev_cwd = Path.cwd()
def test_feed_output():
os.chdir(wdir)
yield wdir
os.chdir(prev_cwd)
def test_feed_once(prepare_templates):
output = feed(GOOD_TEMPLATE.name, GOOD_DATA)
def test_feed_twice(prepare_templates):
output1 = feed(GOOD_TEMPLATE.name, GOOD_DATA)
output2 = feed(GOOD_TEMPLATE.name, GOOD_DATA)
def test_feed_output(prepare_templates):
dest = "./tests/special_name.tex"
output = feed(GOOD_TEMPLATE, GOOD_DATA, dest)
assert(output.samefile(dest))
os.system(f"rm {output}")
output = feed(GOOD_TEMPLATE.name, GOOD_DATA, dest)
assert output.samefile(dest)
def test_feed_output_noforce():
pass
# output = feed(GOOD_TEMPLATE, GOOD_DATA, )
# os.system(f"rm {output}")
def test_feed_pdflatex():
latex_file = feed(GOOD_TEMPLATE, GOOD_DATA)
def test_feed_pdflatex(prepare_templates):
latex_file = feed(GOOD_TEMPLATE.name, GOOD_DATA)
pdflatex(latex_file)
os.system(f"rm {latex_file}")
clean(TESTDIR, ["*.aux", "*.log", "*.pdf"])
clean(garbages=["*.aux", "*.log", "*.pdf"])
# -----------------------------