Removed many uses of bare "except:", which were either going to a) silence real issues, or b) were impossible to hit.
This commit is contained in:
parent
257c4011cb
commit
335a9f9cf1
|
@ -4,6 +4,7 @@ HR-specific Form helpers
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.contrib.localflavor.hr.hr_choices import (
|
from django.contrib.localflavor.hr.hr_choices import (
|
||||||
|
@ -91,10 +92,9 @@ class HRJMBGField(Field):
|
||||||
dd = int(matches.group('dd'))
|
dd = int(matches.group('dd'))
|
||||||
mm = int(matches.group('mm'))
|
mm = int(matches.group('mm'))
|
||||||
yyy = int(matches.group('yyy'))
|
yyy = int(matches.group('yyy'))
|
||||||
import datetime
|
|
||||||
try:
|
try:
|
||||||
datetime.date(yyy, mm, dd)
|
datetime.date(yyy, mm, dd)
|
||||||
except:
|
except ValueError:
|
||||||
raise ValidationError(self.error_messages['date'])
|
raise ValidationError(self.error_messages['date'])
|
||||||
|
|
||||||
# Validate checksum.
|
# Validate checksum.
|
||||||
|
|
|
@ -4,6 +4,8 @@ Romanian specific form helpers.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
from django.contrib.localflavor.ro.ro_counties import COUNTIES_CHOICES
|
from django.contrib.localflavor.ro.ro_counties import COUNTIES_CHOICES
|
||||||
from django.core.validators import EMPTY_VALUES
|
from django.core.validators import EMPTY_VALUES
|
||||||
from django.forms import ValidationError, Field, RegexField, Select
|
from django.forms import ValidationError, Field, RegexField, Select
|
||||||
|
@ -69,10 +71,9 @@ class ROCNPField(RegexField):
|
||||||
if value in EMPTY_VALUES:
|
if value in EMPTY_VALUES:
|
||||||
return ''
|
return ''
|
||||||
# check birthdate digits
|
# check birthdate digits
|
||||||
import datetime
|
|
||||||
try:
|
try:
|
||||||
datetime.date(int(value[1:3]), int(value[3:5]), int(value[5:7]))
|
datetime.date(int(value[1:3]), int(value[3:5]), int(value[5:7]))
|
||||||
except:
|
except ValueError:
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
# checksum
|
# checksum
|
||||||
key = '279146358279'
|
key = '279146358279'
|
||||||
|
@ -202,4 +203,3 @@ class ROPostalCodeField(RegexField):
|
||||||
def __init__(self, max_length=6, min_length=6, *args, **kwargs):
|
def __init__(self, max_length=6, min_length=6, *args, **kwargs):
|
||||||
super(ROPostalCodeField, self).__init__(r'^[0-9][0-8][0-9]{4}$',
|
super(ROPostalCodeField, self).__init__(r'^[0-9][0-8][0-9]{4}$',
|
||||||
max_length, min_length, *args, **kwargs)
|
max_length, min_length, *args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ class CacheClass(BaseMemcachedCache):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
import memcache
|
import memcache
|
||||||
except:
|
except ImportError:
|
||||||
raise InvalidCacheBackendError(
|
raise InvalidCacheBackendError(
|
||||||
"Memcached cache backend requires either the 'memcache' or 'cmemcache' library"
|
"Memcached cache backend requires either the 'memcache' or 'cmemcache' library"
|
||||||
)
|
)
|
||||||
|
|
|
@ -412,7 +412,4 @@ def _sqlite_format_dtdelta(dt, conn, days, secs, usecs):
|
||||||
return str(dt)
|
return str(dt)
|
||||||
|
|
||||||
def _sqlite_regexp(re_pattern, re_string):
|
def _sqlite_regexp(re_pattern, re_string):
|
||||||
try:
|
|
||||||
return bool(re.search(re_pattern, re_string))
|
return bool(re.search(re_pattern, re_string))
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
|
@ -68,7 +68,6 @@ class MultiPartParser(object):
|
||||||
if not boundary or not cgi.valid_boundary(boundary):
|
if not boundary or not cgi.valid_boundary(boundary):
|
||||||
raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
|
raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
|
||||||
|
|
||||||
|
|
||||||
# Content-Length should contain the length of the body we are about
|
# Content-Length should contain the length of the body we are about
|
||||||
# to receive.
|
# to receive.
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -100,7 +100,7 @@ class FileUploadTests(TestCase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.unlink(file1.name)
|
os.unlink(file1.name)
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
|
@ -17,10 +17,8 @@ class HandlerTests(unittest.TestCase):
|
||||||
# Try running the handler, it will fail in load_middleware
|
# Try running the handler, it will fail in load_middleware
|
||||||
handler = WSGIHandler()
|
handler = WSGIHandler()
|
||||||
self.assertEqual(handler.initLock.locked(), False)
|
self.assertEqual(handler.initLock.locked(), False)
|
||||||
try:
|
with self.assertRaises(Exception):
|
||||||
handler(None, None)
|
handler(None, None)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
self.assertEqual(handler.initLock.locked(), False)
|
self.assertEqual(handler.initLock.locked(), False)
|
||||||
# Reset settings
|
# Reset settings
|
||||||
settings.MIDDLEWARE_CLASSES = old_middleware_classes
|
settings.MIDDLEWARE_CLASSES = old_middleware_classes
|
||||||
|
|
|
@ -1677,10 +1677,7 @@ class CloneTests(TestCase):
|
||||||
list(n_list)
|
list(n_list)
|
||||||
# Use the note queryset in a query, and evalute
|
# Use the note queryset in a query, and evalute
|
||||||
# that query in a way that involves cloning.
|
# that query in a way that involves cloning.
|
||||||
try:
|
|
||||||
self.assertEqual(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
|
self.assertEqual(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
|
||||||
except:
|
|
||||||
self.fail('Query should be clonable')
|
|
||||||
|
|
||||||
|
|
||||||
class EmptyQuerySetTests(TestCase):
|
class EmptyQuerySetTests(TestCase):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.db import connection, connections, transaction, DEFAULT_DB_ALIAS, DatabaseError
|
||||||
from django.db import connection, connections, transaction, DEFAULT_DB_ALIAS
|
|
||||||
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
|
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
|
||||||
from django.test import TransactionTestCase, skipUnlessDBFeature
|
from django.test import TransactionTestCase, skipUnlessDBFeature
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
@ -151,21 +150,14 @@ class TestTransactionClosing(TransactionTestCase):
|
||||||
# Create a user
|
# Create a user
|
||||||
create_system_user()
|
create_system_user()
|
||||||
|
|
||||||
try:
|
with self.assertRaises(DatabaseError):
|
||||||
# The second call to create_system_user should fail for violating a unique constraint
|
# The second call to create_system_user should fail for violating
|
||||||
# (it's trying to re-create the same user)
|
# a unique constraint (it's trying to re-create the same user)
|
||||||
create_system_user()
|
create_system_user()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise ImproperlyConfigured('Unique constraint not enforced on django.contrib.auth.models.User')
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Try to read the database. If the last transaction was indeed closed,
|
# Try to read the database. If the last transaction was indeed closed,
|
||||||
# this should cause no problems
|
# this should cause no problems
|
||||||
_ = User.objects.all()[0]
|
User.objects.all()[0]
|
||||||
except:
|
|
||||||
self.fail("A transaction consisting of a failed operation was not closed.")
|
|
||||||
|
|
||||||
@override_settings(DEBUG=True)
|
@override_settings(DEBUG=True)
|
||||||
def test_failing_query_transaction_closed_debug(self):
|
def test_failing_query_transaction_closed_debug(self):
|
||||||
|
|
Loading…
Reference in New Issue