Fixed #24399 -- Made filesystem loaders use more specific exceptions.#4229
Fixed #24399 -- Made filesystem loaders use more specific exceptions.#4229prestontimmons wants to merge 1 commit intodjango:masterfrom prestontimmons:ticket-24399
Conversation
tests/template_tests/test_loaders.py
Outdated
There was a problem hiding this comment.
os.chmod should be before the try. It doesn't make a big difference but that's the common pattern in general.
|
Thanks. I fixed the docs and updated to a tempfile. That's a much better idea. |
|
Rebased and merged in 70123cf. Thanks! |
There was a problem hiding this comment.
This test is problematic on Windows:
======================================================================
FAIL: test_notafile_error (template_tests.test_loaders.FileSystemLoaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\Users\Tim\code\django\tests\template_tests\test_loaders.py", line 266
, in test_notafile_error
self.engine.get_template('first')
AssertionError: "Is\ a\ directory" does not match "[Errno 13] Permission denied:
u'c:\\Users\\Tim\\code\\django\\tests\\template_tests\\templates\\first'"
There was a problem hiding this comment.
Okay. I'll take a look into it.
There was a problem hiding this comment.
From the testing I did it seems "Permission denied" is the standard message raised on Windows if a directory is passed to open. Since the message can differ per OS, I think the fix is to change assertRaisesMessage(IOError, 'Is a directory') to assertRaises(IOError). I can add a PR if you agree.
There was a problem hiding this comment.
Does the raised exception have the same errno on both platforms?
If that's the case you could do:
with self.assertRaises(IOError) as ctx:
# ....
self.assertEqual(ctx.exception.errno, errno.WHATEVER)There was a problem hiding this comment.
It's different. Linux raises errno.EISDIR (21). Windows raises errno.EACCES (13).
There was a problem hiding this comment.
Seems okay to me. I guess the alternative would to vary the message based on OS. Not sure that complexity is required though.
No description provided.