Fixed pep8 errors in test directory.

Files test_swiftclient.py and utils.py had all pep8 errors
fixed.

Also added tests directory to tox.ini file, so that
pep8 would monitor tests directory by default.

Change-Id: Id60a2cd88bd814d1dcbeca951764c9d236500837
Fixes: bug #1158819
This commit is contained in:
jola-mirecka
2013-03-22 14:59:57 +00:00
parent 4f57f815b3
commit 8ea9c4aae8
3 changed files with 27 additions and 33 deletions

View File

@@ -47,7 +47,7 @@ class TestClientException(testtools.TestCase):
) )
for value in test_kwargs: for value in test_kwargs:
kwargs = { kwargs = {
'http_%s' % value: value, 'http_%s' % value: value,
} }
exc = c.ClientException('test', **kwargs) exc = c.ClientException('test', **kwargs)
self.assertTrue(value in str(exc)) self.assertTrue(value in str(exc))
@@ -71,7 +71,6 @@ class TestJsonImport(testtools.TestCase):
reload(simplejson) reload(simplejson)
super(TestJsonImport, self).tearDown() super(TestJsonImport, self).tearDown()
def test_any(self): def test_any(self):
self.assertTrue(hasattr(c, 'json_loads')) self.assertTrue(hasattr(c, 'json_loads'))
@@ -119,7 +118,6 @@ class MockHttpTest(testtools.TestCase):
def setUp(self): def setUp(self):
super(MockHttpTest, self).setUp() super(MockHttpTest, self).setUp()
def fake_http_connection(*args, **kwargs): def fake_http_connection(*args, **kwargs):
_orig_http_connection = c.http_connection _orig_http_connection = c.http_connection
return_read = kwargs.get('return_read') return_read = kwargs.get('return_read')
@@ -210,7 +208,7 @@ class TestGetAuth(MockHttpTest):
self.assertEquals(token, None) self.assertEquals(token, None)
def test_auth_v2(self): def test_auth_v2(self):
os_options={'tenant_name': 'asdf'} os_options = {'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options, os_options=os_options,
@@ -245,9 +243,9 @@ class TestGetAuth(MockHttpTest):
self.assertTrue(token) self.assertTrue(token)
def test_auth_v2_with_os_options(self): def test_auth_v2_with_os_options(self):
os_options={'service_type': 'object-store', os_options = {'service_type': 'object-store',
'endpoint_type': 'internalURL', 'endpoint_type': 'internalURL',
'tenant_name': 'asdf'} 'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options, os_options=os_options,
@@ -259,13 +257,13 @@ class TestGetAuth(MockHttpTest):
tenant_option = {'tenant_name': 'foo'} tenant_option = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option) c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option)
url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf', url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf',
auth_version="2.0") auth_version="2.0")
self.assertTrue(url.startswith("http")) self.assertTrue(url.startswith("http"))
self.assertTrue(token) self.assertTrue(token)
def test_auth_v2_with_os_region_name(self): def test_auth_v2_with_os_region_name(self):
os_options={'region_name': 'good-region', os_options = {'region_name': 'good-region',
'tenant_name': 'asdf'} 'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options, os_options=os_options,
@@ -274,19 +272,17 @@ class TestGetAuth(MockHttpTest):
self.assertTrue(token) self.assertTrue(token)
def test_auth_v2_no_endpoint(self): def test_auth_v2_no_endpoint(self):
os_options={'region_name': 'unknown_region', os_options = {'region_name': 'unknown_region',
'tenant_name': 'asdf'} 'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0( c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options, os_options, c.ClientException)
c.ClientException)
self.assertRaises(c.ClientException, c.get_auth, self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf', 'http://www.tests.com', 'asdf', 'asdf',
os_options=os_options, auth_version='2.0') os_options=os_options, auth_version='2.0')
def test_auth_v2_ks_exception(self): def test_auth_v2_ks_exception(self):
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0( c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
{}, {}, c.ClientException)
c.ClientException)
self.assertRaises(c.ClientException, c.get_auth, self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf', 'http://www.tests.com', 'asdf', 'asdf',
os_options={}, os_options={},
@@ -295,10 +291,9 @@ class TestGetAuth(MockHttpTest):
def test_auth_v2_cacert(self): def test_auth_v2_cacert(self):
os_options = {'tenant_name': 'foo'} os_options = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0( c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options, os_options, None)
None)
auth_url_secure = 'https://www.tests.com' auth_url_secure = 'https://www.tests.com'
auth_url_insecure = 'https://www.tests.com/self-signed-certificate' auth_url_insecure = 'https://www.tests.com/self-signed-certificate'
url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf', url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf',
@@ -324,10 +319,9 @@ class TestGetAuth(MockHttpTest):
def test_auth_v2_insecure(self): def test_auth_v2_insecure(self):
os_options = {'tenant_name': 'foo'} os_options = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0( c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options, os_options, None)
None)
auth_url_secure = 'https://www.tests.com' auth_url_secure = 'https://www.tests.com'
auth_url_insecure = 'https://www.tests.com/invalid-certificate' auth_url_insecure = 'https://www.tests.com/invalid-certificate'
url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf', url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf',
@@ -394,8 +388,8 @@ class TestHeadContainer(MockHttpTest):
body = 'c' * 60 body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body) c.http_connection = self.fake_http_connection(500, body=body)
self.assertRaises(c.ClientException, c.head_container, self.assertRaises(c.ClientException, c.head_container,
'http://www.test.com', 'asdf', 'asdf', 'http://www.test.com', 'asdf', 'asdf',
) )
try: try:
value = c.head_container('http://www.test.com', 'asdf', 'asdf') value = c.head_container('http://www.test.com', 'asdf', 'asdf')
except c.ClientException as e: except c.ClientException as e:
@@ -413,8 +407,8 @@ class TestPutContainer(MockHttpTest):
body = 'c' * 60 body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body) c.http_connection = self.fake_http_connection(500, body=body)
self.assertRaises(c.ClientException, c.put_container, self.assertRaises(c.ClientException, c.put_container,
'http://www.test.com', 'asdf', 'asdf', 'http://www.test.com', 'asdf', 'asdf',
) )
try: try:
value = c.put_container('http://www.test.com', 'asdf', 'asdf') value = c.put_container('http://www.test.com', 'asdf', 'asdf')
except c.ClientException as e: except c.ClientException as e:
@@ -471,7 +465,7 @@ class TestPutObject(MockHttpTest):
self.assertTrue(isinstance(value, basestring)) self.assertTrue(isinstance(value, basestring))
# Test for RFC-2616 encoded symbols # Test for RFC-2616 encoded symbols
self.assertTrue("a-b: .x:yz mn:fg:lp" in resp.buffer[0], self.assertTrue("a-b: .x:yz mn:fg:lp" in resp.buffer[0],
"[a-b: .x:yz mn:fg:lp] header is missing") "[a-b: .x:yz mn:fg:lp] header is missing")
def test_chunk_warning(self): def test_chunk_warning(self):
conn = c.http_connection('http://www.test.com/') conn = c.http_connection('http://www.test.com/')
@@ -492,7 +486,6 @@ class TestPutObject(MockHttpTest):
self.assertEquals(len(w), 1) self.assertEquals(len(w), 1)
self.assertTrue(issubclass(w[-1].category, UserWarning)) self.assertTrue(issubclass(w[-1].category, UserWarning))
def test_server_error(self): def test_server_error(self):
body = 'c' * 60 body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body) c.http_connection = self.fake_http_connection(500, body=body)
@@ -526,7 +519,7 @@ class TestPostObject(MockHttpTest):
c.post_object(*args, headers=headers, http_conn=conn) c.post_object(*args, headers=headers, http_conn=conn)
# Test for RFC-2616 encoded symbols # Test for RFC-2616 encoded symbols
self.assertTrue("a-b: .x:yz mn:kl:qr" in resp.buffer[0], self.assertTrue("a-b: .x:yz mn:kl:qr" in resp.buffer[0],
"[a-b: .x:yz mn:kl:qr] header is missing") "[a-b: .x:yz mn:kl:qr] header is missing")
def test_server_error(self): def test_server_error(self):
body = 'c' * 60 body = 'c' * 60
@@ -630,7 +623,7 @@ class TestConnection(MockHttpTest):
conn = c.Connection('http://www.test.com', 'asdf', 'asdf', conn = c.Connection('http://www.test.com', 'asdf', 'asdf',
preauthurl='http://www.old.com', preauthurl='http://www.old.com',
preauthtoken='old', preauthtoken='old',
) )
self.assertEquals(conn.attempts, 0) self.assertEquals(conn.attempts, 0)
self.assertEquals(conn.url, 'http://www.old.com') self.assertEquals(conn.url, 'http://www.old.com')
@@ -736,7 +729,7 @@ class TestConnection(MockHttpTest):
exc = err exc = err
self.assertEquals(contents.seeks, []) self.assertEquals(contents.seeks, [])
self.assertEquals(str(exc), "put_object('c', 'o', ...) failure " self.assertEquals(str(exc), "put_object('c', 'o', ...) failure "
"and no ability to reset contents for reupload.") "and no ability to reset contents for reupload.")
finally: finally:
c.http_connection = orig_conn c.http_connection = orig_conn

