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:
parent
89345c62c5
commit
ca8239860b
2
tox.ini
2
tox.ini
@ -1,7 +1,7 @@
|
|||||||
[tox]
|
[tox]
|
||||||
minversion = 1.8
|
minversion = 1.8
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
envlist = py34,py27,pep8
|
envlist = py35,py34,py27,pep8
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class VirtualBMCError(Exception):
|
class VirtualBMCError(Exception):
|
||||||
|
message = None
|
||||||
|
|
||||||
def __init__(self, message=None, **kwargs):
|
def __init__(self, message=None, **kwargs):
|
||||||
if self.message and kwargs:
|
if self.message and kwargs:
|
||||||
|
@ -86,7 +86,7 @@ class VirtualBMCManagerTestCase(base.TestCase):
|
|||||||
def _test__show(self, mock__parse, mock_pid, mock_open, expected=None):
|
def _test__show(self, mock__parse, mock_pid, mock_open, expected=None):
|
||||||
mock_pid.return_value = True
|
mock_pid.return_value = True
|
||||||
mock__parse.return_value = self.domain0
|
mock__parse.return_value = self.domain0
|
||||||
f = mock.MagicMock(spec=file)
|
f = mock.MagicMock()
|
||||||
f.read.return_value = self.domain0['port']
|
f.read.return_value = self.domain0['port']
|
||||||
mock_open.return_value.__enter__.return_value = f
|
mock_open.return_value.__enter__.return_value = f
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class VirtualBMCManagerTestCase(base.TestCase):
|
|||||||
@mock.patch.object(os.path, 'exists')
|
@mock.patch.object(os.path, 'exists')
|
||||||
def test_stop(self, mock_exists, mock_remove, mock_kill, mock_open):
|
def test_stop(self, mock_exists, mock_remove, mock_kill, mock_open):
|
||||||
mock_exists.return_value = True
|
mock_exists.return_value = True
|
||||||
f = mock.MagicMock(spec=file)
|
f = mock.MagicMock()
|
||||||
f.read.return_value = self.domain0['port']
|
f.read.return_value = self.domain0['port']
|
||||||
mock_open.return_value.__enter__.return_value = f
|
mock_open.return_value.__enter__.return_value = f
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ class VirtualBMCManagerTestCase(base.TestCase):
|
|||||||
@mock.patch.object(os.path, 'exists')
|
@mock.patch.object(os.path, 'exists')
|
||||||
def test_stop_pid_file_not_found(self, mock_exists, mock_open):
|
def test_stop_pid_file_not_found(self, mock_exists, mock_open):
|
||||||
mock_exists.return_value = True
|
mock_exists.return_value = True
|
||||||
f = mock.MagicMock(spec=file)
|
f = mock.MagicMock()
|
||||||
f.read.return_value = self.domain0['port']
|
f.read.return_value = self.domain0['port']
|
||||||
mock_open.return_value.__enter__.side_effect = IOError('boom')
|
mock_open.return_value.__enter__.side_effect = IOError('boom')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user