Pep8 unit test modules for hacking and one liners (4 of 12)
Address all the "hacking" lines that are flagged, and all the modules that just have one item flagged. Change-Id: I372a4bdf9c7748f73e38c4fd55e5954f1afade5b Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
parent
c57f526f58
commit
c067abd21e
@ -17,6 +17,7 @@ from eventlet import sleep, Timeout
|
||||
import logging.handlers
|
||||
from httplib import HTTPException
|
||||
|
||||
|
||||
class FakeRing(object):
|
||||
|
||||
def __init__(self, replicas=3, max_more_nodes=0):
|
||||
|
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# TODO: Tests
|
||||
# TODO(creiht): Tests
|
||||
|
||||
import unittest
|
||||
|
||||
|
@ -29,15 +29,15 @@ from swift.common.utils import normalize_timestamp, replication, public
|
||||
|
||||
|
||||
class TestAccountController(unittest.TestCase):
|
||||
""" Test swift.account_server.AccountController """
|
||||
"""Test swift.account.server.AccountController"""
|
||||
def setUp(self):
|
||||
""" Set up for testing swift.account_server.AccountController """
|
||||
"""Set up for testing swift.account.server.AccountController"""
|
||||
self.testdir = os.path.join(os.path.dirname(__file__), 'account_server')
|
||||
self.controller = AccountController(
|
||||
{'devices': self.testdir, 'mount_check': 'false'})
|
||||
|
||||
def tearDown(self):
|
||||
""" Tear down for testing swift.account_server.AccountController """
|
||||
"""Tear down for testing swift.account.server.AccountController"""
|
||||
try:
|
||||
rmtree(self.testdir)
|
||||
except OSError, err:
|
||||
@ -1341,10 +1341,7 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEquals(resp.charset, 'utf-8')
|
||||
|
||||
def test_serv_reserv(self):
|
||||
"""
|
||||
Test replication_server flag
|
||||
was set from configuration file.
|
||||
"""
|
||||
# Test replication_server flag was set from configuration file.
|
||||
conf = {'devices': self.testdir, 'mount_check': 'false'}
|
||||
self.assertEquals(AccountController(conf).replication_server, None)
|
||||
for val in [True, '1', 'True', 'true']:
|
||||
@ -1355,7 +1352,7 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertFalse(AccountController(conf).replication_server)
|
||||
|
||||
def test_list_allowed_methods(self):
|
||||
""" Test list of allowed_methods """
|
||||
# Test list of allowed_methods
|
||||
obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST']
|
||||
repl_methods = ['REPLICATE']
|
||||
for method_name in obj_methods:
|
||||
@ -1366,10 +1363,8 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEquals(method.replication, True)
|
||||
|
||||
def test_correct_allowed_method(self):
|
||||
"""
|
||||
Test correct work for allowed method using
|
||||
swift.account_server.AccountController.__call__
|
||||
"""
|
||||
# Test correct work for allowed method using
|
||||
# swift.account.server.AccountController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
@ -1406,10 +1401,8 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEqual(response, method_res)
|
||||
|
||||
def test_not_allowed_method(self):
|
||||
"""
|
||||
Test correct work for NOT allowed method using
|
||||
swift.account_server.AccountController.__call__
|
||||
"""
|
||||
# Test correct work for NOT allowed method using
|
||||
# swift.account.server.AccountController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
|
@ -565,7 +565,7 @@ class TestRingBuilder(unittest.TestCase):
|
||||
self.assertEquals(counts[3], 256)
|
||||
|
||||
def test_add_rebalance_add_rebalance_delete_rebalance(self):
|
||||
""" Test for https://bugs.launchpad.net/swift/+bug/845952 """
|
||||
# Test for https://bugs.launchpad.net/swift/+bug/845952
|
||||
# min_part of 0 to allow for rapid rebalancing
|
||||
rb = ring.RingBuilder(8, 3, 0)
|
||||
rb.add_dev({'id': 0, 'region': 0, 'zone': 0, 'weight': 1,
|
||||
|
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# TODO: Tests
|
||||
# TODO(gholt): Tests
|
||||
|
||||
import unittest
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# TODO: Test kill_children signal handlers
|
||||
# TODO(clayg): Test kill_children signal handlers
|
||||
|
||||
import os
|
||||
import unittest
|
||||
@ -83,9 +83,7 @@ class TestRunDaemon(unittest.TestCase):
|
||||
self.assertEquals(d.once_called, True)
|
||||
|
||||
def test_run_daemon(self):
|
||||
sample_conf = """[my-daemon]
|
||||
user = %s
|
||||
""" % getuser()
|
||||
sample_conf = "[my-daemon]\nuser = %s\n" % getuser()
|
||||
with tmpfile(sample_conf) as conf_file:
|
||||
with patch.dict('os.environ', {'TZ': ''}):
|
||||
daemon.run_daemon(MyDaemon, conf_file)
|
||||
|
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# TODO: Tests
|
||||
# TODO(creiht): Tests
|
||||
|
||||
import unittest
|
||||
|
||||
|
@ -1602,7 +1602,7 @@ class TestManager(unittest.TestCase):
|
||||
manager.Server = _orig_server
|
||||
manager.watch_server_pids = _orig_watch_server_pids
|
||||
|
||||
# TODO: more tests
|
||||
# TODO(clayg): more tests
|
||||
def test_shutdown(self):
|
||||
m = manager.Manager(['test'])
|
||||
m.stop_was_called = False
|
||||
|
@ -1,4 +1,4 @@
|
||||
# -*- coding: utf8 -*-
|
||||
# -*- coding:utf-8 -*-
|
||||
# Copyright (c) 2010-2012 OpenStack, LLC.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -45,6 +45,7 @@ class ExplodingMockMemcached(object):
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
|
||||
class MockMemcached(object):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -137,7 +137,7 @@ class TestUtils(unittest.TestCase):
|
||||
utils.HASH_PATH_PREFIX = 'startcap'
|
||||
|
||||
def test_normalize_timestamp(self):
|
||||
""" Test swift.common.utils.normalize_timestamp """
|
||||
# Test swift.common.utils.normalize_timestamp
|
||||
self.assertEquals(utils.normalize_timestamp('1253327593.48174'),
|
||||
"1253327593.48174")
|
||||
self.assertEquals(utils.normalize_timestamp(1253327593.48174),
|
||||
@ -158,7 +158,7 @@ class TestUtils(unittest.TestCase):
|
||||
self.assertRaises(ValueError, utils.normalize_timestamp, 'abc')
|
||||
|
||||
def test_backwards(self):
|
||||
""" Test swift.common.utils.backward """
|
||||
# Test swift.common.utils.backward
|
||||
|
||||
# The lines are designed so that the function would encounter
|
||||
# all of the boundary conditions and typical conditions.
|
||||
@ -215,7 +215,7 @@ class TestUtils(unittest.TestCase):
|
||||
os.unlink(testroot)
|
||||
|
||||
def test_split_path(self):
|
||||
""" Test swift.common.utils.split_account_path """
|
||||
# Test swift.common.utils.split_account_path
|
||||
self.assertRaises(ValueError, utils.split_path, '')
|
||||
self.assertRaises(ValueError, utils.split_path, '/')
|
||||
self.assertRaises(ValueError, utils.split_path, '//')
|
||||
@ -249,7 +249,7 @@ class TestUtils(unittest.TestCase):
|
||||
self.assertEquals(str(err), 'Invalid path: o%0An%20e')
|
||||
|
||||
def test_validate_device_partition(self):
|
||||
""" Test swift.common.utils.validate_device_partition """
|
||||
# Test swift.common.utils.validate_device_partition
|
||||
utils.validate_device_partition('foo', 'bar')
|
||||
self.assertRaises(ValueError,
|
||||
utils.validate_device_partition, '', '')
|
||||
@ -279,7 +279,7 @@ class TestUtils(unittest.TestCase):
|
||||
self.assertEquals(str(err), 'Invalid partition: o%0An%20e')
|
||||
|
||||
def test_NullLogger(self):
|
||||
""" Test swift.common.utils.NullLogger """
|
||||
# Test swift.common.utils.NullLogger
|
||||
sio = StringIO()
|
||||
nl = utils.NullLogger()
|
||||
nl.write('test')
|
||||
|
@ -44,7 +44,7 @@ def save_globals():
|
||||
|
||||
|
||||
class TestContainerController(unittest.TestCase):
|
||||
""" Test swift.container_server.ContainerController """
|
||||
"""Test swift.container.server.ContainerController"""
|
||||
def setUp(self):
|
||||
"""Set up for testing swift.object_server.ObjectController"""
|
||||
self.testdir = os.path.join(mkdtemp(),
|
||||
@ -1468,10 +1468,7 @@ class TestContainerController(unittest.TestCase):
|
||||
'x-trans-id': '-'})})
|
||||
|
||||
def test_serv_reserv(self):
|
||||
"""
|
||||
Test replication_server flag
|
||||
was set from configuration file.
|
||||
"""
|
||||
# Test replication_server flag was set from configuration file.
|
||||
container_controller = container_server.ContainerController
|
||||
conf = {'devices': self.testdir, 'mount_check': 'false'}
|
||||
self.assertEquals(container_controller(conf).replication_server, None)
|
||||
@ -1483,7 +1480,7 @@ class TestContainerController(unittest.TestCase):
|
||||
self.assertFalse(container_controller(conf).replication_server)
|
||||
|
||||
def test_list_allowed_methods(self):
|
||||
""" Test list of allowed_methods """
|
||||
# Test list of allowed_methods
|
||||
obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST']
|
||||
repl_methods = ['REPLICATE']
|
||||
for method_name in obj_methods:
|
||||
@ -1494,10 +1491,8 @@ class TestContainerController(unittest.TestCase):
|
||||
self.assertEquals(method.replication, True)
|
||||
|
||||
def test_correct_allowed_method(self):
|
||||
"""
|
||||
Test correct work for allowed method using
|
||||
swift.container_server.ContainerController.__call__
|
||||
"""
|
||||
# Test correct work for allowed method using
|
||||
# swift.container.server.ContainerController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
@ -1533,10 +1528,8 @@ class TestContainerController(unittest.TestCase):
|
||||
self.assertEqual(response, method_res)
|
||||
|
||||
def test_not_allowed_method(self):
|
||||
"""
|
||||
Test correct work for NOT allowed method using
|
||||
swift.container_server.ContainerController.__call__
|
||||
"""
|
||||
# Test correct work for NOT allowed method using
|
||||
# swift.container.server.ContainerController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
|
@ -274,7 +274,8 @@ class TestAuditor(unittest.TestCase):
|
||||
if with_ts:
|
||||
|
||||
name_hash = hash_path('a', 'c', 'o')
|
||||
dir_path = os.path.join(self.devices, 'sda',
|
||||
dir_path = os.path.join(
|
||||
self.devices, 'sda',
|
||||
storage_directory(DATADIR, '0', name_hash))
|
||||
ts_file_path = os.path.join(dir_path, '99999.ts')
|
||||
if not os.path.exists(dir_path):
|
||||
|
@ -123,7 +123,7 @@ class TestObjectExpirer(TestCase):
|
||||
self.deleted_objects = {}
|
||||
|
||||
def delete_object(self, actual_obj, timestamp, container, obj):
|
||||
if not container in self.deleted_objects:
|
||||
if container not in self.deleted_objects:
|
||||
self.deleted_objects[container] = set()
|
||||
self.deleted_objects[container].add(obj)
|
||||
|
||||
|
@ -45,7 +45,7 @@ class TestObjectController(unittest.TestCase):
|
||||
"""Test swift.obj.server.ObjectController"""
|
||||
|
||||
def setUp(self):
|
||||
""" Set up for testing swift.object_server.ObjectController """
|
||||
"""Set up for testing swift.object.server.ObjectController"""
|
||||
utils.HASH_PATH_SUFFIX = 'endcap'
|
||||
utils.HASH_PATH_PREFIX = 'startcap'
|
||||
self.testdir = \
|
||||
@ -58,7 +58,7 @@ class TestObjectController(unittest.TestCase):
|
||||
tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs)
|
||||
|
||||
def tearDown(self):
|
||||
""" Tear down for testing swift.object_server.ObjectController """
|
||||
"""Tear down for testing swift.object.server.ObjectController"""
|
||||
rmtree(os.path.dirname(self.testdir))
|
||||
tpool.execute = self._orig_tpool_exc
|
||||
|
||||
@ -110,7 +110,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 204)
|
||||
|
||||
def test_POST_update_meta(self):
|
||||
""" Test swift.object_server.ObjectController.POST """
|
||||
# Test swift.obj.server.ObjectController.POST
|
||||
original_headers = self.object_controller.allowed_headers
|
||||
test_headers = 'content-encoding foo bar'.split()
|
||||
self.object_controller.allowed_headers = set(test_headers)
|
||||
@ -348,7 +348,7 @@ class TestObjectController(unittest.TestCase):
|
||||
object_server.http_connect = old_http_connect
|
||||
|
||||
def test_POST_quarantine_zbyte(self):
|
||||
""" Test swift.object_server.ObjectController.GET """
|
||||
# Test swift.obj.server.ObjectController.GET
|
||||
timestamp = normalize_timestamp(time())
|
||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'X-Timestamp': timestamp,
|
||||
@ -613,7 +613,7 @@ class TestObjectController(unittest.TestCase):
|
||||
object_server.http_connect = old_http_connect
|
||||
|
||||
def test_HEAD(self):
|
||||
""" Test swift.object_server.ObjectController.HEAD """
|
||||
# Test swift.obj.server.ObjectController.HEAD
|
||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'HEAD'})
|
||||
resp = req.get_response(self.object_controller)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
@ -678,7 +678,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_HEAD_quarantine_zbyte(self):
|
||||
""" Test swift.object_server.ObjectController.GET """
|
||||
# Test swift.obj.server.ObjectController.GET
|
||||
timestamp = normalize_timestamp(time())
|
||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'X-Timestamp': timestamp,
|
||||
@ -706,7 +706,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(os.listdir(quar_dir)[0], file_name)
|
||||
|
||||
def test_GET(self):
|
||||
""" Test swift.object_server.ObjectController.GET """
|
||||
# Test swift.obj.server.ObjectController.GET
|
||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = req.get_response(self.object_controller)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
@ -967,7 +967,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
|
||||
def test_GET_quarantine(self):
|
||||
""" Test swift.object_server.ObjectController.GET """
|
||||
# Test swift.obj.server.ObjectController.GET
|
||||
timestamp = normalize_timestamp(time())
|
||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'X-Timestamp': timestamp,
|
||||
@ -998,7 +998,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_GET_quarantine_zbyte(self):
|
||||
""" Test swift.object_server.ObjectController.GET """
|
||||
# Test swift.obj.server.ObjectController.GET
|
||||
timestamp = normalize_timestamp(time())
|
||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'X-Timestamp': timestamp,
|
||||
@ -1025,7 +1025,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(os.listdir(quar_dir)[0], file_name)
|
||||
|
||||
def test_GET_quarantine_range(self):
|
||||
""" Test swift.object_server.ObjectController.GET """
|
||||
# Test swift.obj.server.ObjectController.GET
|
||||
timestamp = normalize_timestamp(time())
|
||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'X-Timestamp': timestamp,
|
||||
@ -1077,7 +1077,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_DELETE(self):
|
||||
# Test swift.object_server.ObjectController.DELETE
|
||||
# Test swift.obj.server.ObjectController.DELETE
|
||||
req = Request.blank('/sda1/p/a/c',
|
||||
environ={'REQUEST_METHOD': 'DELETE'})
|
||||
resp = req.get_response(self.object_controller)
|
||||
@ -1157,7 +1157,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assert_(os.path.isfile(objfile))
|
||||
|
||||
def test_DELETE_container_updates(self):
|
||||
# Test swift.object_server.ObjectController.DELETE and container
|
||||
# Test swift.obj.server.ObjectController.DELETE and container
|
||||
# updates, making sure container update is called in the correct
|
||||
# state.
|
||||
timestamp = normalize_timestamp(time())
|
||||
@ -1254,7 +1254,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.object_controller.container_update = orig_cu
|
||||
|
||||
def test_call(self):
|
||||
""" Test swift.object_server.ObjectController.__call__ """
|
||||
# Test swift.obj.server.ObjectController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
@ -2623,10 +2623,7 @@ class TestObjectController(unittest.TestCase):
|
||||
diskfile.fallocate = orig_fallocate
|
||||
|
||||
def test_serv_reserv(self):
|
||||
"""
|
||||
Test replication_server flag
|
||||
was set from configuration file.
|
||||
"""
|
||||
# Test replication_server flag was set from configuration file.
|
||||
conf = {'devices': self.testdir, 'mount_check': 'false'}
|
||||
self.assertEquals(
|
||||
object_server.ObjectController(conf).replication_server, None)
|
||||
@ -2640,7 +2637,7 @@ class TestObjectController(unittest.TestCase):
|
||||
object_server.ObjectController(conf).replication_server)
|
||||
|
||||
def test_list_allowed_methods(self):
|
||||
""" Test list of allowed_methods """
|
||||
# Test list of allowed_methods
|
||||
obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST']
|
||||
repl_methods = ['REPLICATE']
|
||||
for method_name in obj_methods:
|
||||
@ -2651,10 +2648,8 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(method.replication, True)
|
||||
|
||||
def test_correct_allowed_method(self):
|
||||
"""
|
||||
Test correct work for allowed method using
|
||||
swift.object_server.ObjectController.__call__
|
||||
"""
|
||||
# Test correct work for allowed method using
|
||||
# swift.obj.server.ObjectController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
@ -2663,7 +2658,7 @@ class TestObjectController(unittest.TestCase):
|
||||
'replication_server': 'false'})
|
||||
|
||||
def start_response(*args):
|
||||
""" Sends args to outbuf """
|
||||
# Sends args to outbuf
|
||||
outbuf.writelines(args)
|
||||
|
||||
method = 'PUT'
|
||||
@ -2690,10 +2685,8 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEqual(response, method_res)
|
||||
|
||||
def test_not_allowed_method(self):
|
||||
"""
|
||||
Test correct work for NOT allowed method using
|
||||
swift.object_server.ObjectController.__call__
|
||||
"""
|
||||
# Test correct work for NOT allowed method using
|
||||
# swift.obj.server.ObjectController.__call__
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
@ -2702,7 +2695,7 @@ class TestObjectController(unittest.TestCase):
|
||||
'replication_server': 'false'})
|
||||
|
||||
def start_response(*args):
|
||||
""" Sends args to outbuf """
|
||||
# Sends args to outbuf
|
||||
outbuf.writelines(args)
|
||||
|
||||
method = 'PUT'
|
||||
|
Loading…
Reference in New Issue
Block a user