How to use the barril.units.FractionScalar function in barril

To help you get started, we’ve selected a few barril examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def Create(number, fraction):
        return units.FractionScalar("length", value=FractionValue(number, fraction), unit="m")
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testEquality():
    def Create(number, fraction):
        return units.FractionScalar("length", value=FractionValue(number, fraction), unit="m")

    assert Create(250, (3, 4)) == Create(250, (3, 4))
    assert not Create(250, (3, 4)) != Create(250, (3, 4))

    assert Create(100, (3, 4)) != Create(250, (3, 4))
    assert not Create(100, (3, 4)) == Create(250, (3, 4))

    a = units.FractionScalar("length", value=1.0, unit="m")
    b = units.FractionScalar("length", value=2.0, unit="m")
    c = units.FractionScalar("length", value=1.0, unit="in")
    d = units.FractionScalar("depth", value=1.0, unit="m")
    e = None
    f = units.FractionScalar("length", value=1.0, unit="m")

    assert a != b
    assert a != c
    assert a != e
    assert a != d

    assert a == f
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testFormatValue():
    f = units.FractionScalar("length", value=FractionValue(250.0, (3, 4)), unit="m")
    assert f.GetFormattedValue() == "250 3/4"
github ESSS / barril / src / barril / units / _tests / test_unit_system_manager.py View on Github external
def testUnitSystemManager(unit_manager, units_mapping_1, units_mapping_2, units_mapping_3):
    CreateUnitSystemTemplate(unit_manager)
    unit_manager.AddUnitSystem("system1", "system1", units_mapping_1, False)
    unit_manager.AddUnitSystem("system2", "system2", units_mapping_2, False)

    with pytest.raises(UnitSystemIDError):
        unit_manager.AddUnitSystem("system1", "system3", units_mapping_3, False)

    with pytest.raises(UnitSystemCategoriesError):
        unit_manager.AddUnitSystem("system3", "system3", units_mapping_3, False)

    scalar = Scalar("length", unit="cm")
    array = Array("length", unit="cm")
    fixed_array = FixedArray(3, "length", unit="cm")
    fraction_scalar = FractionScalar("length")

    unit_systems = unit_manager.GetUnitSystems()
    system1 = unit_systems["system1"]
    system2 = unit_systems["system2"]

    unit_manager.current = system1
    assert unit_manager.GetUnitSystemById("system1") is system1
    assert unit_manager.GetUnitSystemById("system2") is system2

    # make sure the unit system manager is not holding a strong ref to its objects
    scalar_ref = weakref.ref(scalar)
    array_ref = weakref.ref(array)
    fixed_array_ref = weakref.ref(fixed_array)
    fraction_scalar_ref = weakref.ref(fraction_scalar)

    del scalar
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testComparison():

    f1 = units.FractionScalar("length", value=FractionValue(10), unit="in")
    f3 = units.FractionScalar("volume", value=FractionValue(4), unit="m3")
    with pytest.raises(TypeError):
        f1 < f3

    f2 = units.FractionScalar("length", unit="in")
    f1 = f1.CreateCopy(value=FractionValue(250, (1, 2)), unit="m")
    f2 = f2.CreateCopy(value=FractionValue(220, (3, 4)), unit="m")

    assert f1 > f2
    assert f2 < f1
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testEquality():
    def Create(number, fraction):
        return units.FractionScalar("length", value=FractionValue(number, fraction), unit="m")

    assert Create(250, (3, 4)) == Create(250, (3, 4))
    assert not Create(250, (3, 4)) != Create(250, (3, 4))

    assert Create(100, (3, 4)) != Create(250, (3, 4))
    assert not Create(100, (3, 4)) == Create(250, (3, 4))

    a = units.FractionScalar("length", value=1.0, unit="m")
    b = units.FractionScalar("length", value=2.0, unit="m")
    c = units.FractionScalar("length", value=1.0, unit="in")
    d = units.FractionScalar("depth", value=1.0, unit="m")
    e = None
    f = units.FractionScalar("length", value=1.0, unit="m")

    assert a != b
    assert a != c
    assert a != e
    assert a != d

    assert a == f
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testComparison():

    f1 = units.FractionScalar("length", value=FractionValue(10), unit="in")
    f3 = units.FractionScalar("volume", value=FractionValue(4), unit="m3")
    with pytest.raises(TypeError):
        f1 < f3

    f2 = units.FractionScalar("length", unit="in")
    f1 = f1.CreateCopy(value=FractionValue(250, (1, 2)), unit="m")
    f2 = f2.CreateCopy(value=FractionValue(220, (3, 4)), unit="m")

    assert f1 > f2
    assert f2 < f1
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testFractionScalar():
    # create our scalar
    f = units.FractionScalar("length", value=FractionValue(250, (3, 4)), unit="m")

    # check formatting
    assert f.GetFormatted() == "250 3/4 [m]"

    # check conversion
    # f.unit = 'km'
    assert f.GetValue("km") == FractionValue(0.25, (3 / 1000.0, 4))
    assert f.GetValue("m") == FractionValue(250.0, (3, 4))

    # test no fraction part
    f = f.CreateCopy(value=FractionValue(0.25), unit="km")
    assert f.value == FractionValue(0.25)
    assert f.GetFormatted() == "0.25 [km]"

    # set fraction again
    f = f.CreateCopy(value=FractionValue(250, (3, 4)), unit="m")
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testEquality():
    def Create(number, fraction):
        return units.FractionScalar("length", value=FractionValue(number, fraction), unit="m")

    assert Create(250, (3, 4)) == Create(250, (3, 4))
    assert not Create(250, (3, 4)) != Create(250, (3, 4))

    assert Create(100, (3, 4)) != Create(250, (3, 4))
    assert not Create(100, (3, 4)) == Create(250, (3, 4))

    a = units.FractionScalar("length", value=1.0, unit="m")
    b = units.FractionScalar("length", value=2.0, unit="m")
    c = units.FractionScalar("length", value=1.0, unit="in")
    d = units.FractionScalar("depth", value=1.0, unit="m")
    e = None
    f = units.FractionScalar("length", value=1.0, unit="m")

    assert a != b
    assert a != c
    assert a != e
    assert a != d

    assert a == f
github ESSS / barril / src / barril / units / _tests / test_fraction_scalar.py View on Github external
def testEquality():
    def Create(number, fraction):
        return units.FractionScalar("length", value=FractionValue(number, fraction), unit="m")

    assert Create(250, (3, 4)) == Create(250, (3, 4))
    assert not Create(250, (3, 4)) != Create(250, (3, 4))

    assert Create(100, (3, 4)) != Create(250, (3, 4))
    assert not Create(100, (3, 4)) == Create(250, (3, 4))

    a = units.FractionScalar("length", value=1.0, unit="m")
    b = units.FractionScalar("length", value=2.0, unit="m")
    c = units.FractionScalar("length", value=1.0, unit="in")
    d = units.FractionScalar("depth", value=1.0, unit="m")
    e = None
    f = units.FractionScalar("length", value=1.0, unit="m")

    assert a != b
    assert a != c
    assert a != e
    assert a != d

    assert a == f