Пример #1
0
    def test_validate_no_values(self):
        """
        it shouldn't crash with no data!
        """
        DL = DensityList()

        msgs = DL.validate()

        print(msgs)
        assert len(msgs) == 0
Пример #2
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
Пример #3
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
Пример #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_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
Пример #6
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
Пример #7
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]
Пример #8
0
def test_find_density_at_60F_none():
    """
    if there are no density values, then this should not add an API
    """
    oil = no_api_with_density()

    oil.sub_samples[0].physical_properties.densities = DensityList()
    fixer = FixAPI(oil)

    result = fixer.find_density_at_60F()

    assert result is None
    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
Пример #10
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 = DensityList.from_py_json(json_obj)

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

        assert model.py_json() == json_obj
Пример #11
0
def no_api_with_one_density_13C():
    oil = Oil(oil_id='XXXXXX')

    oil.metadata.product_type = "Condensate"
    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=13.0, unit="C")),
    ])

    oil.sub_samples.append(s)

    return oil
Пример #12
0
 def test_from_json_empty(self):
     assert DensityList.from_py_json([]).py_json() == []
Пример #13
0
 def test_init_empty(self):
     assert DensityList().py_json() == []