Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
*.pyc
*~
*.swp
/.cache/
/problemtools.egg-info/
/support/default_validator/default_validator
/support/interactive/interactive
build/

venv/
.pytest_cache/
.mypy_cache/
15 changes: 0 additions & 15 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,5 @@ install_types = True
check_untyped_defs = True
ignore_errors = False

[mypy-problemtools.tests.*]
ignore_errors = True

[mypy-problemtools.generatedata]
ignore_errors = True

[mypy-problemtools.languages]
ignore_errors = True

[mypy-problemtools.template]
ignore_errors = True

[mypy-problemtools.run.checktestdata]
ignore_errors = True

[mypy-problemtools.run.viva]
ignore_errors = True
15 changes: 5 additions & 10 deletions problemtools/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_source_files(self, file_list):
"""
return [file_name for file_name in file_list
if (any(fnmatch.fnmatch(file_name, glob)
for glob in self.files)
for glob in self.files) # type: ignore[union-attr]
and
self.__matches_shebang(file_name))]

Expand Down Expand Up @@ -105,18 +105,13 @@ def __check(self):
"""
# Check that all mandatory fields are provided
if self.name is None:
raise LanguageConfigError(
'Language %s has no name' % self.lang_id)
raise LanguageConfigError(f'Language {self.lang_id} has no name')
if self.priority is None:
raise LanguageConfigError(
'Language %s has no priority' % self.lang_id)
raise LanguageConfigError(f'Language {self.lang_id} has no priority')
if self.files is None:
raise LanguageConfigError(

'Language %s has no files glob' % self.lang_id)
raise LanguageConfigError(f'Language {self.lang_id} has no files glob')
if self.run is None:
raise LanguageConfigError(
'Language %s has no run command' % self.lang_id)
raise LanguageConfigError(f'Language {self.lang_id} has no run command')

# Check that all variables appearing are valid
variables = Language.__variables_in_command(self.run)
Expand Down
8 changes: 5 additions & 3 deletions problemtools/run/checktestdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def do_compile(self) -> tuple[bool, str|None]:
return ((os.WIFEXITED(status) and os.WEXITSTATUS(status) in [0, 1]), None)


def run(self, infile='/dev/null', outfile='/dev/null',
errfile='/dev/null', args=None, timelim=1000):
def run(self, infile='/dev/null', outfile='/dev/null', errfile='/dev/null',
args=None, timelim=1000, memlim=1024, work_dir=None):
"""Run the Checktestdata script to validate an input file.

Args:
Expand All @@ -66,7 +66,9 @@ def run(self, infile='/dev/null', outfile='/dev/null',
outfile=outfile,
errfile=errfile,
args=args,
timelim=timelim)
timelim=timelim,
memlim=memlim,
work_dir=work_dir)
# This is ugly, switches the accept exit status and our accept
# exit status 42.
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
Expand Down
2 changes: 1 addition & 1 deletion problemtools/run/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(self, infile='/dev/null', outfile='/dev/null', errfile='/dev/null',
Args:
infile (str): name of file to pass on stdin
outfile (str): name of file to send stdout to
errfile (str): name of file to send stderr ro
errfile (str): name of file to send stderr to
args (list of str): additional command-line arguments to
pass to the program
timelim (int): CPU time limit in seconds
Expand Down
8 changes: 5 additions & 3 deletions problemtools/run/viva.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def do_compile(self) -> tuple[bool, str|None]:
return ((os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0), None)


def run(self, infile='/dev/null', outfile='/dev/null',
errfile='/dev/null', args=None, timelim=1000):
def run(self, infile='/dev/null', outfile='/dev/null', errfile='/dev/null',
args=None, timelim=1000, memlim=1024, work_dir=None):
"""Run the VIVA script to validate an input file.

Args:
Expand All @@ -68,7 +68,9 @@ def run(self, infile='/dev/null', outfile='/dev/null',
(status, runtime) = super(Viva, self).run(outfile=outfile,
errfile=errfile,
args=args,
timelim=timelim)
timelim=timelim,
memlim=memlim,
work_dir=work_dir)
# This is ugly, switches the accept exit status and our accept
# exit status 42.
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
Expand Down
10 changes: 5 additions & 5 deletions problemtools/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, problemdir, language=None, force_copy_cls=False):
if glob.glob(os.path.join(stmtdir, 'problem.tex')):
langs.append('')
for f in glob.glob(os.path.join(stmtdir, 'problem.[a-z][a-z].tex')):
langs.append(re.search("problem.([a-z][a-z]).tex$", f).group(1))
langs.append(re.search("problem.([a-z][a-z]).tex$", f).group(1)) # type: ignore[union-attr]
if len(langs) == 0:
raise Exception('No problem statements available')

Expand Down Expand Up @@ -61,10 +61,10 @@ def __init__(self, problemdir, language=None, force_copy_cls=False):
templatepaths = [os.path.join(os.path.dirname(__file__), 'templates/latex'),
os.path.join(os.path.dirname(__file__), '../templates/latex'),
'/usr/lib/problemtools/templates/latex']
self.templatepath = next((p for p in templatepaths
if os.path.isdir(p) and os.path.isfile(os.path.join(p, self.templatefile))),
None)
if self.templatepath is None:
try:
self.templatepath = next((p for p in templatepaths
if os.path.isdir(p) and os.path.isfile(os.path.join(p, self.templatefile))))
except StopIteration:
raise Exception('Could not find directory with latex template "%s"' % self.templatefile)

self.basedir = os.path.dirname(problemdir)
Expand Down
6 changes: 3 additions & 3 deletions problemtools/tests/test_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_update(self):
assert lang.files == ['*']

lang.update({'shebang': 'new.*end'})
assert lang.shebang.match('newfilend')
assert lang.shebang is not None and lang.shebang.match('newfilend')

with pytest.raises(languages.LanguageConfigError):
# ambiguous entry point
Expand All @@ -52,9 +52,9 @@ def test_update(self):
def test_invalid_id(self):
vals = self.__language_dict()
with pytest.raises(TypeError):
languages.Language(None, vals)
languages.Language(None, vals) # type: ignore
with pytest.raises(TypeError):
languages.Language(42, vals)
languages.Language(42, vals) # type: ignore
with pytest.raises(languages.LanguageConfigError):
languages.Language('åäö', vals)
with pytest.raises(languages.LanguageConfigError):
Expand Down
2 changes: 1 addition & 1 deletion problemtools/tests/test_output_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_output_validator_feedback():
text = "".join(r.choices(string.printable))
feedback.write_text(text)
data = OutputValidators._get_feedback(directory)
assert text in data
assert data is not None and text in data


def test_output_validator_feedback_non_unicode():
Expand Down
5 changes: 3 additions & 2 deletions problemtools/tests/test_verify_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ def test_load_hello():

args = verify.argparser().parse_args([string])
verify.initialize_logging(args)
context = verify.Context(args, None)

with verify.Problem(string) as p:
assert p.shortname == "hello"
# pytest and fork don't go along very well, so just run aspects that work without run
assert p.getProblemPart(verify.ProblemConfig).check(args)
assert p.getProblemPart(verify.Attachments).check(args)
assert p.getProblemPart(verify.ProblemConfig).check(context)
assert p.getProblemPart(verify.Attachments).check(context)