From d5ffb38009562f31106b3081001cf3cc5a68cdd1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20H=C3=B6nig?= <jan.hoenig@fau.de>
Date: Thu, 25 Nov 2021 09:12:08 +0100
Subject: [PATCH] WIP

---
 tests/test_benchmark.py        | 14 ++++++++------
 tests/test_benchmark_vector.py | 14 ++++++++------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py
index 63be8ff..ea2b3bc 100755
--- a/tests/test_benchmark.py
+++ b/tests/test_benchmark.py
@@ -1,14 +1,13 @@
 import subprocess
 import numpy as np
 import sympy as sp
+import tempfile
 import pystencils as ps
-from pystencils_benchmark import generate_benchmark, Compiler
 from pathlib import Path
+from pystencils_benchmark import generate_benchmark, Compiler
 
 
 def test_generate():
-    path = Path.cwd() / 'test'
-    path.mkdir(parents=True, exist_ok=True)
     a, b, c = ps.fields(a=np.ones(4000000), b=np.ones(4000000), c=np.ones(4000000))
     alpha = sp.symbols('alpha')
 
@@ -23,7 +22,10 @@ def test_generate():
     kernel_daxpy = ps.create_kernel(**daxpy)
 
     for compiler in [Compiler.GCC, Compiler.GCCdebug, Compiler.Clang]:
-        generate_benchmark([kernel_vadd, kernel_daxpy], path, compiler=compiler)
-        subprocess.run(['make', '-C', f'{path}'], check=True)
-        subprocess.run([f'{path}/benchmark-{compiler.name}', '10'], check=True)
+        with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir:
+            temp_dir = Path(temp_dir)
+            generate_benchmark([kernel_vadd, kernel_daxpy], temp_dir, compiler=compiler)
+            subprocess.run(['make', '-C', f'{temp_dir}'], check=True)
+            subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True)
+
 
diff --git a/tests/test_benchmark_vector.py b/tests/test_benchmark_vector.py
index 5f73e77..6fe2a6e 100644
--- a/tests/test_benchmark_vector.py
+++ b/tests/test_benchmark_vector.py
@@ -1,14 +1,13 @@
 import subprocess
 import numpy as np
 import sympy as sp
+import tempfile
 import pystencils as ps
-from pystencils_benchmark import generate_benchmark, Compiler
 from pathlib import Path
+from pystencils_benchmark import generate_benchmark, Compiler
 
 
 def test_generate():
-    path = Path.cwd() / 'test'
-    path.mkdir(parents=True, exist_ok=True)
     a, b, c = ps.fields(a=np.ones(4000000), b=np.ones(4000000), c=np.ones(4000000))
     alpha = sp.symbols('alpha')
 
@@ -23,7 +22,10 @@ def test_generate():
     kernel_daxpy = ps.create_kernel(**daxpy)
 
     for compiler in [Compiler.GCC, Compiler.GCCdebug, Compiler.Clang]:
-        generate_benchmark([kernel_vadd, kernel_daxpy], path, compiler=compiler)
-        subprocess.run(['make', '-C', f'{path}'], check=True)
-        subprocess.run([f'{path}/benchmark-{compiler.name}', '10'], check=True)
+        with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir:
+            temp_dir = Path(temp_dir)
+            generate_benchmark([kernel_vadd, kernel_daxpy], temp_dir, compiler=compiler)
+            subprocess.run(['make', '-C', f'{temp_dir}'], check=True)
+            subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True)
+
 
-- 
GitLab