def test_bad_type(no_type_oil): no_type_oil.metadata.product_type = "Fred" validate(no_type_oil) for s in no_type_oil.status: print(s) assert snippet_in_oil_status("W003:", no_type_oil)
def test_reasonable_name(name): # unreasonable names should fail oil = Oil(oil_id='AD00123') oil.metadata.name = name validate(oil) assert snippet_in_oil_status("W001:", oil)
def test_none_year_in_reference(big_record): oil = big_record oil.metadata.reference.year = None validate(oil) assert snippet_in_oil_status("W008", oil)
def test_bad_year_in_reference(big_record): oil = big_record oil.metadata.reference.year = -2000 validate(oil) assert snippet_in_oil_status("E012", oil)
def test_correct_type(no_type_oil): no_type_oil.metadata.product_type = "Crude" validate(no_type_oil) print(no_type_oil.status) for msg in no_type_oil.status: assert not msg.startswith("W001") assert not msg.startswith("W002")
def test_bad_value_in_dist_temp(big_record): oil = big_record oil.sub_samples[0].distillation_data.cuts[0].vapor_temp.value = -1000 validate(oil) print(oil.status) assert snippet_in_oil_status("E040: Value for distillation vapor temp", oil)
def test_good_year_in_reference(big_record): oil = big_record oil.metadata.reference.year = 2020 validate(oil) assert snippet_not_in_oil_status("W1111", oil) assert snippet_not_in_oil_status("E1111", oil)
def test_no_densities(big_record): oil = big_record pp = oil.sub_samples[0].physical_properties del pp.densities[:] validate(oil) print(oil.status) assert snippet_in_oil_status("W006: No density values provided", oil)
def test_no_type(no_type_oil): # print("oil.metadata") # print(no_type_oil.metadata) validate(no_type_oil) # print("status after validating") # for s in no_type_oil.status: # print(s) assert snippet_in_oil_status("W002:", no_type_oil)
def test_big_record_no_type(big_record): """ remove the product type from the record """ oil = big_record oil.metadata.product_type = None validate(oil) print(oil.status) assert snippet_in_oil_status("W002", oil)
def test_api_real_record(big_record): """ note that this used a real record as of version 1: api is stored in the zeroth subrecord.. so this makes sure the API tests work with that. """ oil = big_record validate(oil) assert snippet_not_in_oil_status("E002:", oil) assert snippet_not_in_oil_status("W004:", oil)
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)
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)
def test_no_api_crude(no_type_oil): oil = no_type_oil oil.metadata.product_type = "Crude Oil NOS" validate(oil) assert snippet_in_oil_status("E030:", oil)
def test_no_api_not_crude(no_type_oil): # we've turned off these warnings oil = no_type_oil oil.metadata.product_type = "Solvent" validate(oil) assert snippet_not_in_oil_status("W004:", oil)
def test_no_densities_with_density(big_record): oil = big_record validate(oil) assert snippet_not_in_oil_status("W006:", oil)
def test_density_data(big_record): oil = big_record validate(oil) assert snippet_not_in_oil_status("W004:", oil)
def test_no_subsamples(no_type_oil): oil = no_type_oil validate(oil) assert snippet_in_oil_status("E031", oil)
def test_api_outragious(no_type_oil): oil = no_type_oil oil.metadata.API = -200 validate(oil) assert snippet_in_oil_status("W005:", oil)