Additional Example Cases

This commit is contained in:
Jürgen Edelbluth 2022-08-17 13:10:24 +02:00
parent 45abe33d7f
commit f370ac7ce2
Signed by: jed
GPG Key ID: 6DEAEDD5CDB646DF
3 changed files with 62 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-csv-params"
version = "0.3.2"
version = "0.3.3"
description = "Pytest plugin for Test Case Parametrization with CSV files"
authors = ["Juergen Edelbluth <csv_params@jued.de>"]
license = "MIT"

View File

@ -0,0 +1,4 @@
"Order-Ref #", "Anz. Schrauben-Päck.", "Dim. Schrauben-Päck.", "Anz. Scheiben-Päck.", "Dim. Scheiben-Päck.", "Volumen Container"
"221-12-A-24", "670", "30 x 50 x 70 mm", "150", "40 x 50 x 70 mm", "1 m³"
"281-13-C-15", "5000", "30 x 50 x 70 mm", "10000", "40 x 50 x 70 mm", "5 m³"
"281-13-C-76", "50000", "35 x 55 x 75 mm", "5000", "50 x 60 x 90 mm", "10 m³"
1 Order-Ref # Anz. Schrauben-Päck. Dim. Schrauben-Päck. Anz. Scheiben-Päck. Dim. Scheiben-Päck. Volumen Container
2 221-12-A-24 670 30 x 50 x 70 mm 150 40 x 50 x 70 mm 1 m³
3 281-13-C-15 5000 30 x 50 x 70 mm 10000 40 x 50 x 70 mm 5 m³
4 281-13-C-76 50000 35 x 55 x 75 mm 5000 50 x 60 x 90 mm 10 m³

View File

@ -0,0 +1,57 @@
"""
This is a test example for a blog post
"""
import re
from math import ceil
from os.path import join, dirname
from pytest_csv_params.decorator import csv_params
def get_volume(size_data: str) -> int:
"""
Get the volume from size data, return it as mm³
"""
matcher = re.compile(r"^\D*(?P<l>\d+)\D+(?P<d>\d+)\D+(?P<h>\d+)\D+$").match(size_data)
return int(matcher.group("l")) * int(matcher.group("d")) * int(matcher.group("h"))
def get_container_volume(container_size: str) -> int:
"""
Get the container size (remove the unit, as mm³)
"""
matcher = re.compile(r"^\D*(?P<size>\d+)\D+$").match(container_size)
return int(matcher.group("size")) * 1_000_000_000
@csv_params(
data_file=join(dirname(__file__), "assets", "blog-example.csv"),
id_col="Order-Ref #",
header_renames={
"Anz. Schrauben-Päck.": "anz_schrauben",
"Dim. Schrauben-Päck.": "vol_schrauben",
"Anz. Scheiben-Päck.": "anz_scheiben",
"Dim. Scheiben-Päck.": "vol_scheiben",
"Volumen Container": "vol_container",
},
data_casts={
"anz_schrauben": int,
"anz_scheiben": int,
"vol_schrauben": get_volume,
"vol_scheiben": get_volume,
"vol_container": get_container_volume,
},
)
def test_does_it_fit(anz_schrauben: int, vol_schrauben: int, anz_scheiben: int, vol_scheiben: int, vol_container: int) -> None:
"""
Simple test to see if all fits in an container
"""
available_container_sizes = map(lambda x: x * 1_000_000_000, [1, 5, 10])
size_required = (anz_schrauben * vol_schrauben) + (anz_scheiben * vol_scheiben)
# Smallest possible Container ordered?
smallest_possible_container = min(filter(lambda x: x >= size_required, available_container_sizes))
assert vol_container == smallest_possible_container