File: test_cif2cell.py

package info (click to toggle)
cif2cell 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 14,676 kB
  • sloc: python: 19,624; makefile: 18
file content (54 lines) | stat: -rw-r--r-- 1,723 bytes parent folder | download | duplicates (4)
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
"""Tests for cif2cell."""
from pathlib import Path
import subprocess
import platform
import os
import pytest

TEST_DIR = Path(__file__).resolve().parent
CIFS_DIR = TEST_DIR.parent / 'cifs'
CIF_FILES = CIFS_DIR.glob('*.cif')
CIF2CELL_SCRIPT = TEST_DIR.parent / 'binaries' / 'cif2cell'

def run_cif2cell(args):
    if platform.system() == 'Windows':
        # windows does not understand the shebang
        cmd = ["python.exe", CIF2CELL_SCRIPT] + args
    else:
        cmd = [ CIF2CELL_SCRIPT ] + args

    try:
        # Setting the PYTHONIOENCODING was necessary for windows runners on GitHub action
        result = subprocess.check_output(
            cmd,
            stderr=subprocess.STDOUT,
            env=dict(os.environ, PYTHONIOENCODING='utf8'),
            encoding='utf8')
        return result
    except subprocess.CalledProcessError as exc:
        raise EnvironmentError(result) from exc


@pytest.mark.parametrize("cif_file", CIF_FILES)
def test_parse(cif_file):
    """Test running cif2cell on each CIF file in /cifs."""
    result = run_cif2cell([cif_file])

    assert not "***Warning: Space group operation check failed" in result
    assert not "Error" in result

def test_vasp():
    """Test VASP output."""
    cif_file = CIFS_DIR / "SiC.cif"
    result = run_cif2cell(["-p", "vasp", "-f", cif_file])
    assert not "***Warning: Space group operation check failed" in result
    assert not "Error" in result
    assert Path("POSCAR").exists()

def test_castep():
    """Test CASTEP output."""
    cif_file = CIFS_DIR / "SiC.cif"
    result = run_cif2cell(["-p", "castep", "-f", cif_file])

    assert not "***Warning: Space group operation check failed" in result
    assert not "Error" in result