예제 #1
0
def test_full_round_robin():
    pif = System(properties=[
        Property(
            name="foo",
            scalars=[Scalar(value=np.float32(2.4)),
                     Scalar(value=np.int64(2))]),
        Property(name="bar", scalars=[Scalar(value=2.4),
                                      Scalar(value=2)]),
        Property(name="spam", files=[FileReference(relative_path="/tmp/file")])
    ],
                 preparation=[
                     ProcessStep(name="processed",
                                 details=[
                                     Value(name="temp",
                                           scalars=[Scalar(value=1.0)])
                                 ])
                 ],
                 contacts=[Person(name=Name(family="Einstein"))])

    pif2 = loads(dumps(pif))
    assert pif2.as_dictionary() == pif.as_dictionary(
    ), "PIF contents are not the same"
    assert pif.properties[0].scalars[0].value == pif2.properties[0].scalars[
        0].value
    assert pif.properties[1].scalars[0].value == pif2.properties[1].scalars[
        0].value
    assert pif.properties[2].files[0].relative_path == pif2.properties[
        2].files[0].relative_path
    assert pif.preparation[0].details[0].scalars[0].value == pif2.preparation[
        0].details[0].scalars[0].value
    assert pif.contacts[0].name.family == pif2.contacts[0].name.family
예제 #2
0
def test_upload_pif():
    """
    Tests that a PIF can be created, serialized, uploaded
    then downloaded and deserialized
    """
    pif = System()
    pif.id = 0
    uid = random_string()
    pif.uid = uid

    with open("tmp.json", "w") as fp:
        dump(pif, fp)
    assert client.upload(dataset_id, "tmp.json").successful()
    tries = 0
    while True:
        try:
            pif = client.get_pif(dataset_id, uid)
            break
        except ResourceNotFoundException:
            if tries < 10:
                tries += 1
                time.sleep(1)
            else:
                raise

    status = client.get_ingest_status(dataset_id)
    assert status == "Finished"
    with open("tmp.json", "r") as fp:
        assert json.loads(fp.read())["uid"] == pif.uid
예제 #3
0
def test_update_pif_append():
    pif1 = System(
        properties=[Property(name="foo", scalars=[Scalar(value="bar")])])
    pif2 = System(
        properties=[Property(name="spam", scalars=[Scalar(value="eggs")])])
    new = update_pif(pif1, pif2)
    assert len(new.properties) == 2
    assert set(x.name for x in new.properties) == set(["foo", "spam"])
def test_upload_pif():
    client = CitrinationClient(environ['CITRINATION_API_KEY'], environ['CITRINATION_SITE'])
    dataset = loads(client.create_data_set(name="Tutorial dataset", description="Dataset for tutorial", share=0).content.decode('utf-8'))['id']
    pif = System()
    pif.id = 0

    with open("tmp.json", "w") as fp:
        dump(pif, fp)
    response = loads(client.upload_file("tmp.json", dataset))
    assert response["message"] == "Upload is complete."
예제 #5
0
def test_update_pif_set():
    pif1 = System(contacts=[
        Person(name=Name(given="Steve", family="Holt"), email="*****@*****.**")
    ])
    pif2 = System(
        properties=[Property(name="spam", scalars=[Scalar(value="eggs")])])
    new = update_pif(pif1, pif2)
    assert new.contacts[0].name.given == "Steve"
    assert new.contacts[0].email == "*****@*****.**"
    assert new.properties[0].scalars[0].value == "eggs"
def test_upload_pif():
    client = CitrinationClient(environ['CITRINATION_API_KEY'], 'https://stage.citrination.com')
    dataset = loads(client.create_data_set(name="Tutorial dataset", description="Dataset for tutorial", share=0).content.decode('utf-8'))['id']
    pif = System()
    pif.id = 0

    with TemporaryDirectory() as tmpdir:
        tempname = join(tmpdir, "pif.json")
        with open(tempname, "w") as fp:
            dump(pif, fp)
        response = loads(client.upload_file(tempname, dataset))
    assert response["message"] == "Upload is complete."
