Fix shell tests for older prettytable versions.

Fix the shell tests so they pass for all supported prettytable
versions, as per requirements.txt (>=0.6,<0.8).

Fixes bug: #1185580.

Change-Id: I8dca23faa3c178494656ebc8088b6d1994e9869f
This commit is contained in:
Adam Gandelman 2013-05-29 14:20:43 -07:00
parent 1bb9824808
commit def5df2760
1 changed files with 16 additions and 5 deletions

View File

@ -1,7 +1,10 @@
import cStringIO
import prettytable
import re
import sys
from distutils.version import StrictVersion
import fixtures
import mock
from testtools import matchers
@ -148,13 +151,21 @@ class ShellTest(utils.TestCase):
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
@mock.patch('getpass.getpass', return_value='password')
def test_password(self, mock_getpass, mock_stdin):
# default output of empty tables differs depending between prettytable
# versions
if (hasattr(prettytable, '__version__') and
StrictVersion(prettytable.__version__) < StrictVersion('0.7.2')):
ex = '\n'
else:
ex = (
'+----+------+--------+------------+-------------+----------+\n'
'| ID | Name | Status | Task State | Power State | Networks |\n'
'+----+------+--------+------------+-------------+----------+\n'
'+----+------+--------+------------+-------------+----------+\n'
)
self.make_env(exclude='OS_PASSWORD')
stdout, stderr = self.shell('list')
self.assertEqual((stdout + stderr),
'+----+------+--------+------------+-------------+----------+\n'
'| ID | Name | Status | Task State | Power State | Networks |\n'
'+----+------+--------+------------+-------------+----------+\n'
'+----+------+--------+------------+-------------+----------+\n')
self.assertEqual((stdout + stderr), ex)
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
@mock.patch('getpass.getpass', side_effect=EOFError)