didatictests package

Subpackages

Submodules

didatictests.didatictests module

class didatictests.didatictests.Didatic_test(fn=None, args={}, test_name='Test', keyboard_inputs=[], expected_output=None, expected_prints='', verbose=None, run_output_test=None, run_prints_test=None)[source]

Bases: object

A class to configure and run simple didatic tests

Didatic_test(Callable=None, args={}, test_name=None, keyboard_inputs=(), expected_output=None, expected_prints=””, verbose=None, run_output_test=None, run_prints_test=None, )

Parameters
  • fn (Callable) – The function that will be tested

  • args (dict) – The arguments that fn will be tested with. Use parse() to generate args, ex.: args = parse(‘a’,5,7, x=1, s=’aaa’)

  • test_name (str) – An optional identifier that will be printed with the test result

  • keyboard_inputs (Tuple[str, …]) – A tuple containig all the simulated keyboards inputs that will be used in every fn’s input()

  • expected_output (Any) – What the fn’s return value should be

  • expected_prints (str) – What the fn’s internal print()’s concatenation should be (including new line character)

  • verbose (bool) – Controls if all the fn’s internal print()’s and input()’s prompts are printed

  • run_output_test (bool) – Controls if the fn’s return value is checked

  • run_prints_test (bool) – Controls if the fn’s internal print()’s are checked

static auto_redefine(fn, verbose=False)[source]

Run fn normally once and save all the inputs, then return a redefined fn that reuses the same user inputs (simulated) The args and kwarks continue to work normally

ex.: open_menu = auto_redefine(open_menu)

Parameters
  • fn (The function that will be called with intercepted inputs)

  • verbose (flag that controls if the inputs primpts will be printed)

Returns

auto_redefined

Return type

Return a new function that will always use the same keyboard inputs as typed on the first run

fn = None
static generate_test(fn, args, test_name='Test', verbose=False, run_output_test=True, run_prints_test=False, generator_verbose=False)[source]

Run the function once using ther given ‘args’ and intercepts all the inpus, prints and outpus Generate and return the string to create the test with the given configs. and the intercepted infos.

ex.: generate_test(fn, Didatic_test.parse_args(1,2,3), “Test-5”, True, True)

Parameters

fn (The function that will be tested)

args: dict in the format {“pos_inputs”: args, “key_inputs”: kwargs} test_name: test name to identify the results and hint the type of test verbose: controls if the fn’s internal inputs and prints will be printed run_output_test: controls if the output of the test run will be checked against the expected output value run_prints_test: controls if the prints of the test run will be checked against the expected prints generator_verbose: controls if the fn’s internal inputs and prints will be printed in the fist run (the interception run)

Returns

constructor_str

Return type

Return the string with the test constuctor containing all the configurations and args predefined, and with the intecepted inputs, prints and outputs as the expected values

static intercepted_fn(fn, interceptions, verbose=False, input_identifier='', print_identifier='')[source]
just_run()[source]

Run the configured Didatic_test, print the result and returns a dictionary with the test outcome

{

“output_is_correct”: bool, “print_is_correct”: bool, “test_failed”: bool, “test_done”: bool,

}

static parse_args(args, kwargs)[source]

Auxiliar function to pass fn’s args and kwargs like in a normal fn call Just passs the positional args first and then key arguments

ex.: parse_args(1,2,3,x=15,y=[0,0,1],z=’aa’)

Parameters
  • args (The positional arguments of fn)

  • kwargs (The key arguments of fn)

Returns

values

Return type

dict with 2 keys: ‘pos_inputs’ and ‘key_inputs’

static redefine(fn, keyboard_inputs, verbose=False)[source]

Return a new function that will use the ‘keyboard_inputs’ tuple as simulated inputs, but will work as fn otherwise

ex.: call_menu = redefine(call_menu,(‘lorem ipsum’,’25’,’y’,’n’))

Parameters
  • fn (The function that will be copied but will use the simulated inputs)

  • keyboard_inputs (The inputs that will be simulated)

Returns

refedined_fn

Return type

Return a fn copy that will always use the ‘keyboard_inputs’ as input simulation

run()[source]

Run the configured Didatic_test, print the result and returns a dictionary with the test outcome

{

“output_is_correct”: bool, “print_is_correct”: bool, “test_failed”: bool, “test_done”: bool,

}

run_output_test = True
run_prints_test = False
static run_tests(tests)[source]

Run all the tests in the ‘tests’ list

Parameters

tests (list[Didatic_test]) – A list of tests that you want to execute

static set_defaults(fn=None, verbose=None, run_output_test=None, run_prints_test None)[source]

Set common default values fot the tests configs to avoid repetition when setting them up later

Parameters
  • fn (Callable) – The function that will be tested

  • verbose (bool) – Controls if all the fn’s internal print()’s and input()’s prompts are printed

  • run_output_test (bool) – Controls if the fn’s return value is checked

  • run_prints_test (bool) – Controls if the fn’s internal print()’s are checked

static set_generator_defaults(fn=None, verbose=None, run_output_test=None, run_prints_test=None, generator_verbose=None)[source]

Set common default values fot the test generator to avoid unnecessary repetition

Parameters
  • fn (Callable) – The function that will be tested

  • verbose (bool) – Controls if all the fn’s internal print()’s and input()’s prompts are printed when a test runs

  • run_output_test (bool) – Controls if the fn’s return value is tested

  • run_prints_test (bool) – Controls if the fn’s internal print()’s are tested

  • generator_verbose (bool) – Controls if all the fn’s internal print()’s and input()’s prompts are printed on the test generator run

verbose = False

didatictests.example module

class didatictests.example.Example(init_value: int = 10)[source]

Bases: object

This is an example object. Use this example for ideas on how to write doc strings, use logging, construct objects. This is not an exhaustive example but a decent start.

Parameters

init_value (int) – An integer value to initialize the object with.

get_previous_value() int[source]

Get the previous value.

Returns

previous_value – The previous value stored in the object.

Return type

int

get_value() int[source]

Get the current value.

Returns

current_value – The current value stored in the object.

Return type

int

update_value(new_value: int) int[source]

Save old value and set new value.

Parameters

new_value (int) – The new value to assign to the object.

Returns

old_value – The previous value stored in the object.

Return type

int

property values: Tuple[int]

Get both values stored in the object as a tuple of integers.

Returns

values – The current and old values stored in a tuple in (current_value, old_value) order.

Return type

Tuple[int]

Module contents

Top-level package for didatictests.

didatictests.get_module_version()[source]