Coverage for gpaw/test/cli/test_basis.py: 100%
31 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1"""
2Test the `gpaw basis` subcommand.
3"""
4from __future__ import annotations
6import pathlib
7import subprocess
8import shlex
9import sys
10from collections.abc import Collection
12import pytest
14from gpaw.setup_data import search_for_file
17@pytest.mark.parametrize(
18 ('search', 'flags', 'expected_outputs'),
19 [
20 # Standard use
21 (False, None, ['H.dzp.basis', 'Cl.dzp.basis']),
22 # Search for the setup files among the installed datasets
23 (True, None, ['H.dzp.basis', 'Cl.dzp.basis']),
24 # Triple-zeta polarized functions
25 (True, '--type=tzp', ['H.tzp.basis', 'Cl.tzp.basis']),
26 # Other flags
27 (True,
28 '--name=foo --tail=.1,.2,.3 --energy=.3 --vconf-sharp-confinement',
29 ['H.foo.dzp.basis', 'Cl.foo.dzp.basis'])])
30@pytest.mark.serial
31def test_gpaw_basis_subcommand(
32 search: bool,
33 flags: str | None,
34 expected_outputs: Collection[str],
35 in_tmp_dir: pathlib.Path) -> None:
36 """
37 Test generating basis-set files with the `gpaw basis` subcommand.
38 """
39 cmd = [sys.executable, '-m', 'gpaw', '-T', 'basis']
40 setup_files = ['H.PBE', 'Cl.PBE']
41 if flags is not None:
42 cmd.extend(shlex.split(flags))
43 if search:
44 cmd.append('--search')
45 cmd.extend(setup_files)
46 else:
47 for setup in setup_files:
48 filename, _ = search_for_file(setup)
49 cmd.append(filename)
50 assert not subprocess.run(cmd).returncode
51 files = {path.name for path in in_tmp_dir.iterdir()}
52 assert files == set(expected_outputs)
55@pytest.mark.serial
56def test_old_gpaw_basis_tool(
57 in_tmp_dir: pathlib.Path) -> None:
58 """
59 Test generating basis-set files with the old `gpaw-basis` CLI tool.
60 """
61 # From atomic species
62 cmd = ['gpaw-basis',
63 '--xc', 'PBE',
64 '--name', 'myfile',
65 '--type', 'tzp',
66 '--save-setup',
67 'H', 'Cl']
68 assert not subprocess.run(cmd).returncode
69 assert ({path.name for path in in_tmp_dir.iterdir()}
70 == {'H.myfile.tzp.basis', 'Cl.myfile.tzp.basis',
71 'H.myfile.PBE', 'Cl.myfile.PBE'})
72 # From the generated PAW setups
73 assert not subprocess.run(['gpaw-basis',
74 'H.myfile.PBE', 'Cl.myfile.PBE']).returncode
75 assert ({path.name for path in in_tmp_dir.iterdir()}
76 == {'H.myfile.tzp.basis', 'Cl.myfile.tzp.basis',
77 'H.myfile.PBE', 'Cl.myfile.PBE',
78 'H.dzp.basis', 'Cl.dzp.basis'})