-
Notifications
You must be signed in to change notification settings - Fork 268
/
Copy pathtest_liborgdate_utf8.py
50 lines (40 loc) · 1.42 KB
/
test_liborgdate_utf8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import sys
import unittest
import locale
import threading
from datetime import date
from contextlib import contextmanager
from orgmode.py3compat.unicode_compatibility import *
sys.path.append(u'../ftplugin')
from orgmode.liborgmode.orgdate import OrgDate
class OrgDateUtf8TestCase(unittest.TestCase):
u"""
Tests OrgDate with utf-8 enabled locales
"""
LOCALE_LOCK = threading.Lock()
UTF8_LOCALE = "fr_FR.utf-8"
@contextmanager
def setlocale(self, name):
with self.LOCALE_LOCK:
saved = locale.setlocale(locale.LC_ALL)
try:
yield locale.setlocale(locale.LC_ALL, name)
finally:
locale.setlocale(locale.LC_ALL, saved)
def setUp(self):
self.year = 2016
self.month = 5
self.day = 7
self.text = u'<2016-05-07 sam.>'
self.textinactive = u'[2016-05-07 sam.]'
def test_OrdDate_str_unicode_active(self):
with self.setlocale(self.UTF8_LOCALE):
od = OrgDate(True, self.year, self.month, self.day)
self.assertEqual(self.text, unicode(od))
def test_OrdDate_str_unicode_inactive(self):
with self.setlocale(self.UTF8_LOCALE):
od = OrgDate(False, self.year, self.month, self.day)
self.assertEqual(self.textinactive, unicode(od))
def suite():
return unittest.TestLoader().loadTestsFromTestCase(OrgDateUtf8TestCase)