Testing framework for Foliant
Project description
Test framework
Foliant test framework is a tool which helps you test your Foliant extensions. It is still under development and right now you can only test preprocessors with it using Preprocessor Test Framework.
Preprocessor Test Framework
Preprocessor Test Framework is a class which allows you to quickly set up simulated environment for preprocessor testing. It runs a specific preprocessor just like Foliant core runs it, and the compares the results with expected results.
Usage
First you need to initialize the framework by passing it a name of preprocessor you want to test. Let's test the includes preprocessor in this example:
>>> from foliant_test.preprocessor import PreprocessorTestFramework
>>> ptf = PreprocessorTestFramework('includes')
Now to test the work of includes we need some source files. Source files are supplied in a mapping. We need to pass the framework both input source files and expected files.
Let's create a basic file structure with just two files, one of which includes the other:
>>> input_files = {
... 'first.md': '# First file\n\n<include src="second.md"></include>',
... 'second.md': 'Second file content'
... }
Now let's create the expected mapping for these two files. What should be their contents after we apply the includes preprocessor?
>>> expected_files = {
... 'first.md': '# First file\n\nSecond file content',
... 'second.md': 'Second file content'
... }
All is left to do is to run the test:
>>> ptf.test_preprocessor(
... input_mapping=input_files,
... expected_mapping=expected_files
... )
If you don't see any output, it means that everything went well and expected results were identical to the factual.
Adding options
To set up your preprocessor options, change the options
attribute of the framework instance.
For example, let's test the work of includes' extensions
option, which allows us to process different file types besides .md
>>> ptf.options = {'extensions': ['md', 'txt']}
>>> input_files = {
... 'first.txt': '# First file\n\n<include src="second.md"></include>',
... 'second.md': 'Second file content'
... }
>>> expected_files = {
... 'first.txt': '# First file\n\nSecond file content',
... 'second.md': 'Second file content'
... }
>>> ptf.test_preprocessor(
... input_mapping=input_files,
... expected_mapping=expected_files
... )
Apart from options you can also change:
config
attribute which represents the virtual foliant.yml
dictionary;
chapters
attribute, which holds the list of chapters,
context
attribute which holds the whole preprocessor context.
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
Built Distribution
Hashes for foliantcontrib.test_framework-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00f169e469bed83350dbb0456f603d2ed24fcd85b9e8bc32c0fdfda6ab11c7e4 |
|
MD5 | b9f51b7f86565ab7486745df8934abe5 |
|
BLAKE2b-256 | 1a86bf017bbc68e10f4ec3b9869c5b72f704d8d2d2bea406598c24c77d8f810b |
Hashes for foliantcontrib.test_framework-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5365260f079a637d8df678ba6265370d407fed934ea5592671d551cf80ece555 |
|
MD5 | 4381fdd4ea8e347e8eac95a776f8fa1c |
|
BLAKE2b-256 | 7a6e8ab75aafc720f8ebb6fe416a9c45ab481e787070a501d3b2734fe06d8111 |