~ubuntu-branches/debian/stretch/waagent/stretch

« back to all changes in this revision

Viewing changes to tests/tools.py

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2016-08-24 16:48:22 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20160824164822-vdf8m5xy5gycm1cz
Tags: 2.1.6-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#
15
15
# Requires Python 2.4+ and Openssl 1.0+
16
16
#
17
 
# Implements parts of RFC 2131, 1541, 1497 and
18
 
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
19
 
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
20
17
 
21
18
"""
22
19
Define util functions for unit test
23
20
"""
24
21
 
 
22
import json
 
23
import os
25
24
import re
26
 
import os
 
25
import shutil
27
26
import sys
 
27
import tempfile
28
28
import unittest
29
 
import shutil
30
 
import json
31
 
import tempfile
 
29
 
32
30
from functools import wraps
33
 
import azurelinuxagent.conf as conf
34
 
import azurelinuxagent.logger as logger
35
 
import azurelinuxagent.event as event
 
31
 
 
32
import azurelinuxagent.common.conf as conf
 
33
import azurelinuxagent.common.event as event
 
34
import azurelinuxagent.common.logger as logger
 
35
from azurelinuxagent.common.version import PY_VERSION_MAJOR
36
36
 
37
37
#Import mock module for Python2 and Python3
38
38
try:
39
 
    from unittest.mock import Mock, patch, MagicMock
 
39
    from unittest.mock import Mock, patch, MagicMock, DEFAULT, call
40
40
except ImportError:
41
 
    from mock import Mock, patch, MagicMock
 
41
    from mock import Mock, patch, MagicMock, DEFAULT, call
42
42
 
43
43
test_dir = os.path.dirname(os.path.abspath(__file__))
44
44
data_dir = os.path.join(test_dir, "data")
56
56
    def setUp(self):
57
57
        prefix = "{0}_".format(self.__class__.__name__)
58
58
        self.tmp_dir = tempfile.mkdtemp(prefix=prefix)
 
59
        conf.get_autoupdate_enabled = Mock(return_value=True)
59
60
        conf.get_lib_dir = Mock(return_value=self.tmp_dir)
60
61
        ext_log_dir = os.path.join(self.tmp_dir, "azure")
61
62
        conf.get_ext_log_dir = Mock(return_value=ext_log_dir)
 
63
        conf.get_agent_pid_file_path = Mock(return_value=os.path.join(self.tmp_dir, "waagent.pid"))
62
64
 
63
65
    def tearDown(self):
64
66
        if not debug and self.tmp_dir is not None:
98
100
 
99
101
]
100
102
 
 
103
def open_patch():
 
104
    open_name = '__builtin__.open'
 
105
    if PY_VERSION_MAJOR == 3:
 
106
        open_name = 'builtins.open'
 
107
    return open_name
 
108
 
101
109
def distros(distro_name=".*", distro_version=".*", distro_full_name=".*"):
102
110
    """Run test on multiple distros"""
103
111
    def decorator(test_method):