diff --git a/common/test/test_applicationinstance.py b/common/test/test_applicationinstance.py index 19b99cd60..3f090a2ac 100644 --- a/common/test/test_applicationinstance.py +++ b/common/test/test_applicationinstance.py @@ -21,7 +21,7 @@ from unittest.mock import patch from threading import Thread -from test import generic, utils +from test import generic sys.path.append(os.path.join(os.path.dirname(__file__), "..")) @@ -70,7 +70,10 @@ def _createProcess(self): return self.subproc.pid def _killProcess(self): - utils.kill_subprocess(self.subproc) + if self.subproc: + subproc = self.subproc + subproc.kill() + subproc.wait() self.subproc = None def test_create_and_remove_pid_file(self): diff --git a/common/test/test_config_crontab.py b/common/test/test_config_crontab.py index 2a1d6f4b7..8eaa11bfa 100644 --- a/common/test/test_config_crontab.py +++ b/common/test/test_config_crontab.py @@ -18,17 +18,19 @@ See also test_schedule.py for low-level-Cron-behavior implemented in schedule module.""" -import unittest -import sys +import inspect import os +import sys import tempfile -import inspect +import unittest from pathlib import Path from unittest import mock + import pyfakefs.fake_filesystem_unittest as pyfakefs_ut + sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + import config -from test import utils class Cron(unittest.TestCase): @@ -81,7 +83,26 @@ def setUp(self): def _create_config_file(self, parent_path): """Minimal config file""" - config_data = utils.config_template.format( + config_data = """ + config.version={config_version} + profile1.snapshots.include.1.type={snapshot_type} + profile1.snapshots.include.1.value={snapshot_value} + profile1.snapshots.include.size={snapshot_size} + profile1.snapshots.no_on_battery={no_on_battery} + profile1.snapshots.notify.enabled={notify_enabled} + profile1.snapshots.path={snapshot_path} + profile1.snapshots.path.host={snapshot_host} + profile1.snapshots.path.profile={snapshot_profile} + profile1.snapshots.path.user={snapshot_user} + profile1.snapshots.preserve_acl={preserve_acl} + profile1.snapshots.preserve_xattr={preserve_xattr} + profile1.snapshots.remove_old_snapshots.enabled={remove_old_snapshots_enabled} + profile1.snapshots.remove_old_snapshots.unit={remove_old_snapshots_unit} + profile1.snapshots.remove_old_snapshots.value={remove_old_snapshots_value} + profile1.snapshots.rsync_options.enabled={rsync_options_enabled} + profile1.snapshots.rsync_options.value={rsync_options_value} + profiles.version={profiles_version} + """.format( config_version=6, snapshot_type=0, snapshot_value='rootpath/source', diff --git a/common/test/test_plugin_usercallback.py b/common/test/test_plugin_usercallback.py index e08ed3585..bca0f0cdf 100644 --- a/common/test/test_plugin_usercallback.py +++ b/common/test/test_plugin_usercallback.py @@ -1,21 +1,21 @@ -import sys import inspect -import tempfile -import stat import io +import stat +import sys +import tempfile import unittest import unittest.mock as mock -from pathlib import Path from ast import literal_eval -from contextlib import redirect_stdout, redirect_stderr +from contextlib import redirect_stderr, redirect_stdout +from pathlib import Path # This workaround will become obsolet when migrating to src-layout sys.path.append(str(Path(__file__).parent)) sys.path.append(str(Path(__file__).parent / 'plugins')) + import pluginmanager from config import Config -from test import utils -from snapshots import Snapshots, SID +from snapshots import SID, Snapshots from usercallbackplugin import UserCallbackPlugin @@ -209,7 +209,26 @@ def _create_source_and_destination_folders(cls, parent_path): @classmethod def _create_config_file(cls, parent_path): """Minimal config file""" - config_data = utils.config_template.format( + config_data = """ + config.version={config_version} + profile1.snapshots.include.1.type={snapshot_type} + profile1.snapshots.include.1.value={snapshot_value} + profile1.snapshots.include.size={snapshot_size} + profile1.snapshots.no_on_battery={no_on_battery} + profile1.snapshots.notify.enabled={notify_enabled} + profile1.snapshots.path={snapshot_path} + profile1.snapshots.path.host={snapshot_host} + profile1.snapshots.path.profile={snapshot_profile} + profile1.snapshots.path.user={snapshot_user} + profile1.snapshots.preserve_acl={preserve_acl} + profile1.snapshots.preserve_xattr={preserve_xattr} + profile1.snapshots.remove_old_snapshots.enabled={remove_old_snapshots_enabled} + profile1.snapshots.remove_old_snapshots.unit={remove_old_snapshots_unit} + profile1.snapshots.remove_old_snapshots.value={remove_old_snapshots_value} + profile1.snapshots.rsync_options.enabled={rsync_options_enabled} + profile1.snapshots.rsync_options.value={rsync_options_value} + profiles.version={profiles_version} + """.format( config_version=6, snapshot_type=0, snapshot_value=f'{parent_path}/{cls.NAME_SOURCE}', diff --git a/common/test/test_tools.py b/common/test/test_tools.py index 06b99497f..c21c8b615 100644 --- a/common/test/test_tools.py +++ b/common/test/test_tools.py @@ -29,7 +29,7 @@ from unittest.mock import patch from tempfile import NamedTemporaryFile, TemporaryDirectory import pyfakefs.fake_filesystem_unittest as pyfakefs_ut -from test import generic, utils +from test import generic sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import tools @@ -95,7 +95,9 @@ def _create_process(self, *args): return self.subproc.pid def _kill_process(self): - utils.kill_subprocess(self.subproc) + if self.subproc: + self.subproc.kill() + self.subproc.wait() self.subproc = None def test_sharePath(self): diff --git a/common/test/utils.py b/common/test/utils.py deleted file mode 100644 index c7ac530e1..000000000 --- a/common/test/utils.py +++ /dev/null @@ -1,29 +0,0 @@ -"""Utilities for testing""" - -config_template = """ - config.version=6 - profile1.snapshots.include.1.type={snapshot_type} - profile1.snapshots.include.1.value={snapshot_value} - profile1.snapshots.include.size={snapshot_size} - profile1.snapshots.no_on_battery={no_on_battery} - profile1.snapshots.notify.enabled={notify_enabled} - profile1.snapshots.path={snapshot_path} - profile1.snapshots.path.host={snapshot_host} - profile1.snapshots.path.profile={snapshot_profile} - profile1.snapshots.path.user={snapshot_user} - profile1.snapshots.preserve_acl={preserve_acl} - profile1.snapshots.preserve_xattr={preserve_xattr} - profile1.snapshots.remove_old_snapshots.enabled={remove_old_snapshots_enabled} - profile1.snapshots.remove_old_snapshots.unit={remove_old_snapshots_unit} - profile1.snapshots.remove_old_snapshots.value={remove_old_snapshots_value} - profile1.snapshots.rsync_options.enabled={rsync_options_enabled} - profile1.snapshots.rsync_options.value={rsync_options_value} - profiles.version={profiles_version} - """ - - -def kill_subprocess(proc): - """Kill a process and wait for it to terminate.""" - if proc: - proc.kill() - proc.wait()