Other supporting code
Tools for demos and semi-automated testing
Scribbling on papers
Plom tools for scribbling fake answers on PDF files.
- plom.create.scribble_utils.fill_in_fake_data_on_exams(paper_dir, classlist, outfile, *, which=None)[source]
Fill-in exams with fake data for demo or testing.
- Parameters:
paper_dir (str/pathlib.Path) – Directory containing the blank exams.
classlist (list) – list of dicts with keys id and name. See also Issue #1646: deprecate student_number by id
outfile (str/pathlib.Path) – write results into this concatenated PDF file.
- Keyword Arguments:
which (iterable) – By default we scribble on all exams or specify something like
which=range(10, 16)here to scribble on a subset. (default: None)- Returns:
None
- plom.create.scribble_utils.make_colliding_pages(paper_dir, outfile)[source]
Build two colliding pages - last pages of papers 2 and 3.
- Parameters:
paper_dir (str/pathlib.Path) – Directory containing the blank exams.
outfile (pathlib.Path) – modify this pdf file, appending the colliding pages.
Intended for testing.
- plom.create.scribble_utils.make_garbage_pages(pdf_file, number_of_garbage_pages=2)[source]
Randomly generates and inserts garbage pages into a PDF document.
- Parameters:
pdf_file (pathlib.Path) – a pdf file we add pages to.
- Keyword Arguments:
number_of_garbage_pages (int) – how many junk pages to add (default: 2)
- Returns:
None
Intended for testing.
- plom.create.scribble_utils.make_scribbles(basedir=PosixPath('.'), *, msgr)[source]
Fake exam writing by scribbling on the pages of the blank exams.
After Plom exam PDF files have been generated, this can be used to scribble on them to simulate random student work. Note this tool does not upload those files, it just makes some PDF files for you to play with or for testing purposes.
- Parameters:
basedir (str/pathlib.Path) – the blank tests (for scribbling) will be taken from basedir/papersToPrint. The pdf files with scribbles will be created in basedir. Defaults to current directory.
- Keyword Arguments:
msgr (plom.Messenger/tuple) – either a connected Messenger or a tuple appropriate for credientials.
- Returns:
None
Read in the existing papers.
Create the fake data filled pdfs
Do some things to make the data unpleasant:
delete the last page of the first test.
Randomly add some extra pages
- plom.create.scribble_utils.scribble_name_and_id(pdf_doc, student_id, student_name, *, pagenum=0, seed=None, y_offset: int = 0)[source]
Write name/number on coverpage of pymupdf pdf_doc.
- Parameters:
pdf_doc (pymupdf.Document) – an open pdf file, we’ll modify it implicitly but not close it.
student_id (str) – student id number to write on page.
student_name (str) – student name to write on page.
- Keyword Arguments:
pagenum (int) – which page is the coverpage, default 0 (1st page).
seed (None/int) – seed the random number generator with this value. Default of None means don’t. This can be used to ensure the same digit images are chosen each time, useful for testing.
y_offset – how far to offset the scribbles from their ‘default’ position in the version-1 assessment paper.
- Returns:
but modifies the open document as a side effect.
- Return type:
None
- plom.create.scribble_utils.scribble_pages(pdf_doc, exclude=(0, 1))[source]
Scribble on most pages of pymupdf pdf_doc.
- Parameters:
pdf_doc (pymupdf.Document) – an open pdf file, we’ll modify it implicitly but not close it.
- Keyword Arguments:
exclude – which pages to exclude. By default exclude pages 0 and 1 (the ID page and DNM page in our demo data).
- Returns:
but modifies the open document as a side effect.
- Return type:
None
Random grading: plom.client.randoMarker
Command-line script
Module docs
Random identifying: plom.client.randoIDer
Command-line script
Module docs
TeX Tools
Tools for working with TeX.
- plom.textools.buildLaTeX(src: str, out: IO[bytes]) tuple[int, str][source]
Compile a string presentation of a latex file, with the idbox template available.
- Parameters:
src – a string of LaTeX code to compile.
out – a file-like object for writing binary data (such as the result of
open("foo.pdf", "wb") as f:. The PDF data will be written into this.
- Returns:
Tuple containing an integer exit value from the subprocess call (zero good, non-zero bad), and a string of the combined stdout/stderr from the subprocess call.
- plom.textools.texFragmentToPNG(fragment: str, *, dpi: int = 225) tuple[bool, bytes | str][source]
Process a fragment of latex and produce a png image.
- Parameters:
fragment – a string of text to be rendered with LaTeX.
- Keyword Arguments:
dpi – controls the resolution of the image by setting the dots-per-inch. Defaults: 225.
- Returns:
(True, imgdata) or (False, error_msg) where imgdata is the raw contents of a PNG file, and error_msg is (currently) a string, but this could change in the future.
- Return type:
tuple
- Raises:
Not expected to raise any exceptions. –