File: testutils.py

package info (click to toggle)
cclib 1.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,412 kB
  • sloc: python: 23,605; makefile: 75; sh: 31
file content (56 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright (c) 2024, the cclib development team
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.

"""Unit tests for parser utils module."""

import cclib


class convertorTest:
    def test_basic(self) -> None:
        """Are some basic conversions correct?"""
        convertor = cclib.parser.utils.convertor
        assert round(abs(convertor(1.89, "bohr", "Angstrom") - 1.0), 3) == 0
        assert round(abs(convertor(0.529, "Angstrom", "bohr") - 1.0), 3) == 0
        assert round(abs(convertor(627.5, "kcal/mol", "hartree") - 1.0), 3) == 0

    def test_pairs(self) -> None:
        """Do flipped conversions correspond to each other?"""

        convertor = cclib.parser.utils.convertor

        pairs_proportional = (
            ("Angstrom", "bohr"),
            ("wavenumber", "eV"),
            ("wavenumber", "kcal/mol"),
            ("eV", "kJ/mol"),
            ("coulomb", "e"),
        )
        pairs_inverse = (("nm", "wavenumber"),)

        for unit1, unit2 in pairs_proportional:
            conv1 = convertor(1.0, unit1, unit2)
            conv2 = 1.0 / convertor(1.0, unit2, unit1)
            assert round(abs((conv1 - conv2) / conv1), 7) == 0
        for unit1, unit2 in pairs_inverse:
            conv1 = convertor(1.0, unit1, unit2)
            conv2 = convertor(1.0, unit2, unit1)
            assert round(abs((conv1 - conv2) / conv1), 7) == 0


class PeriodicTableTest:
    def setup_method(self) -> None:
        self.pt = cclib.parser.utils.PeriodicTable()

    def test_elements(self) -> None:
        """Does the periodic table give correct elements?"""
        assert self.pt.element[6] == "C"
        assert self.pt.element[44] == "Ru"
        assert self.pt.element[0] is None

    def test_numbers(self) -> None:
        """Does the periodic table give correct atom numbers?"""
        assert self.pt.number["C"] == 6
        assert self.pt.number["Au"] == 79