Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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))
Exemplo n.º 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()
Exemplo n.º 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()