Skip to main content

Build simple tests to validate functions prints and outputs with configurable args, kwargs and simulated user inputs

Project description

didatictests

Build Status Documentation Code Coverage


Features

  • Run functions with preconfigured simulated keyboard inputs

  • Build simple tests to validate functions prints and outputs with configurable args, kwargs and simulated user inputs

Quick Start

from didatictests import Didatic_test as Dt

Demo function: the_function(arg):

  • receives 1 argument arg
  • receives 1 user input inp
  • calculates total = arg + int(inp)
  • prints total
  • return total
def the_function(arg):
  inp = input("One number, please: ")
  total = arg + int(inp)
  print(total)
  return total

Create and run some tests:


Test-1

test1 = Dt(
  fn = the_function,
  args = Dt.parse_args(40),
  keyboard_inputs = ('2'),
  test_name = 'This one shall pass!',
  expected_output = 42,
  expected_prints = '42\n',
  run_prints_test = True,
  run_output_test = True,
  verbose=True
)

test1.run()
  • print:
Case: This one shall pass!
[I]: One number, please:  2
[P]: 42

outputs: ✔️  prints: ✔️                
---------------------------------------------------
  • return:
{'output_is_correct': True, 'print_is_correct': True, 'test_failed': False, 'test_done': True}

Test-2

test2 = Dt(
  fn = the_function,
  args = Dt.parse_args(40),
  keyboard_inputs = ('2'),
  test_name = 'You Shall Not Pass!!!',
  expected_output = 42,
  expected_prints = '13\n',
  run_prints_test = True,
  run_output_test = True,
  verbose=True
)

test2.run()
  • print:
Case: You Shall Not Pass!!!
[I]: One number, please:  2
[P]: 42

outputs: ✔️  prints: ❌                
   ➖ Function args:      (40,) {}
   ➖ Keyboard inputs:    ('2',)
   ✔️ Function outputs:   42                  
   ➖ Expected output:    42
   ❌ fn internal prints: 42
   ➖ Expected prints:    13
---------------------------------------------------
  • return:
{'output_is_correct': True, 'print_is_correct': False, 'test_failed': False, 'test_done': True}

Test-3

test3 = Dt(
  fn = the_function,
  args = Dt.parse_args('forty'),
  keyboard_inputs = ('two'),
  test_name = 'Error demo',
  expected_output = 42,
  expected_prints = '42\n',
  run_prints_test = True,
  run_output_test = True,
  verbose=True
)

test3.run()
  • print:
Case: Error demo
🚨⚠️🚨⚠️🚨 Error! 💀💀💀
<class 'ValueError'>
("invalid literal for int() with base 10: 'two'",)
invalid literal for int() with base 10: 'two'
[I]: One number, please:  two

---------------------------------------------------
  • return:
{'output_is_correct': False, 'print_is_correct': False, 'test_failed': True, 'test_done': False}

Installation

Stable Release: pip install didatictests
Development Head: pip install git+https://github.com/lmkawakami/didatictests.git

Documentation

For full package documentation please visit lmkawakami.github.io/didatictests.

Development

See CONTRIBUTING.md for information related to developing the code. MIT license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

didatictests-0.0.7.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

didatictests-0.0.7-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file didatictests-0.0.7.tar.gz.

File metadata

  • Download URL: didatictests-0.0.7.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for didatictests-0.0.7.tar.gz
Algorithm Hash digest
SHA256 92af7481d57d57544622a1476663d67a32fa97504c9b0e2e4802fd99b1a80fe2
MD5 0c2602da2850dced8fcf3729e314b541
BLAKE2b-256 8b66c9c769267ded84f2b10b4bfcbb923c12e48ad33c952145245246d5a22019

See more details on using hashes here.

File details

Details for the file didatictests-0.0.7-py2.py3-none-any.whl.

File metadata

  • Download URL: didatictests-0.0.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for didatictests-0.0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2762e1a8d612660668dbd4b3096a791938ebb13b91c0e96040e3de3b68291bb4
MD5 2820d8f76c723aa5865e1e667c74160a
BLAKE2b-256 60c3d85f2fc0174934ca6ceeda5d3c39c1e95e7e8682914fe923e00ee37a08fe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page