Tests for batchprocessors error conditions.

This commit is contained in:
Henddher Pedroza 2019-10-13 00:29:06 -04:00
parent 9154e477ef
commit 903bf1663e
2 changed files with 22 additions and 1 deletions

View file

@ -233,7 +233,7 @@ def read_batchfile(pythonpath, file_ending=".py"):
continue
break
if not text and decoderr:
raise UnicodeDecodeError("\n".join(decoderr))
raise UnicodeDecodeError("\n".join(decoderr), bytearray(), 0, 0, '')
return text

View file

@ -0,0 +1,21 @@
"""Tests for batchprocessors """
import codecs
from django.test import TestCase
from evennia.utils import batchprocessors, utils
import mock
class TestBatchprocessorErrors(TestCase):
@mock.patch.object(utils, 'pypath_to_realpath', return_value=[])
def test_read_batchfile_raises_IOError(self, _):
with self.assertRaises(IOError):
batchprocessors.read_batchfile('foopath')
@mock.patch.object(utils, 'pypath_to_realpath', return_value=['pathfoo'])
@mock.patch.object(codecs, 'open', side_effect=ValueError('decodeerr'))
@mock.patch.object(batchprocessors, '_ENCODINGS', ['fooencoding'])
def test_read_batchfile_raises_UnicodeDecodeError(self, *_):
with self.assertRaises(UnicodeDecodeError, msg='decodeerr'):
batchprocessors.read_batchfile('foopath')