Skip to content

Commit

Permalink
test for provenance from SNLs
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Mar 11, 2021
1 parent cea55df commit 637945c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/emmet-core/test_provenance.py
@@ -0,0 +1,52 @@
from datetime import datetime

import pytest
from pymatgen import Element, Lattice
from pymatgen.core import Structure
from pymatgen.util.provenance import Author, HistoryNode, StructureNL

from emmet.core.provenance import Database, ProvenanceDoc


@pytest.fixture
def structure():
test_latt = Lattice.cubic(3.0)
test_struc = Structure(lattice=test_latt, species=["Fe"], coords=[[0, 0, 0]])
return test_struc


@pytest.fixture
def snls(structure):

docs = [
StructureNL(
structure,
authors=[Author("test{i}", "test@test.com").as_dict()],
history=[HistoryNode("nothing", "url.com", {})],
created_at=datetime.utcnow(),
).as_dict()
for i in range(3)
]
docs[0]["snl_id"] = "icsd-2"
docs[1]["snl_id"] = "user-1"
docs[2]["snl_id"] = "pf-3"

return docs


def test_from_snls(snls):

doc = ProvenanceDoc.from_SNLs(material_id="mp-3", snls=snls)

assert isinstance(doc, ProvenanceDoc)
assert doc.property_name == "provenance"
assert doc.material_id == "mp-3"
assert doc.theoretical is True
assert doc.database_IDs == {
Database.ICSD: ["icsd-2"],
Database.Pauling_Files: ["pf-3"],
}

# Test experimental detection
snls[0]["about"]["history"][0]["experimental"] = True
assert ProvenanceDoc.from_SNLs(material_id="mp-3", snls=snls).theoretical is False

0 comments on commit 637945c

Please sign in to comment.