View File

@@ -16,6 +16,7 @@ from httplib import HTTPException
from eventlet import Timeout, sleep from eventlet import Timeout, sleep
def fake_get_keystoneclient_2_0(os_options, exc=None, **kwargs): def fake_get_keystoneclient_2_0(os_options, exc=None, **kwargs):
def fake_get_keystoneclient_2_0(auth_url, def fake_get_keystoneclient_2_0(auth_url,
user, user,
@@ -78,7 +79,7 @@ def fake_http_connect(*code_iter, **kwargs):
'last-modified': self.timestamp, 'last-modified': self.timestamp,
'x-object-meta-test': 'testing', 'x-object-meta-test': 'testing',
'etag': 'etag':
self.etag or '"68b329da9893e34099c7d8ad5cb9c940"', self.etag or '"68b329da9893e34099c7d8ad5cb9c940"',
'x-works': 'yes', 'x-works': 'yes',
'x-account-container-count': 12345} 'x-account-container-count': 12345}
if not self.timestamp: if not self.timestamp:

View File

@@ -13,7 +13,7 @@ commands = python setup.py testr --testr-args="{posargs}"
[testenv:pep8] [testenv:pep8]
deps = pep8 deps = pep8
commands = pep8 --repeat --show-source --exclude=openstack swiftclient setup.py commands = pep8 --repeat --show-source --exclude=openstack swiftclient setup.py tests
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}