diff options
author | Tim Burke <tim.burke@gmail.com> | 2015-09-09 17:41:21 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2015-10-07 22:33:42 -0700 |
commit | 9fed7ed5e1f6dd3e589a35e3ee4abecb676f2188 (patch) | |
tree | 9fc610c348fc753a98422b3f8551ca2a8a3776d4 /tests/unit/test_multithreading.py | |
parent | 43b2c6bfe5140f32a37638985bd4cb7b73988160 (diff) | |
download | python-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_multithreading.py')
-rw-r--r-- | tests/unit/test_multithreading.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/tests/unit/test_multithreading.py b/tests/unit/test_multithreading.py index 2c45b47..76758b6 100644 --- a/tests/unit/test_multithreading.py +++ b/tests/unit/test_multithreading.py @@ -82,14 +82,13 @@ class TestConnectionThreadPoolExecutor(ThreadTestCase): ) # Now a job that fails - went_boom = False try: f = pool.submit(self._func, "go boom") f.result() except Exception as e: - went_boom = True self.assertEqual('I went boom!', str(e)) - self.assertTrue(went_boom) + else: + self.fail('I never went boom!') # Has the connection been returned to the pool? f = pool.submit(self._func, "succeed") @@ -106,24 +105,22 @@ class TestConnectionThreadPoolExecutor(ThreadTestCase): ctpe = mt.ConnectionThreadPoolExecutor(self._create_conn_fail, 1) with ctpe as pool: # Now a connection that fails - connection_failed = False try: f = pool.submit(self._func, "succeed") f.result() except Exception as e: - connection_failed = True self.assertEqual('This is a failed connection', str(e)) - self.assertTrue(connection_failed) + else: + self.fail('The connection did not fail') # Make sure we don't lock up on failed connections - connection_failed = False try: f = pool.submit(self._func, "go boom") f.result() except Exception as e: - connection_failed = True self.assertEqual('This is a failed connection', str(e)) - self.assertTrue(connection_failed) + else: + self.fail('The connection did not fail') def test_lazy_connections(self): ctpe = mt.ConnectionThreadPoolExecutor(self._create_conn, 10) |