Dialogue class for testing REPLs
Project description
The Dialogue class
The Dialogue class helps testing REPLs (interactive interpreters with a Read-Eval-Print-Loop).
Given a multi-line interactive session transcript, a Dialogue instance emulates user interactions by offering a fake_input method which can replace the input built-in function in Python 3.
How to use
You can code your REPL function to accept an input function as an optional argument, or you can monkey patch Python's input built-in. Either way, you replace the standard input with the fake_input method bound to a Dialogue instance. Each time it is invoked, this method will print the next prompt and fake user input from the session transcript, then return the same user input string to the REPL for processing.
The Dialogue.session instance attribute holds a multi-line string with all the prompts, user inputs and the outputs expected from the REPL under test. This is used to assert the test case.
See the dialogue_test.py module for two simple REPLs that exercise the Dialogue class.
Note: the
.sessionattribute is normalized with thedialogue.normalize()function. Use that function to normalize the output captured by your testing framework as well. This normalization removes trailing whitespace from each line, preserving only the newlines separating them, and also removes leading and trailing whitespace from the session as a whole. This avoids many issues with linters and IDEs complaining about trailing whitespace, and also makes it easier to edit the session examples in tests. See the tests in this package for use ofnormalizein test assertions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dialogue_tester-1.0b5.tar.gz.
File metadata
- Download URL: dialogue_tester-1.0b5.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c99ebca70d9ec273131ceb7e4687ef8c0b9d8930c8b69ad60d73a30ddc7733d
|
|
| MD5 |
a13d45aa69d882d3320b24f4ef3552e8
|
|
| BLAKE2b-256 |
9e0e4de6cc3aaee16056e746731bbcb3810f17b7b26234ee70734718b282ae9d
|
File details
Details for the file dialogue_tester-1.0b5-py3-none-any.whl.
File metadata
- Download URL: dialogue_tester-1.0b5-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bb3597bba6aa298e40c4844dda7838342cf2ac70312eb2bf3d0f94033af3f53
|
|
| MD5 |
822c23409209da8fa7256c175cb117c6
|
|
| BLAKE2b-256 |
5b4e61726984c2bce4ee90892b6a4be551c34c011d23a33832d647374580ab54
|