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
2 changes: 1 addition & 1 deletion problemtools/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, problem_root: Path, texfile: Path, language: str, force_copy_

sample_dir = problem_root / 'data' / 'sample'
if sample_dir.is_dir():
self.samples = sorted({file.stem for file in sample_dir.iterdir() if file.suffix in ['in', 'interaction']})
self.samples = sorted({file.stem for file in sample_dir.iterdir() if file.suffix in ['.in', '.interaction']})
else:
self.samples = []

Expand Down
35 changes: 34 additions & 1 deletion tests/test_latex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import Path
import re
import tempfile

from problemtools import problem2pdf
from problemtools import problem2html, problem2pdf


def test_pdf_render_verifyproblem():
Expand All @@ -26,3 +27,35 @@ def test_pdf_render_problem2pdf():
assert False, 'PDF conversion failed'
with open(temp_filename, 'rb') as temp_file:
assert temp_file.read(5) == b'%PDF-', 'Output header does not look like a PDF.'


def test_html_render_different():
# Same options as typical problem2html usage
with tempfile.TemporaryDirectory() as temp_dir:
problem_path = Path(__file__).parent / '..' / 'examples' / 'different'
temp_dir = Path(temp_dir) / 'different_html'
options = problem2html.get_parser().parse_args(['-d', str(temp_dir), '-l', 'en', '-q', str(problem_path.resolve())])
problem2html.convert(options)
with open(temp_dir / 'index.html', 'r') as temp_file:
full_html = temp_file.read()
assert re.search('<html>', full_html)
assert re.search('A Different Problem', full_html)
assert re.search('Problem ID: different', full_html)
assert re.search('Write a program that computes', full_html)
assert re.search('71293781758123 72784', full_html) # part of sample


def test_html_render_guess():
# Same options as typical problem2html usage
with tempfile.TemporaryDirectory() as temp_dir:
problem_path = Path(__file__).parent / '..' / 'examples' / 'guess'
temp_dir = Path(temp_dir) / 'guess_html'
options = problem2html.get_parser().parse_args(['-d', str(temp_dir), '-l', 'en', '-q', str(problem_path.resolve())])
problem2html.convert(options)
with open(temp_dir / 'index.html', 'r') as temp_file:
full_html = temp_file.read()
assert re.search('<html>', full_html)
assert re.search('Guess the Number', full_html)
assert re.search('Problem ID: guess', full_html)
assert re.search('After each guess,', full_html) # Short snippet from statement
assert re.search('995', full_html) # part of sample