def testValidUnits(unit_database_empty): # let'scalar clear up the unit manager unit_database = unit_database_empty unit_database.AddUnitBase("length", "meters", "m") unit_database.AddUnit("length", "centimeters", "cm", "%f * 100.0", "%f / 100.0") unit_database.AddUnit("length", "milimeters", "mm", "%f * 1000.0", "%f / 1000.0") unit_database.AddUnit("length", "kilometers", "km", "%f / 1000.0", "%f * 1000.0") unit_database.AddUnit("length", "miles", "mi", "%f / 1609.347", "%f * 1609.347") unit_database.AddUnit("length", "inches", "in", "%f / 0.0254", "%f * 0.0254") valid_units = ["m", "cm", "mm"] unit_database.AddCategory("length", "length") unit_database.AddCategory("well-length", "length", valid_units=valid_units) unit_database.AddCategory("well-diameter", "length") Quantity("well-length", "km") scalar = units.Scalar("well-length", 1, "m") assert valid_units == scalar.GetValidUnits() scalar = units.Scalar("well-diameter", 1, "m") assert ["m", "cm", "mm", "km", "mi", "in"] == scalar.GetValidUnits() # Creating a scalar in a unit that isn't valid shouldn't raise an error and the unit # will be added to valid units scalar = units.Scalar("well-length", 1, "mi") assert scalar.GetValidUnits() == ["m", "cm", "mm", "mi"]
def testQuantity(unit_database_well_length): Quantity("well-length", "m") with pytest.raises(units.InvalidQuantityTypeError): Quantity("foo", "m")