Пример #1
0
    def test_complete_sample(self):
        """
        trying to do a pretty complete one

        Note: This is more an integration test.  Each complex attribute of the
              PhysicalProperties dataclass should have its own pytests
        """
        p = PhysicalProperties()

        p.densities = DensityList([
            DensityPoint(density=Density(value=0.8751, unit="kg/m^3",
                                         standard_deviation=1.2,
                                         replicates=3),
                         ref_temp=Temperature(value=15.0, unit="C")),
            DensityPoint(density=Density(value=0.99, unit="kg/m^3",
                                         standard_deviation=1.4,
                                         replicates=5),
                         ref_temp=Temperature(value=25.0, unit="C"))
        ])

        py_json = p.py_json(sparse=False)  # the non-sparse version

        for name in ('densities',
                     'kinematic_viscosities',
                     'dynamic_viscosities'):
            assert name in py_json

        # Now test some real stuff:
        dens = py_json['densities']
        print(type(dens))

        assert type(dens) == list
        assert dens[0]['density']['value'] == 0.8751
    def test_complete_sample(self):
        """
        trying to do a pretty complete one

        Note: This is more an integration test.  Each complex attribute of the
              Sample should have its own pytests
        """
        s = Sample(metadata=SampleMetaData(
            short_name="short", name="a longer name that is more descriptive"))
        p = PhysicalProperties()

        s.metadata.fraction_evaporated = MassFraction(value=11, unit='%')
        s.metadata.boiling_point_range = None

        p.densities = DensityList([
            DensityPoint(density=Density(value=0.8751,
                                         unit="kg/m^3",
                                         standard_deviation=1.2,
                                         replicates=3),
                         ref_temp=Temperature(value=15.0, unit="C")),
            DensityPoint(density=Density(value=0.99,
                                         unit="kg/m^3",
                                         standard_deviation=1.4,
                                         replicates=5),
                         ref_temp=Temperature(value=25.0, unit="C"))
        ])

        s.physical_properties = p

        py_json = s.py_json(sparse=False)  # the non-sparse version

        for name in ('CCME', 'ESTS_hydrocarbon_fractions', 'SARA',
                     'bulk_composition', 'compounds', 'cut_volume',
                     'distillation_data', 'environmental_behavior',
                     'extra_data', 'headspace_analysis', 'industry_properties',
                     'metadata', 'miscellaneous', 'physical_properties'):
            assert name in py_json

        assert py_json['metadata']['name'] == ('a longer name that is more '
                                               'descriptive')
        assert py_json['metadata']['short_name'] == "short"

        for name in ('densities', 'kinematic_viscosities',
                     'dynamic_viscosities'):
            assert name in py_json['physical_properties']

        # Now test some real stuff:
        dens = py_json['physical_properties']['densities']
        print(type(dens))

        assert type(dens) == list
        assert dens[0]['density']['value'] == 0.8751
Пример #3
0
    def test_validate_no_duplicate_values(self):
        dp1 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=0, unit='C'),
                           )
        dp2 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=15, unit='C'),
                           )

        DL = DensityList((dp1, dp2))

        msgs = DL.validate()

        print(msgs)
        assert len(msgs) == 0
Пример #4
0
    def test_validate_non_numeric_value(self):
        dp1 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=0, unit='C'),
                           )
        dp2 = DensityPoint(density=Density(value="NM", unit='kg/m^3'),
                           ref_temp=Temperature(value=15, unit='C'),
                           )

        DL = DensityList((dp1, dp2))

        msgs = DL.validate()

        print(msgs)
        assert len(msgs) == 1
        assert "E044:" in msgs[0]
Пример #5
0
    def test_validate_bad_temp(self):
        dp1 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=0, unit='K'),
                           )
        dp2 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=20.0, unit='K'),
                           )

        DL = DensityList((dp1, dp2))

        msgs = DL.validate()

        print(msgs)

        assert len(msgs) == 2
        for msg in msgs:
            assert "E040:" in msg
            assert "Density" in msg
Пример #6
0
    def test_validate_negative_numeric_value(self):
        dp1 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=0, unit='C'),
                           )
        dp2 = DensityPoint(density=Density(value="0.0", unit='kg/m^3'),
                           ref_temp=Temperature(value=15, unit='C'),
                           )
        dp3 = DensityPoint(density=Density(value="-10.0", unit='kg/m^3'),
                           ref_temp=Temperature(value=15, unit='C'),
                           )

        DL = DensityList((dp1, dp2, dp3))

        msgs = DL.validate()

        print(msgs)
        assert len(msgs) == 2
        assert "E044:" in msgs[0]
        assert "0.0" in msgs[0]
        assert "E044:" in msgs[1]
        assert "-10.0" in msgs[1]
