Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Use assertRaises instead of try/except blocks for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Aug 1, 2013
1 parent 915d8ff commit 4407fcb
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tests/unit/cloudsearch/test_exceptions.py
Expand Up @@ -24,20 +24,14 @@ def test_no_simplejson_value_error(self):
with mock.patch.object(json, 'loads', fake_loads_value_error):
search = SearchConnection(endpoint=HOSTNAME)

try:
with self.assertRaisesRegexp(SearchServiceException, 'non-json'):
search.search(q='test')
self.fail('This should never run!')
except SearchServiceException, err:
self.assertTrue('non-json' in str(err))

@unittest.skipUnless(hasattr(json, 'JSONDecodeError'),
'requires simplejson')
def test_simplejson_jsondecodeerror(self):
with mock.patch.object(json, 'loads', fake_loads_json_error):
search = SearchConnection(endpoint=HOSTNAME)

try:
with self.assertRaisesRegexp(SearchServiceException, 'non-json'):
search.search(q='test')
self.fail('This should never run!')
except SearchServiceException, err:
self.assertTrue('non-json' in str(err))

0 comments on commit 4407fcb

Please sign in to comment.