API Reference

Main

exam_generator.main.bootstrap_app()[source]
exam_generator.main.exam_generator(args)[source]

Main function which combines all modules of this program.

Parameters
  • args.create_test – Would the user like to create a test

  • args.make_all – Would the user like to create a preview for all problems

  • args.make_pool – Pool which the user would like to create a preview for

  • args.make_specific – Name of the problem the user would like to create a preview for

exam_generator.main.main()[source]

Calls parser and delivers arguments to exam_generator.

Classes

This module contains all classes relevant for the exam-generator.

class exam_generator.classes.Pool(name, pool_files)[source]

Bases: object

Represents each pool with its corresponding problems.

Construction:

>>> Pool(name, file_names_tex)
Parameters
  • name (str) – Name of the pool for example: A1, CV21, DV07

  • pool_files (list[str]) – All Problem-Solution-file names of the pool

discard()[source]

Discards all pulled problems to the discard pile

pull()[source]

Pulls a random problem + solution from the pool

Returns

prob_sol

Return type

tuple(str, str)

class exam_generator.classes.TestType(name, *pools)[source]

Bases: object

Represents all different test types

Construction:

>>> TestType(name, *pools)
Parameters
  • name (str) – Name of the test type, for example the name of Experiment

  • pools (list[pool]) – Pools belonging to the test type, mind the “*”

Functions

This module contains all functions relevant for the exam-generator.

exam_generator.funcs.apply_jinja_template(latex_directory, file)[source]

Applies jinja template to a file.

Parameters
  • latex_directory (str) – directory where template lives

  • file (str) – name of file

exam_generator.funcs.build_sumo(directory, sumo_name, pdf_list, pages_per_sheet, copies_per_file)[source]

This function creates the sumo file which contains all problems/ solutions for all groups.

Parameters
  • directory – Directory where to be combined problems lie

  • sumo_name (str) – Name of the Sumo file either for the problems or solutions

  • pdf_list (list[str]) – List of the names of the created PDF problem/ solution files

  • pages_per_sheet (int) – How many different pages there should be displayed on one page/ sheet

  • kopien_pro_blatt (int) – How many copies you would like for each problem/ solution

Creates:

  • pdf file sumo_name.pdf

exam_generator.funcs.check_directory(root_directory) bool[source]

Checks if required directories exists.

Returns

False=not all exist, True= all exist

Return type

bool

exam_generator.funcs.check_settings(settings, settings_file)[source]

Checks the json settings file for user input errors.

Parameters
  • settings (Dict from addict) – settings input from user.

  • settings_file (str) – name of the used settings file.

exam_generator.funcs.combine_file_names(pool_files)[source]

Combines the problems of all individual pools into one.

Parameters

pool_files (list[tuple(list[str], str)]) – problem/ solution names, name of corresponding pool

Returns

names of all problems/ solutions

Return type

list[str]

exam_generator.funcs.combine_group_files(test_directory, latex_directory, groups, test_list_variant, variant_name, exam_format, solution_format)[source]

Combines the separate group pdf files into one file and moves it to the test directory.

Parameters
  • test_directory (str) – directory where generated exam is stored

  • latex_directory (str) – directory of latex compiler

  • groups (int) – number of different groups

  • test_list_variant (list[TestType]) – List of test variants belonging to chosen variant

  • variant_name (str) – name of the variant

exam_generator.funcs.combining_problems(number_group_pairs, test_list_variant)[source]

For each group this function adds to a list which contains problems and their according solutions from given pools depending on the test variant.

Parameters
  • number_group_pairs (int) – Number of groups

  • test_list_variant (list[TestType]) – List of test variants belonging to chosen variant

Returns

tests_per_group - problems/ solutions for each group

Return type

list[list[list[tuple(str, str, str)]]]

exam_generator.funcs.compile(test_directory, latex_directory, delete_temp_data)[source]

This function compiles the tex files and turns them into pdf format and moves them to the test directory. Lastly, it deletes temporary data.

Parameters
  • test_directory (str) – Directory where the generated tests are saved

  • latex_directory (str) – Working directory of latex compiler

  • delete_temp_data (bool) – Should temporary data be deleted

exam_generator.funcs.create_custom_test_list(test_types_dictionary, pool_info)[source]

Creates custom test list out of json dictionary.

Parameters
  • test_types_dictionary (dict) – json dict loaded into Python format

  • pool_info (list[tuple(list[str], str)]) – pool files, pool name

Returns

list of custom tests

Return type

list[TestType]

exam_generator.funcs.create_file_content(template, title, semester, test_typ, group_name, tests_per_group, group, test_index, prob_sol_index, student, test)[source]

Replaces template variables and adds problem string.

Parameters
  • template (str) – file content of template

  • title (str) – title of exam

  • semester (str) – semester

  • test_typ (TestType) – test type out of test list

  • group_name (str) – name of group

  • test_index (int) – index of test in test_list_variant

  • prob_sol_index (int) – determines compilation for prob[0]/ sol[1]

  • student (int) – number of student

  • test (str) – name of test

Returns

file content

Return type

str

exam_generator.funcs.create_problem_content(tests_per_group, group, test_index, prob_sol_index, student, test)[source]

Combines problem files, replaces KEYs and applies jinja templates.

Parameters
  • tests_per_group (int) – number of tests per group

  • group (str) – name of group

  • test_index (int) – index of test in test_list_variant

  • prob_sol_index (int) – determines compilation for prob[0]/ sol[1]

  • student (int) – number of student

  • test (str) – name of test

