def test_convert_R_unit_string(self): r"""Test convert_R_unit_string.""" pairs = [('g', 'g'), ('g2', '(g**2)'), ('g2 km s-2', '(g**2)*km*(s**-2)'), ('degC d', 'degC*d'), (tools.bytes2str(b'\xc2\xb0C d'), tools.bytes2str(b'\xc2\xb0C*d')), ('h', 'hr'), ('hrs/kg', 'hr/kg'), ('', ''), ('cm**(-2)', '(cm**-2)')] for x, y in pairs: self.assert_equal(units.convert_R_unit_string(x), y) self.assert_equal(units.convert_R_unit_string(y), y) units.add_units(1.0, x)
def parse_units(cls, x): r"""Parse units. Args: x (str): Unit string. Returns: str: Propertly formatted units. """ replacements = { "kg N": "kg", "kg P": "kg", "kg-1 dry biomass": "kg-1", "kg CH2O": "kg", "days": "d", "cel": "degC" } for k, v in replacements.items(): x = x.replace(k, v) if x == '-': x = "" out = units.convert_R_unit_string(x) return out
def test_convert_R_unit_string(self): r"""Test convert_R_unit_string.""" pairs = [('g', 'g'), ('g2', 'g**2'), ('g2 km s-2', 'g**2 km s**-2')] for x, y in pairs: self.assert_equal(units.convert_R_unit_string(x), y)