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: maybe will use student_number someday.

  • 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)

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.

Purely used 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.

Used for testing.

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)

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:
  • server (str) – the name and port of the server.

  • password (str) – the “manager” password.

  • 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.

  1. Read in the existing papers.

  2. Create the fake data filled pdfs

  3. 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_number, student_name, *, pagenum=0, seed=None)[source]

Write name/number on coverpage of fitz pdf_doc.

Parameters:
  • pdf_doc (fitz.Document) – an open pdf file, we’ll modify it implicitly but not close it.

  • student_number (str) –

  • student_name (str) –

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.

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 fitz pdf_doc.

Parameters:

pdf_doc (fitz.Document) – an open pdf file, we’ll modify it implicitly but not close it.

Returns:

but modifies the open document as a side effect.

Return type:

None

By default exclude pages 0 and 1 (the ID page and DNM page in our demo data).

plom.create.scribble_utils.splitFakeFile(outfile, *, parts=3)[source]

Split the scribble pdf into specified number of files (defaults to 3)

Random grading: plom.client.randoMarker

Command-line script

Perform marking tasks randomly, generally for testing.

usage: python -m plom.client.randoMarker [-h] [-w PASSWORD] [-u USER] [-s SERVER[:PORT]]
options
-w, --password

by default, for the “scanner” user’, also checks the environment variable PLOM_SCAN_PASSWORD.

-u, --user

Override default of “scanner”

-s, --server

Which server to contact, port defaults to 41984. Also checks the environment variable PLOM_SERVER if omitted.

Module docs

Randomly scribble marks and annotations on papers for testing purposes.

This is a very very cut-down version of Annotator, and a command-line tool used to automate some random marking of papers.

plom.client.randoMarker.build_random_rubrics(question, *, messenger)[source]

Push random rubrics into a server: only for testing/demo purposes

Caution

Do not use on a real production server.

Parameters:

question (int) –

Keyword Arguments:

messenger – a messenger object already connected to the server.

Returns:

None

plom.client.randoMarker.do_rando_marking(server, user, password)[source]

Randomly annotate the papers assigning RANDOM grades: only for testing please.

Caution

Only for testing/demos. Do not use for real tests.

Also, for each paper, with probability 1/3, we tag with up to 3 randomly selected tags.

Parameters:
  • server (str) –

  • user (str) –

  • password (str) –

Returns:

0 on success, non-zero on error/unexpected.

Return type:

int

Random identifying: plom.client.randoIDer

Command-line script

Perform identifier tasks randomly, generally for testing.

usage: python -m plom.client.randoIDer [-h] [-w PASSWORD] [-u USER] [-s SERVER[:PORT]]
options
-w, --password

by default, for the “scanner” user’, also checks the environment variable PLOM_SCAN_PASSWORD.

-u, --user

Override default of “scanner”

-s, --server

Which server to contact, port defaults to 41984. Also checks the environment variable PLOM_SERVER if omitted.

Module docs

Randomly ID papers for testing purposes.

plom.client.randoIDer.do_rando_identifying(server, user, password)[source]

Randomly associate papers with students: only for testing please.

Parameters:
  • server (str) –

  • user (str) –

  • password (str) –

Returns:

0 on success, non-zero on error/unexpected.

Return type:

int

TeX Tools

Tools for working with TeX

plom.textools.buildLaTeX(src, out)[source]

Compile a string of latex.

Parameters:
  • src (str) –

  • out (file-like) – the binary pdf file will be written into this.

Returns:

tuple containing

  • (int): exit value from the subprocess call (zero good, non-zero bad)

  • (str): stdout/stderr from the subprocess call

TODO: this is more generally useful but how to handle the idBox2?

plom.textools.texFragmentToPNG(fragment, *, dpi=225)[source]

Process a fragment of latex and produce a png image.

Parameters:
  • fragment (str) – a string of text to be rendered with LaTeX.

  • dpi (int) – 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