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 files_on_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_equal(self, v1, v2): assert v1 == v2, f"{v1} != {v2}" 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, mvec_pow=20, name="def.sim", data_push_pow=28, sync_pow=20, **kwargs): def test_decorator(test_case): def test_wrapper(self): cmd = f"./salis.py new -a{anc} -A{anc_path} -C{clones} -c{cores} -d{data_push_pow} -H{self.tempdir.name} -m{mvec_pow} -n{name} -u{ui} -U{ui_path} -v{vm_arch} -y{sync_pow}" subprocess.run(cmd.split(), check=True, stdout=subprocess.DEVNULL) self.assert_file_list_exists(self.files_on_new(name)) test_case(self) return test_wrapper return test_decorator