コード例 #1
0
def main():
    base_dir, dry_run = process_input()

    for rec, pth in get_all_records(base_dir):
        print("\n\n******************\n")
        print("processing:", rec.oil_id, rec.metadata.name)
        fixer = FixAPI(rec)
        flag, msg = fixer.check()
        if flag is True:
            print(msg)
            print("Cleaning up!")
            fixer.cleanup()
            print("API is now:", rec.metadata.API)
            if not dry_run:
                print("Saving out:", pth)
                rec.to_file(pth)
            else:
                print("Nothing saved")
        elif flag is False:
            print(msg)
            print("It's a:", rec.metadata.product_type)
            print("Densities are:",
                  rec.sub_samples[0].physical_properties.densities)
        else:
            print(msg)
コード例 #2
0
def test_check_no_API():
    oil = no_api_with_density()

    fixer = FixAPI(oil)
    print("in test: API:", oil.metadata.API)

    flag, msg = fixer.check()

    assert flag is True

    assert msg.startswith(f"Cleanup: {fixer.ID}:")
    assert "No API value provided" in msg
コード例 #3
0
def test_check_API_is_there_mismatch():
    """
    if there is an API, check() should return the empty string
    """
    oil = no_api_with_density()
    oil.metadata.API = 32.0

    fixer = FixAPI(oil)

    flag, msg = fixer.check()

    print(flag)
    print(msg)

    assert flag is True
    assert "doesn't match density data" in msg
コード例 #4
0
def test_check_API_is_there_correct():
    """
    if there is an API, check() should return the empty string
    """
    oil = no_api_with_density()
    oil.metadata.API = 30.06

    fixer = FixAPI(oil)

    flag, msg = fixer.check()

    print(flag)
    print(msg)

    assert flag is None
    assert "API is fine" in msg