Skip to content

Commit f122f29

Browse files
committed
Apply ruff fixes
1 parent 8f8e3fd commit f122f29

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

abcd/parsers/extras.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def string(self, s):
9797
if __name__ == "__main__":
9898
test_string = " ".join(
9999
[
100-
" " "flag", # start with a separator
100+
" flag", # start with a separator
101101
'quotedd_string="quoteddd value"',
102102
r'quotedddd_string_escaped="esc\"aped"',
103103
"false_value = F",

tests/hash.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import io
2+
3+
import ase
4+
from ase.calculators.lj import LennardJones
5+
import ase.io
6+
import numpy as np
7+
import pytest
8+
9+
from abcd.model import AbstractModel
10+
11+
12+
@pytest.fixture
13+
def rng():
14+
return np.random.default_rng(seed=42)
15+
16+
17+
def test_hash_structure(rng):
18+
# create atoms & add a calculator
19+
atoms = ase.Atoms(
20+
"H3",
21+
positions=rng.random(size=(3, 3)),
22+
pbc=True,
23+
cell=[2, 2, 2],
24+
)
25+
atoms.calc = LennardJones()
26+
atoms.calc.calculate(atoms)
27+
28+
# dump to XYZ
29+
buffer = io.StringIO()
30+
ase.io.write(buffer, atoms, format="extxyz")
31+
32+
# read back
33+
buffer.seek(0)
34+
atoms_read = ase.io.read(buffer, format="extxyz")
35+
assert atoms.positions[0, 0] == pytest.approx(atoms_read.positions[0, 0], abs=1e-10)
36+
37+
# read in both of them
38+
abcd_data = AbstractModel.from_atoms(atoms)
39+
abcd_data_after_read = AbstractModel.from_atoms(atoms_read)
40+
41+
assert atoms_read.positions[0, 0:5] == pytest.approx(
42+
atoms.positions[0, 0:5], abs=1e-10
43+
)
44+
assert abcd_data["hash_structure"] == abcd_data_after_read["hash_structure"], (
45+
atoms.positions,
46+
atoms_read.positions,
47+
)

tests/test_abstract_model.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,29 +229,29 @@ def test_write_and_read(store_calc):
229229
"calculator_name",
230230
"calculator_parameters",
231231
}:
232-
assert (
233-
abcd_data[key] == abcd_data_after_read[key]
234-
), f"{key}'s value does not match"
232+
assert abcd_data[key] == abcd_data_after_read[key], (
233+
f"{key}'s value does not match"
234+
)
235235

236236
# date & hashed will differ
237237
for key in set(abcd_data.derived_keys) - {
238238
"hash",
239239
"modified",
240240
"uploaded",
241241
}:
242-
assert (
243-
abcd_data[key] == abcd_data_after_read[key]
244-
), f"{key}'s value does not match"
242+
assert abcd_data[key] == abcd_data_after_read[key], (
243+
f"{key}'s value does not match"
244+
)
245245

246246
# expected differences - n.b. order of calls above
247247
assert abcd_data_after_read["modified"] > abcd_data["modified"]
248248
assert abcd_data_after_read["uploaded"] > abcd_data["uploaded"]
249249

250250
# expect results to match within fp precision
251251
for key in set(abcd_data.results_keys):
252-
assert abcd_data[key] == approx(
253-
np.array(abcd_data_after_read[key])
254-
), f"{key}'s value does not match"
252+
assert abcd_data[key] == approx(np.array(abcd_data_after_read[key])), (
253+
f"{key}'s value does not match"
254+
)
255255

256256

257257
def test_hash_update():

tests/test_parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_composite(self, parser):
140140
'a3x3_array="1 4 7 2 5 8 3 6 9" ' # fortran ordering
141141
'Lattice=" 4.3 0.0 0.0 0.0 3.3 0.0 0.0 0.0 7.0 " ' # spaces in array
142142
'comma_separated="7, 4, -1"',
143-
'array_boolean_2=" T, F, T " ' 'not_array="1.2 3.4 text"', # leading spaces
143+
'array_boolean_2=" T, F, T " not_array="1.2 3.4 text"', # leading spaces
144144
"not_bool_array=[T F S]",
145145
],
146146
)

0 commit comments

Comments
 (0)