diff options
| author | Tim Graham <timograham@gmail.com> | 2017-01-25 10:13:08 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-25 10:13:08 -0500 |
| commit | 632c4ffd9cb1da273303bcd8005fff216506c795 (patch) | |
| tree | 4e475379e7e210a513789513021720b8b4808f7c /tests | |
| parent | 3f0c4fe18fe9850bb2f56be138012add4b54873d (diff) | |
Refs #23919 -- Replaced errno checking with PEP 3151 exceptions.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cache/tests.py | 2 | ||||
| -rw-r--r-- | tests/file_storage/tests.py | 17 | ||||
| -rw-r--r-- | tests/file_uploads/tests.py | 4 | ||||
| -rw-r--r-- | tests/staticfiles_tests/storage.py | 6 |
4 files changed, 12 insertions, 17 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 79a5120f71..7c61837ab0 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1360,7 +1360,7 @@ class FileBasedCacheTests(BaseCacheTests, TestCase): # Returns the default instead of erroring. self.assertEqual(cache.get('foo', 'baz'), 'baz') - def test_get_does_not_ignore_non_enoent_errno_values(self): + def test_get_does_not_ignore_non_filenotfound_exceptions(self): with mock.patch('builtins.open', side_effect=IOError): with self.assertRaises(IOError): cache.get('foo') diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index d33ca67c33..ba77622067 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -1,4 +1,3 @@ -import errno import os import shutil import sys @@ -416,9 +415,9 @@ class FileStorageTests(SimpleTestCase): real_makedirs(path) elif path == os.path.join(self.temp_dir, 'raced'): real_makedirs(path) - raise OSError(errno.EEXIST, 'simulated EEXIST') + raise FileNotFoundError() elif path == os.path.join(self.temp_dir, 'error'): - raise OSError(errno.EACCES, 'simulated EACCES') + raise FileExistsError() else: self.fail('unexpected argument %r' % path) @@ -433,8 +432,8 @@ class FileStorageTests(SimpleTestCase): with self.storage.open('raced/test.file') as f: self.assertEqual(f.read(), b'saved with race') - # OSErrors aside from EEXIST are still raised. - with self.assertRaises(OSError): + # Exceptions aside from FileNotFoundError are raised. + with self.assertRaises(FileExistsError): self.storage.save('error/test.file', ContentFile('not saved')) finally: os.makedirs = real_makedirs @@ -452,9 +451,9 @@ class FileStorageTests(SimpleTestCase): real_remove(path) elif path == os.path.join(self.temp_dir, 'raced.file'): real_remove(path) - raise OSError(errno.ENOENT, 'simulated ENOENT') + raise FileNotFoundError() elif path == os.path.join(self.temp_dir, 'error.file'): - raise OSError(errno.EACCES, 'simulated EACCES') + raise PermissionError() else: self.fail('unexpected argument %r' % path) @@ -469,9 +468,9 @@ class FileStorageTests(SimpleTestCase): self.storage.delete('raced.file') self.assertFalse(self.storage.exists('normal.file')) - # OSErrors aside from ENOENT are still raised. + # Exceptions aside from FileNotFoundError are raised. self.storage.save('error.file', ContentFile('delete with error')) - with self.assertRaises(OSError): + with self.assertRaises(PermissionError): self.storage.delete('error.file') finally: os.remove = real_remove diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index c7315ae142..827083412e 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -1,5 +1,4 @@ import base64 -import errno import hashlib import json import os @@ -564,9 +563,8 @@ class DirectoryCreationTests(SimpleTestCase): """Permission errors are not swallowed""" os.chmod(MEDIA_ROOT, 0o500) self.addCleanup(os.chmod, MEDIA_ROOT, 0o700) - with self.assertRaises(OSError) as cm: + with self.assertRaises(PermissionError): self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', b'x'), save=False) - self.assertEqual(cm.exception.errno, errno.EACCES) def test_not_a_directory(self): """The correct IOError is raised when the upload directory name exists but isn't a directory""" diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py index 79e6245f59..7a1f72c130 100644 --- a/tests/staticfiles_tests/storage.py +++ b/tests/staticfiles_tests/storage.py @@ -1,4 +1,3 @@ -import errno import os from datetime import datetime, timedelta @@ -51,9 +50,8 @@ class PathNotImplementedStorage(storage.Storage): name = self._path(name) try: os.remove(name) - except OSError as e: - if e.errno != errno.ENOENT: - raise + except FileNotFoundError: + pass def path(self, name): raise NotImplementedError |