예제 #7
0
def test_upload_pif():
    client = CitrinationClient(environ['CITRINATION_API_KEY'],
                               environ['CITRINATION_SITE'])
    dataset = loads(
        client.create_data_set(name="Tutorial dataset",
                               description="Dataset for tutorial",
                               share=0).content.decode('utf-8'))['id']
    pif = System()
    pif.id = 0

    with open("tmp.json", "w") as fp:
        dump(pif, fp)
    response = loads(client.upload_file("tmp.json", dataset))
    assert response["message"] == "Upload is complete."
def test_condition():
    """Test that conditions are flattened and added"""
    condition = Value(name="spam", scalars=[Scalar(value="eggs")])
    sys = System(properties=[
        Property(name="foo", scalars=[Scalar(value="bar")], conditions=[condition])
    ])
    user_data = _to_user_defined(sys)
    assert user_data["spam"] == "eggs"
예제 #9
0
def test_property_list():
    """Test that a property with a list of scalars gets pulled out"""
    sys = System(properties=[
        Property(name="foo",
                 scalars=[Scalar(
                     value="spam"), Scalar(value="eggs")])
    ])
    user_data = _to_user_defined(sys)
    assert user_data["foo"] == ["spam", "eggs"]
예제 #10
0
def test_property_vector():
    """Test that a vector gets pulled out"""
    sys = System(properties=[
        Property(name="foo",
                 units="bar",
                 vectors=[[Scalar(
                     value="spam"), Scalar(value="eggs")]])
    ])
    user_data = _to_user_defined(sys)
    assert user_data["foo_bar"] == ["spam", "eggs"]
예제 #11
0
def test_add_datacite():
    data_pif = System(
        properties=[Property(name="Foo", scalars=[Scalar(value="bar")])])
    dc = {
        "identifier": {
            "identifier": "000.000",
            "identifierType": "DOI"
        },
        "title":
        "The joy of the PIF",
        "publisher":
        "Ether",
        "publicationYear":
        "2014",
        "creators": [{
            "creatorName": "Kyle Michel",
            "affiliations": ["Berklee", "NW"]
        }]
    }
    res = add_datacite(data_pif, dc)
    assert res.properties[0].scalars[0].value == "bar"
    assert res.references[0].doi == "000.000"

    data_pif2 = System(
        properties=[Property(name="Foo", scalars=[Scalar(value="bar")])])
    dc2 = {
        "title":
        "The joy of the PIF",
        "publisher":
        "Ether",
        "publicationYear":
        "2014",
        "creators": [{
            "creatorName": "Kyle Michel",
            "affiliations": ["Berklee", "NW"]
        }]
    }
    res2 = add_datacite(data_pif2, dc2)
    assert res2.properties[0].scalars[0].value == "bar"
    assert res2.references[0].doi is None
예제 #12
0
def test_basic_round_robin():
    pif = System()
    pif.uid = "foo"
    pif2 = loads(dumps(pif))
    assert pif2.uid == pif.uid
예제 #13
0
def test_dup_pifs():
    pifs = [System(names=["foo"]), System(names=["foo"])]
    set_uids(pifs)
    assert len({p.uid for p in pifs}) == 1
예제 #14
0
def test_get_url():
    pif = System(uid="foobar")
    url = get_url(pif, version=2, dataset=8)
    assert url == "https://citrination.com/datasets/8/version/2/pif/foobar"
예제 #15
0
def test_property_value():
    """Test that a simple property gets pulled out"""
    sys = System(
        properties=[Property(name="foo", scalars=[Scalar(value="bar")])])
    user_data = _to_user_defined(sys)
    assert user_data["foo"] == "bar"
예제 #16
0
def test_explicit_uids():
    pifs = [System(names=["foo"]), System(names=["bar"])]
    uids = ["spam", "eggs"]
    set_uids(pifs, ["spam", "eggs"])
    assert [p.uid for p in pifs] == uids
예제 #17
0
def test_set_uids():
    pifs = [System(names=["foo"]), System(names=["bar"])]
    set_uids(pifs)
    for pif in pifs:
        assert pif.uid
    assert len({p.uid for p in pifs}) == 2
예제 #18
0
def test_update_pif_replace():
    pif1 = System(uid="0")
    pif2 = System(uid="1")
    new = update_pif(pif1, pif2)
    assert new.uid == "1"