summaryrefslogtreecommitdiff
path: root/tests/unit/test_utils.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2015-09-09 17:41:21 -0700
committerTim Burke <tim.burke@gmail.com>2015-10-07 22:33:42 -0700
commit9fed7ed5e1f6dd3e589a35e3ee4abecb676f2188 (patch)
tree9fc610c348fc753a98422b3f8551ca2a8a3776d4 /tests/unit/test_utils.py
parent43b2c6bfe5140f32a37638985bd4cb7b73988160 (diff)
downloadpython-swiftclient-9fed7ed5e1f6dd3e589a35e3ee4abecb676f2188.tar.gz
Miscellaneous (mostly test) cleanup
* Always use testtools.TestCase, since we're relying on testtools * Always use mock (as opposed to unittest.mock) since we're relying on mock * Add note about when a missing logging handler was added * Stop %-formatting the giant usage string that doesn't actually need any formatting * Prefer assertIs, assertIn, assertIsInstance over assertTrue * Use else-self.fail instead of sentinel values * Check resp.get('error') is None before checking resp['success'] is True, so test failures actually tell you something useful * Tighten some isinstance assertions * Import MockHttpTest from correct location * Only populate clean_os_environ once * Use setUp for setup, not __init__ * Replace assertIn(key, dict) and assertEqual(foo, dict[key]) with assertEqual(foo, dict.get(key)) when key is a literal and foo is not None * Use mock.patch.object instead of manually patching for tests * Use six.binary_type instead of type(''.encode('utf-8')) * Stop shadowing builtin bytes * Reclaim some margin * Stop checking the return-type of encode_utf8; we already know it's bytes Change-Id: I2138ea553378ce88810b7353147c8645a8f8c90e
Diffstat (limited to 'tests/unit/test_utils.py')
-rw-r--r--tests/unit/test_utils.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 7d7f6b6..4faac6d 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -28,17 +28,13 @@ class TestConfigTrueValue(testtools.TestCase):
for v in u.TRUE_VALUES:
self.assertEqual(v, v.lower())
+ @mock.patch.object(u, 'TRUE_VALUES', 'hello world'.split())
def test_config_true_value(self):
- orig_trues = u.TRUE_VALUES
- try:
- u.TRUE_VALUES = 'hello world'.split()
- for val in 'hello world HELLO WORLD'.split():
- self.assertTrue(u.config_true_value(val) is True)
- self.assertTrue(u.config_true_value(True) is True)
- self.assertTrue(u.config_true_value('foo') is False)
- self.assertTrue(u.config_true_value(False) is False)
- finally:
- u.TRUE_VALUES = orig_trues
+ for val in 'hello world HELLO WORLD'.split():
+ self.assertIs(u.config_true_value(val), True)
+ self.assertIs(u.config_true_value(True), True)
+ self.assertIs(u.config_true_value('foo'), False)
+ self.assertIs(u.config_true_value(False), False)
class TestPrtBytes(testtools.TestCase):
@@ -192,11 +188,11 @@ class TestReadableToIterable(testtools.TestCase):
# Check creation with a real and noop md5 class
data = u.ReadableToIterable(None, None, md5=True)
self.assertEqual(md5().hexdigest(), data.get_md5sum())
- self.assertTrue(isinstance(data.md5sum, type(md5())))
+ self.assertIs(type(data.md5sum), type(md5()))
data = u.ReadableToIterable(None, None, md5=False)
self.assertEqual('', data.get_md5sum())
- self.assertTrue(isinstance(data.md5sum, type(u.NoopMD5())))
+ self.assertIs(type(data.md5sum), u.NoopMD5)
def test_unicode(self):
# Check no errors are raised if unicode data is feed in.