54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Test the `parse_weight` and `dimensional_weight`"""
|
|
|
|
from helpers.weight import parse_weight, dimensional_weight
|
|
|
|
|
|
def test_parse_weight_none():
|
|
"""Test None value"""
|
|
assert parse_weight(None) is None
|
|
|
|
|
|
def test_parse_weight():
|
|
"""Test one value from the sample file"""
|
|
assert parse_weight("0.65 pounds") == 294.83
|
|
|
|
|
|
def test_parse_weight_only_decimals():
|
|
"""Test a value with only decimals specified"""
|
|
assert parse_weight(".28 pounds") == 127.01
|
|
|
|
|
|
def test_parse_weight_no_decimals():
|
|
"""Test a value without decimals"""
|
|
assert parse_weight("44 pounds") == 19958.05
|
|
|
|
|
|
def test_parse_weight_ounces():
|
|
"""Test a value with ounces"""
|
|
assert parse_weight("0.65 ounces") == 18.43
|
|
|
|
|
|
def test_parse_weight_unrecognized():
|
|
"""Test a value where the unit is not recognized"""
|
|
assert parse_weight("0.65 mg") is None
|
|
|
|
|
|
def test_dimensional_weight():
|
|
"""Test the dimensional weight calculation"""
|
|
assert dimensional_weight(height=1, width=2, depth=3) == 1.2
|
|
|
|
|
|
def test_dimensional_weight_none():
|
|
"""Test the dimensional weight calculation where there may be nones in the
|
|
input"""
|
|
|
|
assert dimensional_weight(height=None, width=2, depth=3) is None
|
|
assert dimensional_weight(height=1, width=None, depth=3) is None
|
|
assert dimensional_weight(height=1, width=2, depth=None) is None
|
|
|
|
assert dimensional_weight(height=None, width=None, depth=3) is None
|
|
assert dimensional_weight(height=1, width=None, depth=None) is None
|
|
assert dimensional_weight(height=None, width=2, depth=None) is None
|
|
|
|
assert dimensional_weight(height=None, width=None, depth=None) is None
|