From 903bf1663e70167fe56575d20a8658708fe854e7 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Sun, 13 Oct 2019 00:29:06 -0400 Subject: [PATCH] Tests for batchprocessors error conditions. --- evennia/utils/batchprocessors.py | 2 +- evennia/utils/tests/test_batchprocessors.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 evennia/utils/tests/test_batchprocessors.py diff --git a/evennia/utils/batchprocessors.py b/evennia/utils/batchprocessors.py index 4e92a0582e..d798d19d58 100644 --- a/evennia/utils/batchprocessors.py +++ b/evennia/utils/batchprocessors.py @@ -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 diff --git a/evennia/utils/tests/test_batchprocessors.py b/evennia/utils/tests/test_batchprocessors.py new file mode 100644 index 0000000000..84acb623e2 --- /dev/null +++ b/evennia/utils/tests/test_batchprocessors.py @@ -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')