Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |