diff options
Diffstat (limited to 'tests/tools.py')
-rw-r--r-- | tests/tools.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/tools.py b/tests/tools.py index 94fab7f..5c65847 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -26,17 +26,20 @@ import tempfile import unittest from functools import wraps +import time + import azurelinuxagent.common.event as event import azurelinuxagent.common.conf as conf import azurelinuxagent.common.logger as logger +from azurelinuxagent.common.utils import fileutil from azurelinuxagent.common.version import PY_VERSION_MAJOR -#Import mock module for Python2 and Python3 +# Import mock module for Python2 and Python3 try: - from unittest.mock import Mock, patch, MagicMock, DEFAULT, call + from unittest.mock import Mock, patch, MagicMock, DEFAULT, ANY, call except ImportError: - from mock import Mock, patch, MagicMock, DEFAULT, call + from mock import Mock, patch, MagicMock, DEFAULT, ANY, call test_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(test_dir, "data") @@ -45,11 +48,12 @@ debug = False if os.environ.get('DEBUG') == '1': debug = True -#Enable verbose logger to stdout +# Enable verbose logger to stdout if debug: logger.add_logger_appender(logger.AppenderType.STDOUT, logger.LogLevel.VERBOSE) + class AgentTestCase(unittest.TestCase): def setUp(self): prefix = "{0}_".format(self.__class__.__name__) @@ -72,12 +76,20 @@ class AgentTestCase(unittest.TestCase): if not debug and self.tmp_dir is not None: shutil.rmtree(self.tmp_dir) + def _create_files(self, tmp_dir, prefix, suffix, count, with_sleep=0): + for i in range(count): + f = os.path.join(tmp_dir, '.'.join((prefix, str(i), suffix))) + fileutil.write_file(f, "faux content") + time.sleep(with_sleep) + + def load_data(name): """Load test data""" path = os.path.join(data_dir, name) with open(path, "r") as data_file: return data_file.read() + def load_bin_data(name): """Load test bin data""" path = os.path.join(data_dir, name) @@ -106,12 +118,14 @@ supported_distro = [ ] + def open_patch(): open_name = '__builtin__.open' if PY_VERSION_MAJOR == 3: open_name = 'builtins.open' return open_name + def distros(distro_name=".*", distro_version=".*", distro_full_name=".*"): """Run test on multiple distros""" def decorator(test_method): @@ -128,8 +142,8 @@ def distros(distro_name=".*", distro_version=".*", distro_full_name=".*"): new_args.extend(args) new_args.extend(distro) test_method(self, *new_args, **kwargs) - #Call tearDown and setUp to create seprated environment for - #distro testing + # Call tearDown and setUp to create separated environment + # for distro testing self.tearDown() self.setUp() return wrapper |