Exemplo n.º 1
0
    def test_megaohm_parsing(self):
        unit_reg = UnitRegistry()
        expected_unit = unit_reg.megaohm

        input_str = u'MΩ'
        output_str, found_unit = parse_units_from_str(input_str)
        self.assertEqual(found_unit, expected_unit)
Exemplo n.º 2
0
    def test_weird_unit_parsing(self):
        unit_reg = UnitRegistry()
        expected_unit = unit_reg.megaohm

        input_str = u'mV ms\u22121'
        found_unit = parse_units_from_str(input_str)
        self.assertIsNone(found_unit)
Exemplo n.º 3
0
    def test_millivolt_parsing(self):
        unit_reg = UnitRegistry()
        expected_unit = unit_reg.millivolt

        input_str = 'mV'
        output_str, found_unit = parse_units_from_str(input_str)
        self.assertEqual(found_unit, expected_unit)
def get_units_from_table_header(header_str):
    (a, parens_str, comma_str) = resolve_table_header(header_str)
    if parens_str:
        matched_units = parse_units_from_str(parens_str)
        if matched_units:
            return parens_str
    elif comma_str:
        matched_units = parse_units_from_str(comma_str)
        if matched_units:
            return comma_str
    else:
        # split header using whitespace and check if any are units
        for e in reversed(a.split()):
            matched_units = parse_units_from_str(e)
            if matched_units:
                return e
    return None