Пример #1
0
def test_pow():
    """Exponentiation of quantities."""
    REGISTRY.clear()
    define_units()
    
    m_unit = unit('m')
    m_quant = Quantity(2, m_unit)
    
    assert (m_quant ** 2 == m_quant * m_quant == pow(m_quant, 2))
    
    cm_unit = unit('cm')
    cm_quant = Quantity(2, cm_unit)
    
    assert within_epsilon(cm_quant ** 2, cm_quant * cm_quant)
    assert within_epsilon(cm_quant ** 2, pow(cm_quant, 2))
Пример #2
0
def can_make(unit_str):
    """True if the given unit string represents an SI unit."""
    if prefixed(unit_str):
        unit = REGISTRY.get(without_prefix(unit_str), None)
        if unit:
            return unit.is_si()
    return False
Пример #3
0
def can_make(unit_str):
    """True if the given unit string represents an SI unit."""
    if prefixed(unit_str):
        unit = REGISTRY.get(without_prefix(unit_str), None)
        if unit:
            return unit.is_si()
    return False
Пример #4
0
def test_pow():
    """Exponentiation of quantities."""
    REGISTRY.clear()
    define_units()

    m_unit = unit('m')
    m_quant = Quantity(2, m_unit)

    assert (m_quant ** 2 ==
            m_quant * m_quant ==
            pow(m_quant, 2))

    cm_unit = unit('cm')
    cm_quant = Quantity(2, cm_unit)

    assert within_epsilon(cm_quant ** 2, cm_quant * cm_quant)
    assert within_epsilon(cm_quant ** 2, pow(cm_quant, 2))
Пример #5
0
def teardown_module(module):
    # Disable warning about not using module.
    # pylint: disable=W0613
    """Called after running all of the tests here."""
    REGISTRY.clear()
Пример #6
0
def teardown_module(module):
    # Disable warning about not using module.
    # pylint: disable=W0613
    """Called after running all of the tests here."""
    REGISTRY.clear()