def test_load__template__correct_loader(self): """ Test that reader.unicode() is called correctly. This test tests that the correct reader is called with the correct arguments. This is a catch-all test to supplement the other test cases. It tests SpecLoader.load() independent of reader.unicode() being implemented correctly (and tested). """ class MockLoader(Loader): def __init__(self): self.s = None self.encoding = None # Overrides the existing method. def unicode(self, s, encoding=None): self.s = s self.encoding = encoding return u"foo" loader = MockLoader() custom_loader = SpecLoader() custom_loader.loader = loader view = TemplateSpec() view.template = "template-foo" view.template_encoding = "encoding-foo" # Check that our unicode() above was called. self._assert_template(custom_loader, view, u'foo') self.assertEqual(loader.s, "template-foo") self.assertEqual(loader.encoding, "encoding-foo")
def test_init__defaults(self): spec_loader = SpecLoader() # Check the loader attribute. loader = spec_loader.loader self.assertEqual(loader.extension, 'mustache') self.assertEqual(loader.file_encoding, sys.getdefaultencoding()) # TODO: finish testing the other Loader attributes. to_unicode = loader.to_unicode
def _make_specloader(): """ Return a default SpecLoader instance for testing purposes. """ # Python 2 and 3 have different default encodings. Thus, to have # consistent test results across both versions, we need to specify # the string and file encodings explicitly rather than relying on # the defaults. def to_unicode(s, encoding=None): """ Raises a TypeError exception if the given string is already unicode. """ if encoding is None: encoding = 'ascii' return unicode(s, encoding, 'strict') loader = Loader(file_encoding='ascii', to_unicode=to_unicode) return SpecLoader(loader=loader)
def test_init__loader(self): loader = Loader() custom = SpecLoader(loader=loader) self.assertIs(custom.loader, loader)