Commit 4be82fd1 by Chris Jerdonek

Addressed TODO to rename reader to loader in test_loader.py.

parent 1fd7f3f0
# encoding: utf-8 # encoding: utf-8
""" """
Unit tests of reader.py. Unit tests of loader.py.
""" """
...@@ -78,8 +78,8 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -78,8 +78,8 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
Test unicode(): default arguments with str input. Test unicode(): default arguments with str input.
""" """
reader = Loader() loader = Loader()
actual = reader.unicode("foo") actual = loader.unicode("foo")
self.assertString(actual, u"foo") self.assertString(actual, u"foo")
...@@ -88,8 +88,8 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -88,8 +88,8 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
Test unicode(): default arguments with unicode input. Test unicode(): default arguments with unicode input.
""" """
reader = Loader() loader = Loader()
actual = reader.unicode(u"foo") actual = loader.unicode(u"foo")
self.assertString(actual, u"foo") self.assertString(actual, u"foo")
...@@ -103,8 +103,8 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -103,8 +103,8 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
s = UnicodeSubclass(u"foo") s = UnicodeSubclass(u"foo")
reader = Loader() loader = Loader()
actual = reader.unicode(s) actual = loader.unicode(s)
self.assertString(actual, u"foo") self.assertString(actual, u"foo")
...@@ -113,32 +113,31 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -113,32 +113,31 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
Test unicode(): encoding attribute. Test unicode(): encoding attribute.
""" """
# TODO: rename reader to loader everywhere in this module. loader = Loader()
reader = Loader()
non_ascii = u'abcdé'.encode('utf-8') non_ascii = u'abcdé'.encode('utf-8')
self.assertRaises(UnicodeDecodeError, reader.unicode, non_ascii) self.assertRaises(UnicodeDecodeError, loader.unicode, non_ascii)
def to_unicode(s, encoding=None): def to_unicode(s, encoding=None):
if encoding is None: if encoding is None:
encoding = 'utf-8' encoding = 'utf-8'
return unicode(s, encoding) return unicode(s, encoding)
reader.to_unicode = to_unicode loader.to_unicode = to_unicode
self.assertString(reader.unicode(non_ascii), u"abcdé") self.assertString(loader.unicode(non_ascii), u"abcdé")
def test_unicode__encoding_argument(self): def test_unicode__encoding_argument(self):
""" """
Test unicode(): encoding argument. Test unicode(): encoding argument.
""" """
reader = Loader() loader = Loader()
non_ascii = u'abcdé'.encode('utf-8') non_ascii = u'abcdé'.encode('utf-8')
self.assertRaises(UnicodeDecodeError, reader.unicode, non_ascii) self.assertRaises(UnicodeDecodeError, loader.unicode, non_ascii)
actual = reader.unicode(non_ascii, encoding='utf-8') actual = loader.unicode(non_ascii, encoding='utf-8')
self.assertString(actual, u'abcdé') self.assertString(actual, u'abcdé')
# TODO: check the read() unit tests. # TODO: check the read() unit tests.
...@@ -147,9 +146,9 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -147,9 +146,9 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
Test read(). Test read().
""" """
reader = Loader() loader = Loader()
path = self._get_path('ascii.mustache') path = self._get_path('ascii.mustache')
actual = reader.read(path) actual = loader.read(path)
self.assertString(actual, u'ascii: abc') self.assertString(actual, u'ascii: abc')
def test_read__file_encoding__attribute(self): def test_read__file_encoding__attribute(self):
...@@ -171,25 +170,25 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -171,25 +170,25 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
Test read(): encoding argument respected. Test read(): encoding argument respected.
""" """
reader = Loader() loader = Loader()
path = self._get_path('non_ascii.mustache') path = self._get_path('non_ascii.mustache')
self.assertRaises(UnicodeDecodeError, reader.read, path) self.assertRaises(UnicodeDecodeError, loader.read, path)
actual = reader.read(path, encoding='utf-8') actual = loader.read(path, encoding='utf-8')
self.assertString(actual, u'non-ascii: é') self.assertString(actual, u'non-ascii: é')
def test_reader__to_unicode__attribute(self): def test_loader__to_unicode__attribute(self):
""" """
Test read(): to_unicode attribute respected. Test read(): to_unicode attribute respected.
""" """
reader = Loader() loader = Loader()
path = self._get_path('non_ascii.mustache') path = self._get_path('non_ascii.mustache')
self.assertRaises(UnicodeDecodeError, reader.read, path) self.assertRaises(UnicodeDecodeError, loader.read, path)
#reader.decode_errors = 'ignore' #loader.decode_errors = 'ignore'
#actual = reader.read(path) #actual = loader.read(path)
#self.assertString(actual, u'non-ascii: ') #self.assertString(actual, u'non-ascii: ')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment