From ca8239860bec561a898d33c9e4d5ab6aef6a3364 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Mon, 5 Dec 2016 12:12:17 +0000 Subject: [PATCH] Fix Python3 test errors This patch is fixing few errors related to Python3 and tests: * Add the attribute "message" to the exception because it doesn't exist by default. * Add the py35 runtime to tox.ini since we now run tests on Python3.5 * Drop the spec=file syntax because "file" is not a builtin type for Python3. Change-Id: I31d1a5719d605974912bc26f65b96734631691d5 Closes-Bug: #1647337 --- tox.ini | 2 +- virtualbmc/exception.py | 1 + virtualbmc/tests/unit/test_manager.py | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index bf7073a..6bb0ef9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] minversion = 1.8 skipsdist = True -envlist = py34,py27,pep8 +envlist = py35,py34,py27,pep8 [testenv] usedevelop = True diff --git a/virtualbmc/exception.py b/virtualbmc/exception.py index 8abc29c..1c52fde 100644 --- a/virtualbmc/exception.py +++ b/virtualbmc/exception.py @@ -12,6 +12,7 @@ class VirtualBMCError(Exception): + message = None def __init__(self, message=None, **kwargs): if self.message and kwargs: diff --git a/virtualbmc/tests/unit/test_manager.py b/virtualbmc/tests/unit/test_manager.py index 1aa32bb..961fc11 100644 --- a/virtualbmc/tests/unit/test_manager.py +++ b/virtualbmc/tests/unit/test_manager.py @@ -86,7 +86,7 @@ class VirtualBMCManagerTestCase(base.TestCase): def _test__show(self, mock__parse, mock_pid, mock_open, expected=None): mock_pid.return_value = True mock__parse.return_value = self.domain0 - f = mock.MagicMock(spec=file) + f = mock.MagicMock() f.read.return_value = self.domain0['port'] mock_open.return_value.__enter__.return_value = f @@ -212,7 +212,7 @@ class VirtualBMCManagerTestCase(base.TestCase): @mock.patch.object(os.path, 'exists') def test_stop(self, mock_exists, mock_remove, mock_kill, mock_open): mock_exists.return_value = True - f = mock.MagicMock(spec=file) + f = mock.MagicMock() f.read.return_value = self.domain0['port'] mock_open.return_value.__enter__.return_value = f @@ -234,7 +234,7 @@ class VirtualBMCManagerTestCase(base.TestCase): @mock.patch.object(os.path, 'exists') def test_stop_pid_file_not_found(self, mock_exists, mock_open): mock_exists.return_value = True - f = mock.MagicMock(spec=file) + f = mock.MagicMock() f.read.return_value = self.domain0['port'] mock_open.return_value.__enter__.side_effect = IOError('boom')