Пример #7
0
def no_api_with_density():
    oil = Oil(oil_id='XXXXXX')

    oil.metadata.product_type = "Crude Oil NOS"
    print(oil)

    # create a sample for fresh oil
    s = Sample()

    # add some densities
    # p = PhysicalProperties()
    p = s.physical_properties
    p.densities = DensityList([
        DensityPoint(density=Density(value=0.8751, unit="g/cm^3"),
                     ref_temp=Temperature(value=60.0, unit="F")),
        DensityPoint(density=Density(value=0.99, unit="g/cm^3"),
                     ref_temp=Temperature(value=25.0, unit="C"))
    ])

    oil.sub_samples.append(s)

    return oil
Пример #8
0
    def make_oil_with_densities(self, densities, temps):
        oil = Oil(oil_id="DENSITY_TESTER")
        sample = Sample()
        sample.metadata.name = "only density"

        oil.sub_samples.append(sample)

        for d, t in zip(densities, temps):
            dp = DensityPoint(meas.Density(d, unit="kg/m^3"),
                              meas.Temperature(t, unit="K"))
            sample.physical_properties.densities.append(dp)

        return oil
Пример #9
0
    def test_from_json(self):
        json_obj = {'density': {'value': 900.0, 'unit': 'kg/m^3',
                                'standard_deviation': 1.2, 'replicates': 3},
                    'ref_temp': {'value': 273.15, 'unit': 'K',
                                 'standard_deviation': 1.2, 'replicates': 3}
                    }
        model = DensityPoint.from_py_json(json_obj)

        # the measurement classes will add unit_type, so we add it to more
        # easily compare the output
        json_obj['density']['unit_type'] = 'density'
        json_obj['ref_temp']['unit_type'] = 'temperature'

        assert model.py_json() == json_obj
Пример #10
0
    def test_validate_one_value(self):
        """
        it shouldn't crash (or give an warning) with one value!
        """
        dp1 = DensityPoint(density=Density(value=900, unit='kg/m^3'),
                           ref_temp=Temperature(value=0, unit='C'),
                           )

        DL = DensityList((dp1,))

        msgs = DL.validate()

        print(msgs)
        assert len(msgs) == 0
Пример #11
0
def test_API_density_missmatch(minimal_oil):
    oil = minimal_oil
    minimal_oil.metadata.API = 32.2  # too far from 32.0
    density = DensityPoint(  # API 32.0 converted
        density=Density(value=0.86469, unit='g/cm^3'),
        ref_temp=Temperature(value=60, unit='F'),
    )
    oil.sub_samples[0].physical_properties.densities.append(density)

    density_at_60F = physical_properties.Density(oil).at_temp(60, 'F')
    API = uc.convert('kg/m^3', 'API', density_at_60F)

    print(f"{density_at_60F=}")
    print(f"{API=}")
    print(f"{minimal_oil.metadata.API=}")

    validate(oil)

    print(oil.status)

    assert snippet_in_oil_status("E043", oil)
Пример #12
0
def test_API_density_match(minimal_oil):
    oil = minimal_oil
    minimal_oil.metadata.API = 32.1  # close enough to 32.0
    density = DensityPoint(
        density=Density(value=0.86469, unit='g/cm^3'),
        ref_temp=Temperature(value=60, unit='F'),
    )
    oil.sub_samples[0].physical_properties.densities.append(density)

    density_at_60F = physical_properties.Density(oil).at_temp(60, 'F')
    API = uc.convert('kg/m^3', 'API', density_at_60F)
    print(density_at_60F)
    print(API)

    assert math.isclose(API, oil.metadata.API, rel_tol=1e3)

    validate(oil)

    print(oil.status)

    assert snippet_not_in_oil_status("E043", oil)
Пример #13
0
    def test_from_json_empty(self):
        model = DensityPoint.from_py_json({})

        assert model.density is None
        assert model.ref_temp is None
        assert model.method is None
Пример #14
0
    def test_init_empty(self):
        model = DensityPoint()

        assert model.density is None
        assert model.ref_temp is None
        assert model.method is None