Ejemplo n.º 1
0
def test_get_units():
    a = nplab.ArrayWithAttrs(np.array([1, 2, 3, 4, 5]),
                             attrs={'units': 'um/s'})
    q = units.ureg('um/second')
    assert get_units(a) == units.ureg('um/s')
    assert get_units(q) == units.ureg('um/s')
    assert get_units(10, default='um/s') == units.ureg('um/s')
Ejemplo n.º 2
0
def test_get_unit_string():
    a = nplab.ArrayWithAttrs(np.array([1, 2, 3, 4, 5]),
                             attrs={'units': 'um/s'})
    q = units.ureg('um/second')
    assert get_unit_string(a) == 'um/s'
    assert get_unit_string(q) == 'micrometer / second'
    assert get_unit_string(10, default='foo') == 'foo'
    with pytest.raises(ValueError):
        get_unit_string(10, fail=True)
Ejemplo n.º 3
0
def test_convert_quantity():
    a = nplab.ArrayWithAttrs(np.array(0.1), attrs={'units': 'um'})
    q = units.ureg('0.1 um')
    na = np.array(0.1)
    assert convert_quantity(a, 'nm') == 100
    assert convert_quantity(q, 'nm') == 100
    with pytest.raises(ValueError):
        convert_quantity(na, 'nm')
    assert convert_quantity(na, 'nm', default='um') == 100
    assert convert_quantity(0.1, 'nm', default='um') == 100
Ejemplo n.º 4
0
def test_ensure_unit():
    assert ensure_unit('um/s') == units.ureg('micrometer/second')
    assert isinstance(ensure_unit('um/s'), units.ureg.Quantity)
    assert isinstance(ensure_unit(units.ureg('um/s').units),
                      units.ureg.Quantity)
Ejemplo n.º 5
0
def test_unit_to_string():
    q = units.ureg('7 um/second')
    assert unit_to_string(q) == '7.0 micrometer / second'
Ejemplo n.º 6
0
def test_unit_to_string_unity():
    q = units.ureg('um/second')
    assert unit_to_string(q) == 'micrometer / second'