Python2: Add SimpleNamespace for Python 2

types.SimpleNamespace was added in Python 3.3. Reimplement it in 3
lignes to add compatibility with Python 2.7.

Related-Bug: 1726399
Change-Id: I1553a39ecbf315b5e89d3ec8070b15769cabb8d2
This commit is contained in:
Victor Stinner 2017-10-23 15:26:07 +02:00
parent 90642dd2ec
commit c2d1728dee
1 changed files with 10 additions and 2 deletions

View File

@ -23,6 +23,14 @@ from ospurge.resources.base import ServiceResource
from ospurge import utils
try:
SimpleNamespace = types.SimpleNamespace # Python 3.3+
except AttributeError:
class SimpleNamespace(object): # Python 2.7
def __init__(self, **attr):
self.__dict__.update(attr)
class TestFunctions(unittest.TestCase):
@mock.patch('logging.basicConfig', autospec=True)
def test_configure_logging_verbose(self, m_basicConfig):
@ -193,7 +201,7 @@ class TestFunctions(unittest.TestCase):
@mock.patch.object(main, 'shade')
class TestCredentialsManager(unittest.TestCase):
def test_init_with_purge_own_project(self, m_shade):
_options = types.SimpleNamespace(
_options = SimpleNamespace(
purge_own_project=True, purge_project=None)
creds_mgr = main.CredentialsManager(_options)
@ -219,7 +227,7 @@ class TestCredentialsManager(unittest.TestCase):
@mock.patch.object(utils, 'replace_project_info')
def test_init_with_purge_project(self, m_replace, m_shade):
_options = types.SimpleNamespace(
_options = SimpleNamespace(
purge_own_project=False, purge_project=mock.sentinel.purge_project)
creds_mgr = main.CredentialsManager(_options)