def fix_unit(db, varname): res = reg_varunit.match(varname) if res: vname, unit = res.groups() mul, unit = unit_to_multiplier(unit) # db.rename(varname, vname) if varname in db.ivardata: olddim = db.ivardata[varname] newdim = olddim.__class__(olddim, name=vname, data=olddim.data * mul, unit=unit) db.replace_dim(olddim, newdim) else: db.rename(varname, vname) db[vname] = db[vname] * mul db[vname].unit = unit
def test_4(self): self.assertEqual(unit_to_multiplier("#"), (1, None))
def test_3(self): self.assertEqual(unit_to_multiplier("%"), (.01, None))
def test_2(self): self.assertEqual(unit_to_multiplier("mXYZ"), (1, "mXYZ"))
def test_1(self): self.assertEqual(unit_to_multiplier("s"), (1, "s"))