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
|
"""Test input file READ section parsing."""
import logging
import pytest
from apbs.input_file.read import Read
_LOGGER = logging.getLogger(__name__)
GOOD_INPUT = [
"""# Typical input with PQR molecules
molecules:
- alias: molecule 1
format: pqr
path: mol1.pqr
- alias: molecule 2
format: pqr
path: mol2.pqr
- alias: complex between 1 & 2
format: pqr
path: complex.pqr
""",
"""# PDB input with parameter file
molecules:
- alias: molecule 1
format: pdb
path: mol1.pdb
- alias: molecule 2
format: pdb
path: mol2.pdb
- alias: the complex
format: pdb
path: mol1.pdb
parameters:
- alias: my parameters
format: flat
path: custom_parms.txt
""",
"""# PQR input with map for boundary conditions
molecules:
- alias: molecule
format: pqr
path: mol.pqr
potential maps:
- alias: potential
format: dx
path: potential.dx
""",
"""# All-map input
charge density maps:
- alias: charge density
format: dx
path: charge.dx
ion accessibility maps:
- alias: ion accessibility
format: dx
path: ions.dx
dielectric maps:
- alias: the dielectric maps
format: dx
x-shifted path: dielx.dx
y-shifted path: diely.dx
z-shifted path: dielz.dx
""",
]
BAD_INPUT = [
"""# Typical input with PQR molecules with BAD format
molecules:
- alias: molecule 1
format: BAD
path: mol1.pqr
- alias: molecule 2
format: pqr
path: mol2.pqr
- alias: complex between 1 & 2
format: pqr
path: complex.pqr
""",
"""# PDB input WITHOUT parameter file
molecules:
- alias: molecule 1
format: pdb
path: mol1.pdb
- alias: molecule 2
format: pdb
path: mol2.pdb
- alias: the complex
format: pdb
path: mol1.pdb
""",
"""# PQR input with map for boundary conditions WITHOUT path
molecules:
- alias: molecule
format: pqr
path: mol.pqr
potential maps:
- alias: potential
format: dx
""",
"""# All-map input with MISSING path
charge density maps:
- alias: charge density
format: dx
path: charge.dx
ion accessibility maps:
- alias: ion accessibility
format: dx
path: ions.dx
dielectric maps:
- alias: the dielectric maps
format: dx
x-shifted path: dielx.dx
z-shifted path: dielz.dx
""",
]
def id_function(test_string) -> str:
"""Turn test strings into labels."""
label = test_string.splitlines()[0]
return label[2:]
@pytest.mark.parametrize("input_", GOOD_INPUT, ids=id_function)
def test_good_input(input_):
"""Test input file READ sections."""
read = Read()
_LOGGER.debug(f"YAML input: {input_}")
read.from_yaml(input_)
read.validate()
new_dict = read.to_dict()
_LOGGER.debug(f"Object dictionary: {new_dict}")
read.from_dict(new_dict)
read.validate()
@pytest.mark.parametrize("input_", BAD_INPUT, ids=id_function)
def test_bad_input(input_):
"""Test input file READ sections."""
with pytest.raises((KeyError, ValueError)):
read = Read()
_LOGGER.debug(input_)
read.from_yaml(input_)
read.validate()
|