aboutsummaryrefslogtreecommitdiff
path: root/test/test_general.py
blob: eb3185d89f15d78548729bb5fd3f8e3d8e85f443 (plain)
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
import subprocess
import unittest

from tempfile import TemporaryDirectory

class SalisTest(unittest.TestCase):
    def setUp(self):
        self.tempdir = TemporaryDirectory(prefix="salis_test_")

    def tearDown(self):
        self.tempdir.cleanup()

    @staticmethod
    def run_subprocess(cmd):
        subprocess.run(cmd.split(), check=True, stdout=subprocess.DEVNULL)

    @staticmethod
    def run_pipe(cmd):
        return subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, text=True)

    @staticmethod
    def run_ui_test(anc, anc_path, ui, ui_path, vm_arch, clones=1, cores=1, name="def.sim"):
        def test_decorator(test_case):
            def test_wrapper(self):
                cmd = f"./salis.py new -a{anc} -A{anc_path} -C{clones} -c{cores} -H{self.tempdir.name} -n{name} -u{ui} -U{ui_path} -v{vm_arch}"
                subprocess.run(cmd.split(), check=True, stdout=subprocess.DEVNULL)
                test_case(self)

            return test_wrapper

        return test_decorator