summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-12-11 13:44:42 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2017-12-12 05:03:45 +0100
commitdf6ee9b1222ebd81fa22ce3499e536abe7bcb05e (patch)
tree2517662ac546431a93f7c1aee1070bf55c7b29f2
parent41a81e7f5ca5d3733e6e5655f5ece7859ce9f49b (diff)
Add python3 for Functest utils
It also fixes test_utils RegexMatch and SubstrMatch. Change-Id: I124aa7d0c4110dcd2f50220aae7ba9b299799e93 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/tests/unit/test_utils.py14
-rw-r--r--functest/tests/unit/utils/test_openstack_clean.py2
-rw-r--r--functest/tests/unit/utils/test_openstack_snapshot.py2
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py5
-rw-r--r--functest/utils/functest_vacation.py6
-rw-r--r--tox.ini2
6 files changed, 19 insertions, 12 deletions
diff --git a/functest/tests/unit/test_utils.py b/functest/tests/unit/test_utils.py
index e171db022..159047649 100644
--- a/functest/tests/unit/test_utils.py
+++ b/functest/tests/unit/test_utils.py
@@ -8,16 +8,22 @@
import re
-class RegexMatch(str):
+class RegexMatch(object):
+ def __init__(self, msg):
+ self.msg = msg
+
def __eq__(self, other):
- match = re.search(self, other)
+ match = re.search(self.msg, other)
if match:
return True
return False
-class SubstrMatch(str):
+class SubstrMatch(object):
+ def __init__(self, msg):
+ self.msg = msg
+
def __eq__(self, other):
- if self in other:
+ if self.msg in other:
return True
return False
diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py
index 6ae7faa4a..d85bd2ba9 100644
--- a/functest/tests/unit/utils/test_openstack_clean.py
+++ b/functest/tests/unit/utils/test_openstack_clean.py
@@ -711,7 +711,7 @@ class OSCleanTesting(unittest.TestCase):
as mock_remove_tenants, \
mock.patch('functest.utils.openstack_clean.yaml.safe_load',
return_value=mock.Mock()), \
- mock.patch('__builtin__.open', mock.mock_open()) as m:
+ mock.patch('six.moves.builtins.open', mock.mock_open()) as m:
openstack_clean.main()
self.assertTrue(mock_remove_instances)
self.assertTrue(mock_remove_images)
diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py
index 33e74609b..919b28c6b 100644
--- a/functest/tests/unit/utils/test_openstack_snapshot.py
+++ b/functest/tests/unit/utils/test_openstack_snapshot.py
@@ -222,7 +222,7 @@ class OSSnapshotTesting(unittest.TestCase):
return_value=self.update_list), \
mock.patch('functest.utils.openstack_snapshot.get_tenants',
return_value=self.update_list), \
- mock.patch('__builtin__.open', mock.mock_open()) as m:
+ mock.patch('six.moves.builtins.open', mock.mock_open()) as m:
openstack_snapshot.main()
mock_logger_info.assert_called_once_with("Generating OpenStack "
"snapshot...")
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 307cbe37d..01085bb7d 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -365,7 +365,8 @@ class OSUtilsTesting(unittest.TestCase):
except:
pass
f = 'rc_file'
- with mock.patch('__builtin__.open', mock.mock_open(read_data=msg),
+ with mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data=msg),
create=True) as m:
m.return_value.__iter__ = lambda self: iter(self.readline, '')
openstack_utils.source_credentials(f)
@@ -1460,7 +1461,7 @@ class OSUtilsTesting(unittest.TestCase):
return_value=True), \
mock.patch('functest.utils.openstack_utils.get_image_id',
return_value=''), \
- mock.patch('__builtin__.open',
+ mock.patch('six.moves.builtins.open',
mock.mock_open(read_data='1')) as m:
self.assertEqual(openstack_utils.
create_glance_image(self.glance_client,
diff --git a/functest/utils/functest_vacation.py b/functest/utils/functest_vacation.py
index c2e40b072..71861ba7c 100644
--- a/functest/utils/functest_vacation.py
+++ b/functest/utils/functest_vacation.py
@@ -46,8 +46,8 @@ def main():
finally:
endwin()
- print '\nSnake.PY-26lines by Kris Cieslak (defaultset.blogspot.com).'
- print 'OPNFV adaptation by Functest dream team.'
+ print('\nSnake.PY-26ines by Kris Cieslak (defaultset.blogspot.com).')
+ print('OPNFV adaptation by Functest dream team.')
score = str(len(snake) - len(body) - 1)
print ('Thanks for playing, your score: %s.' % score)
- print 'Find and fix more bugs in your real OPNFV setup!\n'
+ print('Find and fix more bugs in your real OPNFV setup!\n')
diff --git a/tox.ini b/tox.ini
index 1e5487b12..328eccd21 100644
--- a/tox.ini
+++ b/tox.ini
@@ -57,7 +57,7 @@ dirs =
functest/tests/unit/ci
functest/tests/unit/core
functest/tests/unit/odl
- functest/tests/unit/utils/test_decorators.py
+ functest/tests/unit/utils
commands = nosetests {[testenv:py35]dirs}
[testenv:cover]