Commit 8915224e authored by Louis's avatar Louis
Browse files

[testexo] Il est maintenant possible de compiler une liste d'exercices (et non...

[testexo] Il est maintenant possible de compiler une liste d'exercices (et non pas un unique exercice)

- Ajout de l'option `--output` à testexos
parent e004291a
......@@ -74,6 +74,46 @@ def test_path(dirlevel, name, seed, choice):
"%s.%s.%s" % (name, seed, choice)
)
def compile(exercise_list, openpdf=False, destname=None, pipe=None):
"""Compile exercise list as a pdf, and return the resulting pdf name.
:param openpdf: Open pdf at the end of compilation.
:param str destname: Destination name (use ``None`` to use the default name).
:param list pipe: List of commands executed on the tex file before compilation.
"""
tempdir = tempfile.mkdtemp()
old_dir = os.path.abspath(os.getcwd())
System.creation({
'creer_pdf': True,
'creer_unpdf': True,
'titre': u"Fiche de révisions",
'corrige': True,
'niveau': "test",
'nom_fichier': u'test.tex',
'chemin_fichier': tempdir,
'fiche_exo': os.path.join(tempdir, 'exercises.tex'),
'fiche_cor': os.path.join(tempdir, 'exercises-corrige.tex'),
'datadir': pyromaths.Values.data_dir(),
'configdir': pyromaths.Values.configdir(),
'modele': 'pyromaths.tex',
'liste_exos': exercise_list,
'les_fiches': pyromaths.Values.lesfiches(),
'openpdf': openpdf,
'pipe': pipe,
})
os.chdir(old_dir)
if destname:
shutil.move(
os.path.join(tempdir, 'exercises.pdf'),
destname,
)
else:
destname = os.path.join(tempdir, 'exercises.pdf')
return destname
class TestExercise(object):
"""Test of an exercise"""
......@@ -90,44 +130,9 @@ class TestExercise(object):
random.seed(self.seed)
return self.exercise()
def compile(self, openpdf=0, movefile=False, pipe=None):
def compile(self, openpdf=0):
"""Compile exercise"""
tempdir = tempfile.mkdtemp()
old_dir = os.path.abspath(os.getcwd())
System.creation({
'creer_pdf': True,
'creer_unpdf': True,
'titre': u"Fiche de révisions",
'corrige': True,
'niveau': "test",
'nom_fichier': u'test.tex',
'chemin_fichier': tempdir,
'fiche_exo': os.path.join(tempdir, 'exercises.tex'),
'fiche_cor': os.path.join(tempdir, 'exercises-corrige.tex'),
'datadir': pyromaths.Values.data_dir(),
'configdir': pyromaths.Values.configdir(),
'modele': 'pyromaths.tex',
'liste_exos': [self.get_exercise()],
'les_fiches': pyromaths.Values.lesfiches(),
'openpdf': openpdf,
'pipe': pipe,
})
os.chdir(old_dir)
if movefile:
destname = "{}-{}.pdf".format(
self.exercise.id(),
self.seed,
)
shutil.move(
os.path.join(tempdir, 'exercises.pdf'),
destname,
)
else:
destname = os.path.join(tempdir, 'exercises.pdf')
return destname
return compile([self.get_exercise()], openpdf=openpdf)
def test_path(self, name):
"""Return the path of the file containing expected results."""
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 -- Louis Paternault (spalax@gresille.org)
# Copyright (C) 2016 -- Louis Paternault (spalax@gresille.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -27,13 +27,14 @@ To display help:
import argparse
import gettext
import logging
import random
import sys
import unittest
# Quick and dirty definition of `_` as the identity function
gettext.install('pyromaths', unicode=1)
from pyromaths.ex.test import TestPerformer, TestException
from pyromaths.ex.test import TestPerformer, TestException, compile
# Logging configuration
logging.basicConfig(level=logging.INFO)
......@@ -164,6 +165,14 @@ def argument_parser():
"of the string."
)
)
compile_parser.add_argument(
'-o', '--output',
type=str,
default='exercice.pdf',
help=(
"Output filename. Default is 'exercice.pdf'."
),
)
# Check
check = subparsers.add_parser(
......@@ -272,12 +281,18 @@ def do_compile(options):
else:
options.pipe = [item[0] for item in options.pipe]
exercise_list = []
for exercise, seeds in options.exercise:
if not seeds:
seeds = [0]
seeds = [random.randint(0, sys.maxint)]
for seed in seeds:
test = tests.get(exercise, seed)
test.compile(movefile=True, pipe=options.pipe)
exercise_list.append(tests.get(exercise, seed).get_exercise())
compile(
exercise_list,
destname=options.output,
pipe=options.pipe,
)
def do_check(options):
"""Run the tests"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment