コード例 #1
0
def test_example_with_temp():
    """Test the ingest of a material run via temp file and cleaning up."""
    # run the parsing to make sure no exceptions are thrown
    result = ingest_material_run(example)

    # write/read with a temp file that is auto-deleted
    with tempfile.TemporaryFile("w+") as fp:
        # write to temp file
        dump(result, fp, indent=2)

        # read it back
        fp.seek(0)
        copy = load(fp)

        # very cursory check that we get out what we'd expect
        assert next(iter(copy.uids.values())) == example["sample_id"]
コード例 #2
0
def test_example():
    """Test the ingest of a material run and leave evidence for humans."""
    # run the parsing to make sure no exceptions are thrown
    result = ingest_material_run(example)
    filename = "/tmp/material_run_example.json"

    assert len(result.measurements) == len(example["experiments"])

    # write to a file (for human inspection)
    with open(filename, "w") as f:
        dump(result, f, indent=2)

    # read it back
    with open(filename, "r") as f:
        copy = load(f)

    # very cursory check that we get out what we'd expect
    assert next(iter(copy.uids.values())) == example["sample_id"]
コード例 #3
0
def test_table():
    """Convert a dictionary to a pandas dataframe and then to a table."""
    material = MaterialRun("name")
    df = pd.DataFrame.from_records(data)
    result = ingest_table(material, df)
    assert isinstance(result, MaterialRun)
    assert len(result.measurements) == len(data)

    filename = "/tmp/table_example.json"

    # write to a file (for human inspection)
    with open(filename, "w") as f:
        dump(result, f, indent=2)

    # read it back
    with open(filename, "r") as f:
        copy = load(f)

    assert isinstance(copy, MaterialRun)