Skip to content

Commit

Permalink
fix issue with temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
alchem0x2A committed Jan 19, 2024
1 parent 2cc02c6 commit d3c2feb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sparc/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
ase.io.trajectory
"""
import itertools
import os
import re
from pathlib import Path
from warnings import warn

Expand Down Expand Up @@ -336,7 +338,14 @@ def read_raw_results(self, include_all_files=False):
self.raw_results (dict or List): the same as the return value
"""
# Find the max output index
last_out = sorted(self.directory.glob(f"{self.label}.out*"), reverse=True)
out_files = self.directory.glob(f"{self.label}.out*")
valid_out_files = [
f
for f in out_files
if (re.fullmatch(r"^\.out(?:_\d+)?$", f.suffix) is not None)
]
# Combine and sort the file lists
last_out = sorted(valid_out_files, reverse=True)
# No output file, only ion / inpt
if len(last_out) == 0:
self.last_image = -1
Expand Down
15 changes: 15 additions & 0 deletions tests/test_bundle_to_calc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import tempfile
from pathlib import Path

Expand All @@ -11,6 +12,20 @@
test_output_dir = curdir / "outputs"


def test_files_glob():
"""Only match the re part"""
pattern = r"^\.out(?:_\d+)?$"
assert re.fullmatch(pattern, ".out")
assert re.fullmatch(pattern, ".out_0")
assert re.fullmatch(pattern, ".out_01")
assert re.fullmatch(pattern, ".out_009")
assert re.fullmatch(pattern, ".out_") is None
assert re.fullmatch(pattern, ".out_00_") is None
assert re.fullmatch(pattern, ".out#") is None
assert re.fullmatch(pattern, ".out~") is None
assert re.fullmatch(pattern, ".out_01~") is None


def test_bundle_convert():
from sparc.io import SparcBundle

Expand Down

0 comments on commit d3c2feb

Please sign in to comment.