Skip to content

Commit 78e53fe

Browse files
committed
Fix python unit tests
1 parent c18a5d9 commit 78e53fe

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/fortran/lib/mod_tools_infile.f90

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
!!!#############################################################################
21
module raffle__tools_infile
32
!! This module contains a collection of tools for reading input files.
43
!!
@@ -20,7 +19,7 @@ module raffle__tools_infile
2019
public :: getline, rm_comments
2120
public :: assign_val, assign_vec
2221

23-
22+
2423
interface assign_val
2524
procedure assignI, assignR, assignS, assignL
2625
end interface assign_val
@@ -64,15 +63,15 @@ subroutine getline(unit, pattern, buffer)
6463
!! The pattern to grep for.
6564
character(*), intent(out) :: buffer
6665
!! The buffer to assign the line to.
67-
66+
6867
! Local variables
6968
integer :: iostat
7069
!! input output status
7170

7271
call grep(unit,pattern)
7372
backspace(unit)
7473
read(unit,'(A)',iostat=iostat) buffer
75-
74+
7675
end subroutine getline
7776
!###############################################################################
7877

test/test_raffle.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
lib_dir = os.path.join(dirname, "lib")
1818

1919
lib_ext = {
20-
"Darwin": "dylib",
21-
"Linux": "so"
20+
"Darwin": "a",
21+
"Linux": "a"
2222
}[platform.system()]
2323
libraffle_path = os.path.join(lib_dir, f"libraffle.{lib_ext}")
2424

@@ -46,6 +46,20 @@ def uses_openmp(lib_path):
4646
except Exception:
4747
return False
4848

49+
def copy_data_files():
50+
# copy test/data directory to .temp_test/test/data
51+
52+
data_dir = os.path.join(os.path.dirname(__file__), "data")
53+
os.makedirs(os.path.join(temp_test_dir, "test/data"), exist_ok=True)
54+
for file in os.listdir(data_dir):
55+
if file.endswith(".cif") or file.endswith(".xyz") or file.endswith(".vasp") or file.startswith("POSCAR"):
56+
src = os.path.join(data_dir, file)
57+
dst = os.path.join(temp_test_dir, "test/data", file)
58+
print(f"Copying {src} to {dst}")
59+
with open(src, "rb") as fsrc:
60+
with open(dst, "wb") as fdst:
61+
fdst.write(fsrc.read())
62+
4963
def build_fortran_test(test_name):
5064
os.makedirs(temp_test_dir, exist_ok=True)
5165
# make using a fortran compiler
@@ -58,13 +72,13 @@ def build_fortran_test(test_name):
5872

5973
compile_list = [
6074
fc, "-o", test_name+".o",
61-
"../../test/test_io_utils.f90",
62-
" ".join(compile_args),
75+
"../../test/test_"+test_name+".f90",
6376
"-I", include_dir,
6477
"-I", etc_dir,
6578
"-L", lib_dir,
66-
"-lraffle"
79+
"-lraffle",
6780
]
81+
compile_list += compile_args
6882
build_result = subprocess.run(
6983
compile_list,
7084
cwd=temp_test_dir
@@ -285,6 +299,7 @@ def test_print_settings(self):
285299

286300
class TestFortranUnits(unittest.TestCase):
287301

302+
copy_data_files()
288303
@parameterized.expand([(test_name) for test_name in test_names])
289304
def test_fortran(self, test_name):
290305
build_result = build_fortran_test(test_name)

0 commit comments

Comments
 (0)