-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_cli.py
155 lines (125 loc) · 5.53 KB
/
test_cli.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import subprocess as sp
from click.testing import CliRunner
from aiida.backends.testbase import AiidaTestCase
from aiida_gaussian_datatypes.basisset.cli import cli as basisset_cli, list_basisset, import_basisset, dump_basisset
from aiida_gaussian_datatypes.pseudopotential.cli import cli as pseudo_cli, list_pseudo, import_pseudo, dump_pseudo
from . import TEST_DIR
class TestCliBasisset(AiidaTestCase):
def setUp(self):
self.cli_runner = CliRunner()
def test_help(self):
self.cli_runner.invoke(basisset_cli, ["--help"], catch_exceptions=False)
def test_reachable(self):
output = sp.check_output(["verdi", "data", "gaussian.basisset", "--help"])
assert b"Usage:" in output
def test_empty_list(self):
result = self.cli_runner.invoke(list_basisset)
assert not result.exception
assert "No Gaussian Basis Sets found." in result.output
def test_import(self):
result = self.cli_runner.invoke(
import_basisset, ["--format", "cp2k", str(TEST_DIR.joinpath("BASIS_MOLOPT.H"))], input="y\n"
)
assert not result.exception
assert "Add a Gaussian Basis Set for 'H' from 'SZV-MOLOPT-GTH-q1'" in result.output
# a second import should be ignored silently
result = self.cli_runner.invoke(import_basisset, ["--format", "cp2k", str(TEST_DIR.joinpath("BASIS_MOLOPT.H"))])
assert not result.exception
assert "No valid Gaussian Basis Sets found in the given file matching the given criteria" in result.output
# unless explicitly asked for
result = self.cli_runner.invoke(
import_basisset, ["--format", "cp2k", "--duplicates", "error", str(TEST_DIR.joinpath("BASIS_MOLOPT.H"))]
)
assert result.exception
# but we should be able to import as new nevertheless
result = self.cli_runner.invoke(
import_basisset,
["--format", "cp2k", "--duplicates", "new", str(TEST_DIR.joinpath("BASIS_MOLOPT.H"))],
input="y\n",
)
assert not result.exception
assert "Add a Gaussian Basis Set for 'H' from 'SZV-MOLOPT-GTH-q1'" in result.output
result = self.cli_runner.invoke(list_basisset)
assert not result.exception
assert "2 Gaussian Basis Sets found" in result.output
def test_dump(self):
result = self.cli_runner.invoke(
import_basisset, ["--format", "cp2k", "--sym", "H", str(TEST_DIR.joinpath("BASIS_MOLOPT.H"))], input="y\n"
)
assert not result.exception
result = self.cli_runner.invoke(dump_basisset, ["--format", "cp2k", "--sym", "H"])
assert not result.exception
assert "H SZV-MOLOPT-GTH-q1" in result.output
class TestCliPseudo(AiidaTestCase):
def setUp(self):
self.cli_runner = CliRunner()
def test_help(self):
self.cli_runner.invoke(pseudo_cli, ["--help"], catch_exceptions=False)
def test_reachable(self):
output = sp.check_output(["verdi", "data", "gaussian.pseudo", "--help"])
assert b"Usage:" in output
def test_empty_list(self):
result = self.cli_runner.invoke(list_pseudo)
assert not result.exception
assert "No Gaussian Pseudopotentials found." in result.output
def test_import(self):
result = self.cli_runner.invoke(
import_pseudo,
["--format", "cp2k", "--sym", "He", "--tag", "PBE", str(TEST_DIR.joinpath("GTH_POTENTIALS"))],
input="y\n",
)
assert not result.exception
assert "Add a Gaussian 'GTH-PBE-q2' Pseudopotential for 'He'" in result.output
# a second import should be ignored silently
result = self.cli_runner.invoke(
import_pseudo, ["--format", "cp2k", "--sym", "He", "--tag", "PBE", str(TEST_DIR.joinpath("GTH_POTENTIALS"))]
)
assert not result.exception
assert "No valid Gaussian Pseudopotentials found in the given file matching the given criteria" in result.output
# unless explicitly asked for
result = self.cli_runner.invoke(
import_pseudo,
[
"--format",
"cp2k",
"--sym",
"He",
"--tag",
"PBE",
"--duplicates",
"error",
str(TEST_DIR.joinpath("GTH_POTENTIALS")),
],
)
assert result.exception
# but we should be able to import as new nevertheless
result = self.cli_runner.invoke(
import_pseudo,
[
"--format",
"cp2k",
"--sym",
"He",
"--tag",
"PBE",
"--duplicates",
"new",
str(TEST_DIR.joinpath("GTH_POTENTIALS")),
],
input="y\n",
)
assert not result.exception
assert "Add a Gaussian 'GTH-PBE-q2' Pseudopotential for 'He'" in result.output
result = self.cli_runner.invoke(list_pseudo)
assert not result.exception
assert "2 Gaussian Pseudopotentials found" in result.output
def test_dump(self):
result = self.cli_runner.invoke(
import_pseudo,
["--format", "cp2k", "--sym", "He", "--tag", "PBE", str(TEST_DIR.joinpath("GTH_POTENTIALS"))],
input="y\n",
)
assert not result.exception
result = self.cli_runner.invoke(dump_pseudo, ["--format", "cp2k", "--sym", "He"])
assert not result.exception
assert "He GTH-PBE-q2" in result.output