Returns

2-element tuple: string consisting of all problems for a student and a string the graphicspath

Return type

(str, str)

exam_generator.funcs.curly_braces_wrapper(arg: str)[source]

Return a string like “{” + arg + “}”.

Motivation: the templating engine uses curly braces as variable-section delimiter. Also, TeX syntax uses curly braces on many occassion. This makes it hard to denote e.g.

` \emph{XYZ} `

where XYZ should be an expression like {{contex.myvariable}}. The following results in an error of the templating engine:

` \emph{{{contex.myvariable}}} `

With this function one can use:

emph{{cbw(context[“myvariable”])}}

exam_generator.funcs.delete_command(filename=None)[source]

Deletes temporary data with commands based on OS.

Parameters

filename (str) – Specific name to be deleted. Defaulted to None

exam_generator.funcs.delete_pdf(filename)[source]

Deletes a pdf file based on os.

Parameters

filename (str) – name of the file to be deleted.

exam_generator.funcs.determine_copies_per_group(number_groups, copies)[source]

Calculates copies per group

Parameters
  • number_groups (int) – group count

  • copies (int) – number of total copies

Returns

number of copies for each group

Return type

int

exam_generator.funcs.generate_keys(file_content: str, test, group, student)[source]

Searches for all variants of __KEY{int}__ and adds them with a uniquely generated key to dict.

Parameters
  • file_content (str) – content of working file

  • test (str) – name of test

  • group (str) – group name

  • student (str) – number of student

Returns

old key -> unique key

Return type

dict{str: str}

exam_generator.funcs.generate_tex_files(latex_directory, template_directory, number_group_pairs, test_list_variant, variant_name, title, semester, tests_per_group, copies_per_group)[source]

This function replaces the variables within the tex problem/ solution files with the information given by the settings.

Parameters
  • latex_directory (str) – Directory for the latex compiler

  • template_directory (int) – Directory of the problem/ solution templates

  • number_group_pairs (int) – Number of groups

  • test_list_variant (list[TestType]) – List of test variants belonging to chosen variant

  • variant_name (str) – Name of the test variant

  • title (str) – Title of the event. Dependent on name_variant

  • semester (str) – Given semester in json settings file

  • tests_per_group (list[str]) – List of problems/ solutions for each group

exam_generator.funcs.get_random_number(key: str, lower_bound=1, upper_bound=10)[source]

Return a number from the CACHE or key is yet unknown, randomly create a new one.

Parameters
  • key (str) – key to uniquely identify this number for later usages, e.g. in the solution

  • lower_bound (int) – lower bound

  • upper_bound (int) – upper bound

Returns

random number

Return type

int

exam_generator.funcs.initialize_random_number_generator(seed=None)[source]

Initializes random seed.

Parameters

seed (int) – int or float; Seed for random number generator. Default: None (use system clock).

exam_generator.funcs.make_specific(make_all, pool_path, problem_path, root_directory)[source]

This Function creates previews for given pools/ problems or all.

Parameters
  • make_all (bool) – Make a preview for all problems

  • pool (str) – Name of the pool to be created

Problem

File name of the problem to be created

exam_generator.funcs.preview_parameterization(root_directory, filenames_problems)[source]

Applies parameterization to preview files.

Parameters
  • root_directory (str) – path of root directory

  • filenames_problems (list[str]) – path to problem files

Returns

filenames_problems - temp path to parameterized problems

Return type

list[str]

exam_generator.funcs.pull_pool_data(latex_directory)[source]

Sets pool directories and its problem data.

Parameters

latex_directory (str) – working directory of latex compiler

Returns

problem/ solution names, name of corresponding pool

Return type

list[tuple(list[str], str)]

exam_generator.funcs.replace_keys(file_content: str, test=0, group=0, student=0)[source]

Replaces __KEY{int}__ in latex files with custom keys for later usage.

Parameters
  • file_content – content of file to be edited

  • test (str) – name of test

  • group (str) – group name

  • student (int) – number of student

Returns

file content with replaced keys

Return type

str

Custom Errors

exception exam_generator.customExceptions.CompilingError(info, extra_info=None)[source]

Bases: Exception

Error raised when there is a problem during the compiling process.

Parameters
  • info (func) – errorInfo()

  • file (str. Defaulted to None) – name of file where compiling failed

exception exam_generator.customExceptions.MissingDirectoryError(info, directory=None)[source]

Bases: Exception

Error raised when a needed directory is missing.

Parameters
  • info (func) – errorInfo()

  • directory (str. Default None.) – missing directory

exception exam_generator.customExceptions.MissingFileError(info, file=None)[source]

Bases: Exception

Error raised when a needed file is missing.

Parameters
  • info (func) – errorInfo()

  • file (str) – missing file name

exception exam_generator.customExceptions.PoolError[source]

Bases: Exception

Error raised when something went wrong during pool creation

Parameters
  • pool (str) – errorInfo()

  • pool – name of the affected pool

exception exam_generator.customExceptions.SettingsError(info, settings_file=None)[source]

Bases: Exception

Error raised when there is a problem with user input.

Parameters
  • info (func) – errorInfo()

  • settings_file (str) – name of settings file

exam_generator.customExceptions.errorInfo()[source]

Gives information about the origin of the raised error.

Returns

Line of error + file

Return type

str