locale_test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:projects-2017-2 作者: ncss 项目源码 文件源码
def test_csv_bom(self):
        with open(os.path.join(os.path.dirname(__file__), 'csv_translations',
                               'fr_FR.csv'), 'rb') as f:
            char_data = to_unicode(f.read())
        # Re-encode our input data (which is utf-8 without BOM) in
        # encodings that use the BOM and ensure that we can still load
        # it. Note that utf-16-le and utf-16-be do not write a BOM,
        # so we only test whichver variant is native to our platform.
        for encoding in ['utf-8-sig', 'utf-16']:
            tmpdir = tempfile.mkdtemp()
            try:
                with open(os.path.join(tmpdir, 'fr_FR.csv'), 'wb') as f:
                    f.write(char_data.encode(encoding))
                tornado.locale.load_translations(tmpdir)
                locale = tornado.locale.get('fr_FR')
                self.assertIsInstance(locale, tornado.locale.CSVLocale)
                self.assertEqual(locale.translate("school"), u("\u00e9cole"))
            finally:
                shutil.rmtree(tmpdir)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号