|
| 1 | +import pytest |
| 2 | + |
| 3 | +from pynxtools.units import NXUnitSet |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize( |
| 7 | + "unit_category,unit,expected", |
| 8 | + [ |
| 9 | + ("NX_LENGTH", "meter", True), |
| 10 | + ("NX_LENGTH", "m", True), |
| 11 | + ("NX_LENGTH", "second", False), |
| 12 | + ("NX_TEMPERATURE", "kelvin", True), |
| 13 | + ("NX_TEMPERATURE", "celsius", True), # offset unit |
| 14 | + ("NX_TEMPERATURE", "degC", True), # alias |
| 15 | + ("NX_TEMPERATURE", "second", False), |
| 16 | + ("NX_ANY", "meter", True), |
| 17 | + ("NX_ANY", "", True), # empty allowed |
| 18 | + ("NX_ANY", "foobar", False), # unknown unit not allowed for NX_ANY |
| 19 | + ("NX_LENGTH", "foobar", False), # unknown unit not allowed |
| 20 | + ("NX_LENGTH", "pixel", True), # pixel is accepted as length |
| 21 | + ("NX_DIMENSIONLESS", "", True), |
| 22 | + ("NX_DIMENSIONLESS", "meter", False), |
| 23 | + ("NX_UNITLESS", "", True), |
| 24 | + ("NX_UNITLESS", "meter", False), |
| 25 | + ], |
| 26 | +) |
| 27 | +def test_matches(unit_category, unit, expected): |
| 28 | + assert NXUnitSet.matches(unit_category, unit) == expected |
0 commit comments