38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""Test the `parse_materials` function and its helpers"""
|
|
|
|
from helpers.materials import parse_materials, clean_material_name, material_classifier
|
|
|
|
|
|
def test_none():
|
|
"""Test None value"""
|
|
assert parse_materials(None) is None
|
|
|
|
|
|
def test_amounts():
|
|
"""Test a materials string containing amounts"""
|
|
assert parse_materials(" 83% Recycled Polyester, 17% Spandex") == ["fabric"]
|
|
assert clean_material_name(" 83% Recycled Polyester") == "recycled polyester"
|
|
assert material_classifier("recycled polyester") == "fabric"
|
|
|
|
|
|
def test_annotations():
|
|
"""Test a materials string containing annotations between parentheses"""
|
|
assert parse_materials(" Cardboard (Frame)") == ["cardboard"]
|
|
assert clean_material_name(" Cardboard (Frame)") == "cardboard"
|
|
assert material_classifier("cardboard") == "cardboard"
|
|
|
|
|
|
def test_keyword():
|
|
"""Test a string where the material is a word inside the string"""
|
|
assert parse_materials(" Walnut Wood (Frame)") == ["wood"]
|
|
assert clean_material_name("walnut wood") == "walnut wood"
|
|
assert material_classifier("walnut wood") == "wood"
|
|
|
|
|
|
def test_multiple_materials():
|
|
"""Test a string with two different materials"""
|
|
assert parse_materials(" MDF (Medium-Density Fiberboard), Metal (Frame)") == [
|
|
"metal",
|
|
"wood",
|
|
]
|