Feat: Add test! snippet compilation failed thow...

This commit is contained in:
Bertrand Benjamin 2019-12-23 15:05:50 +01:00
parent b40b114bb4
commit 9d5c231c9c
4 changed files with 160 additions and 9 deletions

View File

@ -2,7 +2,8 @@
# encoding: utf-8
__version__ = "0.1"
from .bopytex import produce_and_compile
# -----------------------------
# Reglages pour 'vim'

View File

@ -100,7 +100,11 @@ def pdfjoin(pdf_files, destname, working_dir=".", rm_pdfs=1):
def extract_student_csv(csv_filename):
""" Extract student list from csv_filename """
""" Extract student list from csv_filename
Student identifier is got in the column "Élève".
"""
with open(csv_filename, "r") as csvfile:
reader = csv.DictReader(csvfile)
return [r["Élève"] for r in reader]
@ -113,7 +117,7 @@ def produce_and_compile(options):
if options["only_corr"]:
options["corr"] = True
tex_files = working_dir.files("[0-9]*_*.tex")
tex_files = working_dir.glop("[0-9]*_*.tex")
else:
template = Path(options["template"]).name
logger.debug(f"Template will be {template}")
@ -152,16 +156,16 @@ def produce_and_compile(options):
)
logger.debug(f"{dest} fed")
if not options["no_compil"]:
if not options["no_compile"]:
pdf_files = []
for texfile in tex_files:
logger.debug(f"Start compiling {texfile}")
pytex.pdflatex(texfile)
logger.debug(f"End compiling {texfile}")
pdf_files.append(str(texfile[:-4] + ".pdf"))
pdf_files.append(str(texfile).split('.')[0] + ".pdf")
logger.debug(f"Compiled files : {pdf_files}")
if not options["no_join"] and not options["no_compil"]:
if not options["no_join"] and not options["no_compile"]:
pdfjoin(
pdf_files,
template.replace("tpl", "all").replace(".tex", ".pdf"),
@ -173,14 +177,14 @@ def produce_and_compile(options):
pdf_files = []
for texfile in tex_files:
corr_fname = activate_printanswers(texfile)
if not options["no_compil"]:
if not options["no_compile"]:
logger.debug(f"Start compiling {texfile}")
pytex.pdflatex(corr_fname)
logger.debug(f"End compiling {texfile}")
pdf_files.append(str(corr_fname[:-4] + ".pdf"))
pdf_files.append(str(corr_fname).split(".")[0] + ".pdf")
deactivate_printanswers(corr_fname)
if not options["no_join"] and not options["no_compil"]:
if not options["no_join"] and not options["no_compile"]:
pdfjoin(
pdf_files,
template.replace("tpl", "corr").replace(".tex", ".pdf"),

View File

@ -0,0 +1,22 @@
\documentclass[12pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\title{
Tests
}
\author{
Benjamin Bertrand
}
\begin{document}
\maketitle
\end{document}

124
test/test_bopytex.py Normal file
View File

@ -0,0 +1,124 @@
#!/usr/bin/env python
# encoding: utf-8
import pytest
import os
from pathlib import Path
from shutil import copyfile
from bopytex import produce_and_compile
SNIPPETS_PATH = Path("snippets/")
TEST_TEMPLATE_PATH = Path("test/templates/")
@pytest.fixture
def prepare_test_template(tmp_path):
""" Create a tmp directory, copy snippets inside
return tmp directory name
"""
tmp = tmp_path
snippets = TEST_TEMPLATE_PATH.glob("tpl_*.tex")
for s in snippets:
copyfile(s, tmp / s.name)
prev_dir = Path.cwd()
os.chdir(tmp)
yield tmp
os.chdir(prev_dir)
@pytest.fixture
def prepare_snippets(tmp_path):
""" Create a tmp directory, copy snippets inside
return tmp directory name
"""
tmp = tmp_path
snippets = SNIPPETS_PATH.glob("tpl_*.tex")
for s in snippets:
copyfile(s, tmp / s.name)
prev_dir = Path.cwd()
os.chdir(tmp)
yield tmp
os.chdir(prev_dir)
def test_produce_and_compile_base(prepare_test_template):
test_tpl = list(Path(".").glob("tpl_*.tex"))
assert [tpl.name for tpl in test_tpl] == ["tpl_test.tex"]
for tpl in test_tpl:
produce_and_compile(
{
"template": tpl,
"working_dir": None,
"only_corr": False,
"students_csv": None,
"number_subjects": 1,
"dirty": False,
"no_compile": False,
"no_join": False,
"corr": False,
"crazy": False,
}
)
def test_pdfjoin_current_directory(prepare_test_template):
wdir = prepare_test_template
pass
def test_pdfjoin_deep_directory():
pass
def test_pdfjoin_dont_remove():
pass
def test_subject_names():
pass
def test_feed_texfiles():
pass
def test_tex2pdf_current_directory():
pass
def test_tex2pdf_deep_directory():
pass
def test_activate_solution():
pass
def test_snippets(prepare_snippets):
snippets = list(Path(".").glob("tpl_*.tex"))
for tpl in snippets:
produce_and_compile(
{
"template": tpl,
"working_dir": None,
"only_corr": False,
"students_csv": None,
"number_subjects": 1,
"dirty": False,
"no_compile": False,
"no_join": False,
"corr": False,
"crazy": False,
}
)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del