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
This commit is contained in:
Lucas Alvares Gomes 2016-12-05 12:12:17 +00:00
parent 89345c62c5
commit ca8239860b
3 changed files with 5 additions and 4 deletions

View File

@ -1,7 +1,7 @@
[tox]
minversion = 1.8
skipsdist = True
envlist = py34,py27,pep8
envlist = py35,py34,py27,pep8
[testenv]
usedevelop = True

View File

@ -12,6 +12,7 @@
class VirtualBMCError(Exception):
message = None
def __init__(self, message=None, **kwargs):
if self.message and kwargs:

View File

@ -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')