• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

materialsproject / pymatgen / 4075885785

pending completion
4075885785

push

github

Shyue Ping Ong
Merge branch 'master' of github.com:materialsproject/pymatgen

96 of 96 new or added lines in 27 files covered. (100.0%)

81013 of 102710 relevant lines covered (78.88%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/pymatgen/ext/tests/test_optimade.py
1
# Copyright (c) Pymatgen Development Team.
2
# Distributed under the terms of the MIT License.
3

4
from __future__ import annotations
1✔
5

6
import unittest
1✔
7

8
import requests
1✔
9

10
from pymatgen.core import SETTINGS
1✔
11
from pymatgen.ext.optimade import OptimadeRester
1✔
12
from pymatgen.util.testing import PymatgenTest
1✔
13

14
try:
1✔
15
    website_down = requests.get("https://materialsproject.org").status_code != 200
1✔
16
except requests.exceptions.ConnectionError:
×
17
    website_down = True
×
18

19

20
@unittest.skipIf(
1✔
21
    not SETTINGS.get("PMG_MAPI_KEY") or website_down,
22
    "PMG_MAPI_KEY environment variable not set or MP is down.",
23
)
24
class OptimadeTest(PymatgenTest):
1✔
25
    def test_get_structures_mp(self):
1✔
26
        with OptimadeRester("mp") as optimade:
1✔
27
            structs = optimade.get_structures(elements=["Ga", "N"], nelements=2)
1✔
28

29
        with OptimadeRester("mp") as optimade:
1✔
30
            _filter = 'elements HAS ALL "Ga", "N" AND nelements=2'
1✔
31
            raw_filter_structs = optimade.get_structures_with_filter(_filter)
1✔
32

33
            # skip if query fails to return any results (e.g. server down or inaccessible)
34
            if ("mp" in structs) and ("mp" in raw_filter_structs):
1✔
35
                test_struct = next(iter(structs["mp"].values()))
×
36
                assert [str(el) for el in test_struct.types_of_species] == ["Ga", "N"]
×
37

38
                assert len(structs["mp"]) == len(
×
39
                    raw_filter_structs["mp"]
40
                ), f"Raw filter {_filter} did not return the same number of results as the query builder."
41

42
    def test_get_snls_mp(self):
1✔
43
        with OptimadeRester("mp") as optimade:
1✔
44
            structs = optimade.get_snls(elements=["Ga", "N"], nelements=2)
1✔
45

46
        with OptimadeRester("mp") as optimade:
1✔
47
            response_field_structs_single = optimade.get_snls(
1✔
48
                elements=["Ga", "N"], nelements=2, additional_response_fields="nsites"
49
            )
50
            response_field_structs_set = optimade.get_snls(
1✔
51
                elements=["Ga", "N"], nelements=2, additional_response_fields={"nsites", "nelements"}
52
            )
53
            if ("mp" in response_field_structs_single) and ("mp" in response_field_structs_set):
1✔
54
                assert len(structs["mp"]) == len(response_field_structs_single["mp"])
×
55
                assert len(structs["mp"]) == len(response_field_structs_set["mp"])
×
56

57
                # Check that the requested response fields appear in the SNL metadata
58
                s = list(response_field_structs_single["mp"].values())[0]
×
59
                sp = list(response_field_structs_set["mp"].values())[0]
×
60
                assert "nsites" in s.data["_optimade"]
×
61
                assert "nsites" in sp.data["_optimade"]
×
62
                assert "nelements" in sp.data["_optimade"]
×
63

64
    # Tests fail in CI for unknown reason, use for development only.
65
    # def test_get_structures_mcloud_2dstructures(self):
66
    #
67
    #     with OptimadeRester("mcloud.2dstructures") as optimade:
68
    #
69
    #         structs = optimade.get_structures(elements=["B", "N"], nelements=2)
70
    #
71
    #     test_struct = next(iter(structs["mcloud.2dstructures"].values()))
72
    #
73
    #     self.assertEqual([str(el) for el in test_struct.types_of_species], ["B", "N"])
74

75
    # def test_update_aliases(self):
76
    #
77
    #     with OptimadeRester() as optimade:
78
    #         optimade.refresh_aliases()
79
    #
80
    #     self.assertIn("mp", optimade.aliases)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc