コード例 #1
0
    def test_init_empty(self):
        model = MassFraction()

        py_json = model.py_json()

        # should only have a unit_type
        assert py_json == {}
コード例 #2
0
    def test_completeness_score(self, oil_json, expected):
        oil = Oil.from_py_json(oil_json)
        assert self.Dcheck(oil) == expected

        dist_data = oil.sub_samples[0].distillation_data

        # add fraction_recovered
        # less than one adds 1 point
        dist_data.fraction_recovered = MassFraction(0.8, unit="fraction")
        assert self.Dcheck(oil) == expected + 1

        # exactly one adds 2 points
        dist_data.fraction_recovered = MassFraction(1.0, unit="fraction")
        assert self.Dcheck(oil) == expected + 2
コード例 #3
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
              EnvironmentalBehavior dataclass should have its own pytests
        """
        p = EnvironmentalBehavior()

        p.dispersibilities = DispersibilityList([
            Dispersibility(dispersant='corexit 9500',
                           method='ASTM F2059',
                           effectiveness=MassFraction(value=10.0, unit="%",
                                                      standard_deviation=1.2,
                                                      replicates=3)),
        ])

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

        assert set(py_json.keys()) == {'adhesion',
                                       'dispersibilities',
                                       'emulsions',
                                       'ests_evaporation_test'}

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

        assert type(disp) == list
        assert disp[0]['method'] == 'ASTM F2059'
        assert disp[0]['effectiveness']['value'] == 10.0
コード例 #4
0
    def test_complete(self):
        """
        trying to do a pretty complete one

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

        s.saturates = MassFraction(value=10.0,
                                   unit="%",
                                   standard_deviation=1.2,
                                   replicates=3)

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

        assert set(py_json.keys()) == {
            'method', 'saturates', 'aromatics', 'resins', 'asphaltenes'
        }

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

        assert type(sat) == dict
        assert sat['value'] == 10.0
コード例 #5
0
    def test_py_json(self):
        comp = Compound(name="n-C12 to n-C16",
                        method="ESTS 2002a",
                        measurement=MassFraction(value=38, unit='mg/g'))
        py_json = comp.py_json()

        assert py_json['method'] == "ESTS 2002a"
        assert 'groups' not in py_json
コード例 #6
0
    def test_with_ccme(self):
        """
        Generally we should keep our pytests small, testing one thing at a
        time.
        """
        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)

        py_json = ccme.py_json()

        # test the round trip
        ccme2 = CCME.from_py_json(py_json)

        assert ccme2 == ccme
コード例 #7
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
コード例 #8
0
    def test_init_full(self):
        comp = Compound(name="1-Methyl-2-Isopropylbenzene",
                        groups=["C4-C6 Alkyl Benzenes", "Aromatics"],
                        method="ESTS 2002b",
                        measurement=MassFraction(value=3.4,
                                                 unit="ppm",
                                                 replicates=3,
                                                 standard_deviation=0.1))

        assert comp.name == "1-Methyl-2-Isopropylbenzene"
        assert len(comp.groups) == 2
        assert comp.measurement.value == 3.4
        assert comp.measurement.unit_type == "massfraction"
コード例 #9
0
    def test_full(self):
        """
        But hey, here we go with a full-on test of everything
        """
        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"

        py_json = ccme.py_json()
        pprint(py_json)

        # dump the json:
        # json.dump(py_json, open(OUTPUT_DIR / "example_ccme.json", 'w'),
        #           indent=4)

        # test the round trip
        ccme2 = CCME.from_py_json(py_json)

        assert ccme2 == ccme
コード例 #10
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
コード例 #11
0
    def test_convert_to(self):
        model = MassFraction(value=1.0, unit='g/kg')
        model.convert_to('%')

        assert model.value == 0.1
        assert model.unit == '%'
コード例 #12
0
    "name": "1-Methyl-2-Isopropylbenzene",
    "groups": ["C4-C6 Alkyl Benzenes", ...],
    "method": "ESTS 2002b",
    "measurement": {
        "value": 3.4,
        "unit": "ppm",
        "replicates": 3,
        "standard_deviation": 0.1
    }
}

Comp1 = Compound(name="1-Methyl-2-Isopropylbenzene",
                 groups=["C4-C6 Alkyl Benzenes", "Aromatics"],
                 method="ESTS 2002b",
                 measurement=MassFraction(value=3.4,
                                          unit="ppm",
                                          replicates=3,
                                          standard_deviation=0.1))

Comp2 = Compound(name="4-Ethyl Death-benzene",
                 groups=["C6-C64 Alkyl Benzenes", "Saturated"],
                 method="ANSI random number",
                 measurement=MassFraction(value=2.1,
                                          unit="g/kg",
                                          replicates=5,
                                          standard_deviation=0.2))


class TestCompound:
    def test_init(self):
        comp = Compound()