コード例 #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
              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
コード例 #2
0
    def test_json_non_sparse(self):
        s = Sample()
        py_json = s.py_json(sparse=False)

        for attr 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 attr in py_json

        assert py_json['metadata']['name'] == "Fresh Oil Sample"
        assert py_json['metadata']['short_name'] == "Fresh Oil"
コード例 #3
0
 def test_default_empty_attributes(self, attr):
     """
     test that various attributes get a default empty object,
     rather than None
     """
     s = Sample()
     assert getattr(s, attr) is not None
コード例 #4
0
def minimal_oil():
    oil = Oil('XXXXX')
    oil.metadata.name = "Minimal Oil for Tests"
    fresh = Sample()
    # print(fresh.physical_properties)
    oil.sub_samples.append(fresh)
    return oil
コード例 #5
0
    def test_init(self):
        s = Sample()

        for attr 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 hasattr(s, attr)

        assert s.metadata.name == "Fresh Oil Sample"
        assert s.metadata.short_name == "Fresh Oil"
コード例 #6
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
コード例 #7
0
def test_sample_with_ccme():
    """
    testing loading a sample with ccme data from py_json
    """
    ccme = CCME()

    ccme.F1 = MassFraction(unit="mg/g", value=15.58)
    ccme.F2 = MassFraction(unit="mg/g", value=50)
    ccme.F3 = MassFraction(unit="mg/g", value=193)
    ccme.F4 = MassFraction(unit="mg/g", value=40)
    ccme.method = "a method name"

    s = Sample(metadata=SampleMetaData(
        short_name="short", name="a longer name that is more descriptive"))
    s.metadata.fraction_evaporated = MassFraction(value=16, unit="%")
    s.metadata.boiling_point_range = None
    s.CCME = ccme

    sample_json = s.py_json()

    s2 = Sample.from_py_json(sample_json)

    assert s == s2
コード例 #8
0
def add_kin_viscosity_to_oil(oil,
                             viscosities,
                             temp,
                             unit,
                             kvis_temp=15.0,
                             temp_unit="C"):
    try:
        sample = oil.sub_samples[0]
    except IndexError:
        sample = Sample()
        sample.metadata.name = "only viscosity"
        oil.sub_samples.append(sample)
    for kvis in viscosities:
        kp = KinematicViscosityPoint(
            meas.KinematicViscosity(kvis, unit=unit),
            meas.Temperature(kvis_temp, unit=temp_unit))
        sample.physical_properties.kinematic_viscosities.append(kp)
    return None
コード例 #9
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
コード例 #10
0
    def test_metadata(self):
        s = Sample.from_py_json({
            'metadata': {
                'name': 'Fresh Oil Sample',
                'short_name': 'Fresh Oil',
                'fraction_evaporated': {
                    'value': 11,
                    'unit': '%',
                    'unit_type': 'massfraction'
                }
            }
        })

        for attr 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 hasattr(s, attr)

        assert s.metadata.name == 'Fresh Oil Sample'
        assert s.metadata.short_name == 'Fresh Oil'
        assert s.metadata.fraction_evaporated.value == 11
        assert s.metadata.fraction_evaporated.unit == '%'
コード例 #11
0
    def test_add_non_existing(self):
        s = Sample()

        with pytest.raises(AttributeError):
            s.something_random = 43
コード例 #12
0
    def test_json(self):
        s = Sample(metadata=SampleMetaData(
            short_name="short", name="a longer name that is more descriptive"))
        py_json = s.py_json()  # the sparse version

        assert tuple(py_json['metadata'].keys()) == ('name', 'short_name')
コード例 #13
0
    def test_populated(self):
        s = Sample()
        sl = SampleList([s])

        assert len(sl) == 1
        assert type(sl[0]) == Sample