aboutsummaryrefslogtreecommitdiff
path: root/test/test_general.py
blob: 43f3635cac57a41d646d3aef38c04d42b3bf4050 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
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()

    def file_list_new(self, name):
        return [
            os.path.join(self.tempdir.name, name, name),
            os.path.join(self.tempdir.name, name, f"{name}.sqlite3"),
            os.path.join(self.tempdir.name, name, f"{name}-{0:016x}"),
            os.path.join(self.tempdir.name, name, "opts.json"),
            os.path.join(self.tempdir.name, name, "evas", f"evas-{0:016x}"),
        ]

    def assert_file_list_exists(self, files):
        for file in files:
            assert os.path.isfile(file), f"{file} does not exist"

    @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)
                self.assert_file_list_exists(self.file_list_new(name))
                test_case(self)

            return test_wrapper

        return test_decorator