• 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

97.56
/pymatgen/io/qchem/tests/test_utils.py
1
# Copyright (c) Pymatgen Development Team.
2
# Distributed under the terms of the MIT License.
3

4

5
from __future__ import annotations
1✔
6

7
import logging
1✔
8
import os
1✔
9
import struct
1✔
10
import unittest
1✔
11

12
import pytest
1✔
13
from monty.io import zopen
1✔
14

15
from pymatgen.io.qchem.utils import lower_and_check_unique, process_parsed_HESS
1✔
16
from pymatgen.util.testing import PymatgenTest
1✔
17

18
__author__ = "Ryan Kingsbury, Samuel Blau"
1✔
19
__copyright__ = "Copyright 2018-2022, The Materials Project"
1✔
20

21
logger = logging.getLogger(__name__)
1✔
22

23

24
test_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files")
1✔
25

26

27
class UtilTest(PymatgenTest):
1✔
28
    """
29
    test utils
30
    """
31

32
    def test_lower_and_check_unique(self):
1✔
33
        d = {"sVp": {"RHOISO": 0.0009}, "jobType": "SP"}
1✔
34
        d2 = lower_and_check_unique(d)
1✔
35
        assert d2 == {"svp": {"RHOISO": 0.0009}, "job_type": "sp"}
1✔
36
        d3 = lower_and_check_unique(d2["svp"])
1✔
37
        assert d3 == {"rhoiso": "0.0009"}
1✔
38
        d4 = {"jobType": "SP", "JOBtype": "SP"}
1✔
39
        # should not raise an exception
40
        assert lower_and_check_unique(d4) == {"job_type": "sp"}
1✔
41
        d4.update({"jobType": "opt"})
1✔
42
        with pytest.raises(ValueError, match="Multiple instances of key"):
1✔
43
            lower_and_check_unique(d4)
1✔
44

45
    def test_process_parsed_HESS(self):
1✔
46
        data_132 = []
1✔
47
        with zopen(os.path.join(test_dir, "parse_hess", "132.0"), mode="rb") as file:
1✔
48
            binary = file.read()
1✔
49
            for ii in range(int(len(binary) / 8)):
1✔
50
                data_132.append(struct.unpack("d", binary[ii * 8 : (ii + 1) * 8])[0])
1✔
51

52
        data_HESS = []
1✔
53
        with zopen(
1✔
54
            os.path.join(test_dir, "parse_hess", "HESS"),
55
            mode="rt",
56
            encoding="ISO-8859-1",
57
        ) as f:
58
            data_HESS = f.readlines()
1✔
59

60
        processed_data_HESS = process_parsed_HESS(data_HESS)
1✔
61

62
        assert len(data_132) == len(processed_data_HESS)
1✔
63
        for ii, val in enumerate(data_132):
1✔
64
            diff = abs(val - processed_data_HESS[ii])
1✔
65
            assert diff < 1e-15
1✔
66

67

68
if __name__ == "__main__":
1✔
69
    unittest.main()
×
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