2022-08-17 11:26:23 +02:00
|
|
|
"""
|
2022-08-25 13:46:19 +02:00
|
|
|
Example Code for a test case for the `README.md` documentation
|
|
|
|
==============================================================
|
|
|
|
|
|
|
|
**Module:** ``tests.test_complex_example``
|
|
|
|
|
|
|
|
This module contains a quite simple, yet complex configured test to show what's possible with the plugin.
|
|
|
|
|
|
|
|
The example uses this CSV data, as found under ``tests/assets/example.csv``:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../../tests/assets/example.csv
|
|
|
|
:language: text
|
|
|
|
|
|
|
|
The test idea here is much the same as the :mod:`tests.test_blog_example` test case.
|
|
|
|
|
|
|
|
Why is such a test case here? That's simple: To make sure, the code samples in the documentation still work as designed.
|
2022-08-17 11:26:23 +02:00
|
|
|
"""
|
2022-08-25 13:46:19 +02:00
|
|
|
|
2022-08-17 11:26:23 +02:00
|
|
|
from math import ceil
|
|
|
|
from os.path import dirname, join
|
|
|
|
|
|
|
|
from pytest_csv_params.decorator import csv_params
|
|
|
|
|
|
|
|
|
|
|
|
@csv_params(
|
|
|
|
data_file="example.csv",
|
|
|
|
base_dir=join(dirname(__file__), "assets"),
|
|
|
|
id_col="Test ID",
|
|
|
|
header_renames={
|
|
|
|
"Bananas shipped": "bananas_shipped",
|
|
|
|
"Single Banana Weight": "banana_weight",
|
|
|
|
"Apples shipped": "apples_shipped",
|
|
|
|
"Single Apple Weight": "apple_weight",
|
|
|
|
"Container Size": "container_size",
|
|
|
|
},
|
|
|
|
data_casts={
|
|
|
|
"bananas_shipped": int,
|
|
|
|
"banana_weight": float,
|
|
|
|
"apples_shipped": int,
|
|
|
|
"apple_weight": float,
|
|
|
|
"container_size": int,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
def test_container_size_is_big_enough(
|
|
|
|
bananas_shipped: int, banana_weight: float, apples_shipped: int, apple_weight: float, container_size: int
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
This is just an example test case for the documentation.
|
2022-08-25 13:46:19 +02:00
|
|
|
|
|
|
|
:param bananas_shipped: How many mananas were shipped?
|
|
|
|
:param banana_weight: What's the weight of one banana?
|
|
|
|
:param apples_shipped: How many apples where shipped?
|
|
|
|
:param apple_weight: What's the weight of one apple?
|
|
|
|
:param container_size: How large was the container?
|
2022-08-17 11:26:23 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
gross_weight = (banana_weight * bananas_shipped) + (apple_weight * apples_shipped)
|
|
|
|
assert ceil(gross_weight) <= container_size
|