PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib-python/2.7/test/test_strptime.py

https://bitbucket.org/yrttyr/pypy
Python | 562 lines | 516 code | 15 blank | 31 comment | 9 complexity | 54530bb5227724fb6ff3ca029235c70f MD5 | raw file
  1. """PyUnit testing against strptime"""
  2. import unittest
  3. import time
  4. import locale
  5. import re
  6. import sys
  7. from test import test_support
  8. from datetime import date as datetime_date
  9. import _strptime
  10. class getlang_Tests(unittest.TestCase):
  11. """Test _getlang"""
  12. def test_basic(self):
  13. self.assertEqual(_strptime._getlang(), locale.getlocale(locale.LC_TIME))
  14. class LocaleTime_Tests(unittest.TestCase):
  15. """Tests for _strptime.LocaleTime.
  16. All values are lower-cased when stored in LocaleTime, so make sure to
  17. compare values after running ``lower`` on them.
  18. """
  19. def setUp(self):
  20. """Create time tuple based on current time."""
  21. self.time_tuple = time.localtime()
  22. self.LT_ins = _strptime.LocaleTime()
  23. def compare_against_time(self, testing, directive, tuple_position,
  24. error_msg):
  25. """Helper method that tests testing against directive based on the
  26. tuple_position of time_tuple. Uses error_msg as error message.
  27. """
  28. strftime_output = time.strftime(directive, self.time_tuple).lower()
  29. comparison = testing[self.time_tuple[tuple_position]]
  30. self.assertIn(strftime_output, testing,
  31. "%s: not found in tuple" % error_msg)
  32. self.assertTrue(comparison == strftime_output,
  33. "%s: position within tuple incorrect; %s != %s" %
  34. (error_msg, comparison, strftime_output))
  35. def test_weekday(self):
  36. # Make sure that full and abbreviated weekday names are correct in
  37. # both string and position with tuple
  38. self.compare_against_time(self.LT_ins.f_weekday, '%A', 6,
  39. "Testing of full weekday name failed")
  40. self.compare_against_time(self.LT_ins.a_weekday, '%a', 6,
  41. "Testing of abbreviated weekday name failed")
  42. def test_month(self):
  43. # Test full and abbreviated month names; both string and position
  44. # within the tuple
  45. self.compare_against_time(self.LT_ins.f_month, '%B', 1,
  46. "Testing against full month name failed")
  47. self.compare_against_time(self.LT_ins.a_month, '%b', 1,
  48. "Testing against abbreviated month name failed")
  49. def test_am_pm(self):
  50. # Make sure AM/PM representation done properly
  51. strftime_output = time.strftime("%p", self.time_tuple).lower()
  52. self.assertIn(strftime_output, self.LT_ins.am_pm,
  53. "AM/PM representation not in tuple")
  54. if self.time_tuple[3] < 12: position = 0
  55. else: position = 1
  56. self.assertTrue(strftime_output == self.LT_ins.am_pm[position],
  57. "AM/PM representation in the wrong position within the tuple")
  58. def test_timezone(self):
  59. # Make sure timezone is correct
  60. timezone = time.strftime("%Z", self.time_tuple).lower()
  61. if timezone:
  62. self.assertTrue(timezone in self.LT_ins.timezone[0] or
  63. timezone in self.LT_ins.timezone[1],
  64. "timezone %s not found in %s" %
  65. (timezone, self.LT_ins.timezone))
  66. def test_date_time(self):
  67. # Check that LC_date_time, LC_date, and LC_time are correct
  68. # the magic date is used so as to not have issues with %c when day of
  69. # the month is a single digit and has a leading space. This is not an
  70. # issue since strptime still parses it correctly. The problem is
  71. # testing these directives for correctness by comparing strftime
  72. # output.
  73. magic_date = (1999, 3, 17, 22, 44, 55, 2, 76, 0)
  74. strftime_output = time.strftime("%c", magic_date)
  75. self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_date_time,
  76. magic_date),
  77. "LC_date_time incorrect")
  78. strftime_output = time.strftime("%x", magic_date)
  79. self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_date,
  80. magic_date),
  81. "LC_date incorrect")
  82. strftime_output = time.strftime("%X", magic_date)
  83. self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_time,
  84. magic_date),
  85. "LC_time incorrect")
  86. LT = _strptime.LocaleTime()
  87. LT.am_pm = ('', '')
  88. self.assertTrue(LT.LC_time, "LocaleTime's LC directives cannot handle "
  89. "empty strings")
  90. def test_lang(self):
  91. # Make sure lang is set to what _getlang() returns
  92. # Assuming locale has not changed between now and when self.LT_ins was created
  93. self.assertEqual(self.LT_ins.lang, _strptime._getlang())
  94. class TimeRETests(unittest.TestCase):
  95. """Tests for TimeRE."""
  96. def setUp(self):
  97. """Construct generic TimeRE object."""
  98. self.time_re = _strptime.TimeRE()
  99. self.locale_time = _strptime.LocaleTime()
  100. def test_pattern(self):
  101. # Test TimeRE.pattern
  102. pattern_string = self.time_re.pattern(r"%a %A %d")
  103. self.assertTrue(pattern_string.find(self.locale_time.a_weekday[2]) != -1,
  104. "did not find abbreviated weekday in pattern string '%s'" %
  105. pattern_string)
  106. self.assertTrue(pattern_string.find(self.locale_time.f_weekday[4]) != -1,
  107. "did not find full weekday in pattern string '%s'" %
  108. pattern_string)
  109. self.assertTrue(pattern_string.find(self.time_re['d']) != -1,
  110. "did not find 'd' directive pattern string '%s'" %
  111. pattern_string)
  112. def test_pattern_escaping(self):
  113. # Make sure any characters in the format string that might be taken as
  114. # regex syntax is escaped.
  115. pattern_string = self.time_re.pattern("\d+")
  116. self.assertIn(r"\\d\+", pattern_string,
  117. "%s does not have re characters escaped properly" %
  118. pattern_string)
  119. def test_compile(self):
  120. # Check that compiled regex is correct
  121. found = self.time_re.compile(r"%A").match(self.locale_time.f_weekday[6])
  122. self.assertTrue(found and found.group('A') == self.locale_time.f_weekday[6],
  123. "re object for '%A' failed")
  124. compiled = self.time_re.compile(r"%a %b")
  125. found = compiled.match("%s %s" % (self.locale_time.a_weekday[4],
  126. self.locale_time.a_month[4]))
  127. self.assertTrue(found,
  128. "Match failed with '%s' regex and '%s' string" %
  129. (compiled.pattern, "%s %s" % (self.locale_time.a_weekday[4],
  130. self.locale_time.a_month[4])))
  131. self.assertTrue(found.group('a') == self.locale_time.a_weekday[4] and
  132. found.group('b') == self.locale_time.a_month[4],
  133. "re object couldn't find the abbreviated weekday month in "
  134. "'%s' using '%s'; group 'a' = '%s', group 'b' = %s'" %
  135. (found.string, found.re.pattern, found.group('a'),
  136. found.group('b')))
  137. for directive in ('a','A','b','B','c','d','H','I','j','m','M','p','S',
  138. 'U','w','W','x','X','y','Y','Z','%'):
  139. compiled = self.time_re.compile("%" + directive)
  140. found = compiled.match(time.strftime("%" + directive))
  141. self.assertTrue(found, "Matching failed on '%s' using '%s' regex" %
  142. (time.strftime("%" + directive),
  143. compiled.pattern))
  144. def test_blankpattern(self):
  145. # Make sure when tuple or something has no values no regex is generated.
  146. # Fixes bug #661354
  147. test_locale = _strptime.LocaleTime()
  148. test_locale.timezone = (frozenset(), frozenset())
  149. self.assertTrue(_strptime.TimeRE(test_locale).pattern("%Z") == '',
  150. "with timezone == ('',''), TimeRE().pattern('%Z') != ''")
  151. def test_matching_with_escapes(self):
  152. # Make sure a format that requires escaping of characters works
  153. compiled_re = self.time_re.compile("\w+ %m")
  154. found = compiled_re.match("\w+ 10")
  155. self.assertTrue(found, "Escaping failed of format '\w+ 10'")
  156. def test_locale_data_w_regex_metacharacters(self):
  157. # Check that if locale data contains regex metacharacters they are
  158. # escaped properly.
  159. # Discovered by bug #1039270 .
  160. locale_time = _strptime.LocaleTime()
  161. locale_time.timezone = (frozenset(("utc", "gmt",
  162. "Tokyo (standard time)")),
  163. frozenset("Tokyo (daylight time)"))
  164. time_re = _strptime.TimeRE(locale_time)
  165. self.assertTrue(time_re.compile("%Z").match("Tokyo (standard time)"),
  166. "locale data that contains regex metacharacters is not"
  167. " properly escaped")
  168. def test_whitespace_substitution(self):
  169. # When pattern contains whitespace, make sure it is taken into account
  170. # so as to not allow to subpatterns to end up next to each other and
  171. # "steal" characters from each other.
  172. pattern = self.time_re.pattern('%j %H')
  173. self.assertTrue(not re.match(pattern, "180"))
  174. self.assertTrue(re.match(pattern, "18 0"))
  175. class StrptimeTests(unittest.TestCase):
  176. """Tests for _strptime.strptime."""
  177. def setUp(self):
  178. """Create testing time tuple."""
  179. self.time_tuple = time.gmtime()
  180. def test_ValueError(self):
  181. # Make sure ValueError is raised when match fails or format is bad
  182. self.assertRaises(ValueError, _strptime._strptime_time, data_string="%d",
  183. format="%A")
  184. for bad_format in ("%", "% ", "%e"):
  185. try:
  186. _strptime._strptime_time("2005", bad_format)
  187. except ValueError:
  188. continue
  189. except Exception, err:
  190. self.fail("'%s' raised %s, not ValueError" %
  191. (bad_format, err.__class__.__name__))
  192. else:
  193. self.fail("'%s' did not raise ValueError" % bad_format)
  194. def test_unconverteddata(self):
  195. # Check ValueError is raised when there is unconverted data
  196. self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")
  197. def helper(self, directive, position):
  198. """Helper fxn in testing."""
  199. strf_output = time.strftime("%" + directive, self.time_tuple)
  200. strp_output = _strptime._strptime_time(strf_output, "%" + directive)
  201. self.assertTrue(strp_output[position] == self.time_tuple[position],
  202. "testing of '%s' directive failed; '%s' -> %s != %s" %
  203. (directive, strf_output, strp_output[position],
  204. self.time_tuple[position]))
  205. def test_year(self):
  206. # Test that the year is handled properly
  207. for directive in ('y', 'Y'):
  208. self.helper(directive, 0)
  209. # Must also make sure %y values are correct for bounds set by Open Group
  210. for century, bounds in ((1900, ('69', '99')), (2000, ('00', '68'))):
  211. for bound in bounds:
  212. strp_output = _strptime._strptime_time(bound, '%y')
  213. expected_result = century + int(bound)
  214. self.assertTrue(strp_output[0] == expected_result,
  215. "'y' test failed; passed in '%s' "
  216. "and returned '%s'" % (bound, strp_output[0]))
  217. def test_month(self):
  218. # Test for month directives
  219. for directive in ('B', 'b', 'm'):
  220. self.helper(directive, 1)
  221. def test_day(self):
  222. # Test for day directives
  223. self.helper('d', 2)
  224. def test_hour(self):
  225. # Test hour directives
  226. self.helper('H', 3)
  227. strf_output = time.strftime("%I %p", self.time_tuple)
  228. strp_output = _strptime._strptime_time(strf_output, "%I %p")
  229. self.assertTrue(strp_output[3] == self.time_tuple[3],
  230. "testing of '%%I %%p' directive failed; '%s' -> %s != %s" %
  231. (strf_output, strp_output[3], self.time_tuple[3]))
  232. def test_minute(self):
  233. # Test minute directives
  234. self.helper('M', 4)
  235. def test_second(self):
  236. # Test second directives
  237. self.helper('S', 5)
  238. def test_fraction(self):
  239. # Test microseconds
  240. import datetime
  241. d = datetime.datetime(2012, 12, 20, 12, 34, 56, 78987)
  242. tup, frac = _strptime._strptime(str(d), format="%Y-%m-%d %H:%M:%S.%f")
  243. self.assertEqual(frac, d.microsecond)
  244. def test_weekday(self):
  245. # Test weekday directives
  246. for directive in ('A', 'a', 'w'):
  247. self.helper(directive,6)
  248. def test_julian(self):
  249. # Test julian directives
  250. self.helper('j', 7)
  251. def test_timezone(self):
  252. # Test timezone directives.
  253. # When gmtime() is used with %Z, entire result of strftime() is empty.
  254. # Check for equal timezone names deals with bad locale info when this
  255. # occurs; first found in FreeBSD 4.4.
  256. strp_output = _strptime._strptime_time("UTC", "%Z")
  257. self.assertEqual(strp_output.tm_isdst, 0)
  258. strp_output = _strptime._strptime_time("GMT", "%Z")
  259. self.assertEqual(strp_output.tm_isdst, 0)
  260. time_tuple = time.localtime()
  261. strf_output = time.strftime("%Z") #UTC does not have a timezone
  262. strp_output = _strptime._strptime_time(strf_output, "%Z")
  263. locale_time = _strptime.LocaleTime()
  264. if time.tzname[0] != time.tzname[1] or not time.daylight:
  265. self.assertTrue(strp_output[8] == time_tuple[8],
  266. "timezone check failed; '%s' -> %s != %s" %
  267. (strf_output, strp_output[8], time_tuple[8]))
  268. else:
  269. self.assertTrue(strp_output[8] == -1,
  270. "LocaleTime().timezone has duplicate values and "
  271. "time.daylight but timezone value not set to -1")
  272. def test_bad_timezone(self):
  273. # Explicitly test possibility of bad timezone;
  274. # when time.tzname[0] == time.tzname[1] and time.daylight
  275. tz_name = time.tzname[0]
  276. if tz_name.upper() in ("UTC", "GMT"):
  277. return
  278. try:
  279. original_tzname = time.tzname
  280. original_daylight = time.daylight
  281. time.tzname = (tz_name, tz_name)
  282. time.daylight = 1
  283. tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
  284. self.assertEqual(tz_value, -1,
  285. "%s lead to a timezone value of %s instead of -1 when "
  286. "time.daylight set to %s and passing in %s" %
  287. (time.tzname, tz_value, time.daylight, tz_name))
  288. finally:
  289. time.tzname = original_tzname
  290. time.daylight = original_daylight
  291. def test_date_time(self):
  292. # Test %c directive
  293. for position in range(6):
  294. self.helper('c', position)
  295. def test_date(self):
  296. # Test %x directive
  297. for position in range(0,3):
  298. self.helper('x', position)
  299. def test_time(self):
  300. # Test %X directive
  301. for position in range(3,6):
  302. self.helper('X', position)
  303. def test_percent(self):
  304. # Make sure % signs are handled properly
  305. strf_output = time.strftime("%m %% %Y", self.time_tuple)
  306. strp_output = _strptime._strptime_time(strf_output, "%m %% %Y")
  307. self.assertTrue(strp_output[0] == self.time_tuple[0] and
  308. strp_output[1] == self.time_tuple[1],
  309. "handling of percent sign failed")
  310. def test_caseinsensitive(self):
  311. # Should handle names case-insensitively.
  312. strf_output = time.strftime("%B", self.time_tuple)
  313. self.assertTrue(_strptime._strptime_time(strf_output.upper(), "%B"),
  314. "strptime does not handle ALL-CAPS names properly")
  315. self.assertTrue(_strptime._strptime_time(strf_output.lower(), "%B"),
  316. "strptime does not handle lowercase names properly")
  317. self.assertTrue(_strptime._strptime_time(strf_output.capitalize(), "%B"),
  318. "strptime does not handle capword names properly")
  319. def test_defaults(self):
  320. # Default return value should be (1900, 1, 1, 0, 0, 0, 0, 1, 0)
  321. defaults = (1900, 1, 1, 0, 0, 0, 0, 1, -1)
  322. strp_output = _strptime._strptime_time('1', '%m')
  323. self.assertTrue(strp_output == defaults,
  324. "Default values for strptime() are incorrect;"
  325. " %s != %s" % (strp_output, defaults))
  326. def test_escaping(self):
  327. # Make sure all characters that have regex significance are escaped.
  328. # Parentheses are in a purposeful order; will cause an error of
  329. # unbalanced parentheses when the regex is compiled if they are not
  330. # escaped.
  331. # Test instigated by bug #796149 .
  332. need_escaping = ".^$*+?{}\[]|)("
  333. self.assertTrue(_strptime._strptime_time(need_escaping, need_escaping))
  334. class Strptime12AMPMTests(unittest.TestCase):
  335. """Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
  336. def test_twelve_noon_midnight(self):
  337. eq = self.assertEqual
  338. eq(time.strptime('12 PM', '%I %p')[3], 12)
  339. eq(time.strptime('12 AM', '%I %p')[3], 0)
  340. eq(_strptime._strptime_time('12 PM', '%I %p')[3], 12)
  341. eq(_strptime._strptime_time('12 AM', '%I %p')[3], 0)
  342. class JulianTests(unittest.TestCase):
  343. """Test a _strptime regression that all julian (1-366) are accepted"""
  344. def test_all_julian_days(self):
  345. eq = self.assertEqual
  346. for i in range(1, 367):
  347. # use 2004, since it is a leap year, we have 366 days
  348. eq(_strptime._strptime_time('%d 2004' % i, '%j %Y')[7], i)
  349. class CalculationTests(unittest.TestCase):
  350. """Test that strptime() fills in missing info correctly"""
  351. def setUp(self):
  352. self.time_tuple = time.gmtime()
  353. def test_julian_calculation(self):
  354. # Make sure that when Julian is missing that it is calculated
  355. format_string = "%Y %m %d %H %M %S %w %Z"
  356. result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
  357. format_string)
  358. self.assertTrue(result.tm_yday == self.time_tuple.tm_yday,
  359. "Calculation of tm_yday failed; %s != %s" %
  360. (result.tm_yday, self.time_tuple.tm_yday))
  361. def test_gregorian_calculation(self):
  362. # Test that Gregorian date can be calculated from Julian day
  363. format_string = "%Y %H %M %S %w %j %Z"
  364. result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
  365. format_string)
  366. self.assertTrue(result.tm_year == self.time_tuple.tm_year and
  367. result.tm_mon == self.time_tuple.tm_mon and
  368. result.tm_mday == self.time_tuple.tm_mday,
  369. "Calculation of Gregorian date failed;"
  370. "%s-%s-%s != %s-%s-%s" %
  371. (result.tm_year, result.tm_mon, result.tm_mday,
  372. self.time_tuple.tm_year, self.time_tuple.tm_mon,
  373. self.time_tuple.tm_mday))
  374. def test_day_of_week_calculation(self):
  375. # Test that the day of the week is calculated as needed
  376. format_string = "%Y %m %d %H %S %j %Z"
  377. result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
  378. format_string)
  379. self.assertTrue(result.tm_wday == self.time_tuple.tm_wday,
  380. "Calculation of day of the week failed;"
  381. "%s != %s" % (result.tm_wday, self.time_tuple.tm_wday))
  382. def test_week_of_year_and_day_of_week_calculation(self):
  383. # Should be able to infer date if given year, week of year (%U or %W)
  384. # and day of the week
  385. def test_helper(ymd_tuple, test_reason):
  386. for directive in ('W', 'U'):
  387. format_string = "%%Y %%%s %%w" % directive
  388. dt_date = datetime_date(*ymd_tuple)
  389. strp_input = dt_date.strftime(format_string)
  390. strp_output = _strptime._strptime_time(strp_input, format_string)
  391. self.assertTrue(strp_output[:3] == ymd_tuple,
  392. "%s(%s) test failed w/ '%s': %s != %s (%s != %s)" %
  393. (test_reason, directive, strp_input,
  394. strp_output[:3], ymd_tuple,
  395. strp_output[7], dt_date.timetuple()[7]))
  396. test_helper((1901, 1, 3), "week 0")
  397. test_helper((1901, 1, 8), "common case")
  398. test_helper((1901, 1, 13), "day on Sunday")
  399. test_helper((1901, 1, 14), "day on Monday")
  400. test_helper((1905, 1, 1), "Jan 1 on Sunday")
  401. test_helper((1906, 1, 1), "Jan 1 on Monday")
  402. test_helper((1906, 1, 7), "first Sunday in a year starting on Monday")
  403. test_helper((1905, 12, 31), "Dec 31 on Sunday")
  404. test_helper((1906, 12, 31), "Dec 31 on Monday")
  405. test_helper((2008, 12, 29), "Monday in the last week of the year")
  406. test_helper((2008, 12, 22), "Monday in the second-to-last week of the "
  407. "year")
  408. test_helper((1978, 10, 23), "randomly chosen date")
  409. test_helper((2004, 12, 18), "randomly chosen date")
  410. test_helper((1978, 10, 23), "year starting and ending on Monday while "
  411. "date not on Sunday or Monday")
  412. test_helper((1917, 12, 17), "year starting and ending on Monday with "
  413. "a Monday not at the beginning or end "
  414. "of the year")
  415. test_helper((1917, 12, 31), "Dec 31 on Monday with year starting and "
  416. "ending on Monday")
  417. test_helper((2007, 01, 07), "First Sunday of 2007")
  418. test_helper((2007, 01, 14), "Second Sunday of 2007")
  419. test_helper((2006, 12, 31), "Last Sunday of 2006")
  420. test_helper((2006, 12, 24), "Second to last Sunday of 2006")
  421. class CacheTests(unittest.TestCase):
  422. """Test that caching works properly."""
  423. def test_time_re_recreation(self):
  424. # Make sure cache is recreated when current locale does not match what
  425. # cached object was created with.
  426. _strptime._strptime_time("10", "%d")
  427. _strptime._strptime_time("2005", "%Y")
  428. _strptime._TimeRE_cache.locale_time.lang = "Ni"
  429. original_time_re = _strptime._TimeRE_cache
  430. _strptime._strptime_time("10", "%d")
  431. self.assertIsNot(original_time_re, _strptime._TimeRE_cache)
  432. self.assertEqual(len(_strptime._regex_cache), 1)
  433. def test_regex_cleanup(self):
  434. # Make sure cached regexes are discarded when cache becomes "full".
  435. try:
  436. del _strptime._regex_cache['%d']
  437. except KeyError:
  438. pass
  439. bogus_key = 0
  440. while len(_strptime._regex_cache) <= _strptime._CACHE_MAX_SIZE:
  441. _strptime._regex_cache[bogus_key] = None
  442. bogus_key += 1
  443. _strptime._strptime_time("10", "%d")
  444. self.assertEqual(len(_strptime._regex_cache), 1)
  445. def test_new_localetime(self):
  446. # A new LocaleTime instance should be created when a new TimeRE object
  447. # is created.
  448. locale_time_id = _strptime._TimeRE_cache.locale_time
  449. _strptime._TimeRE_cache.locale_time.lang = "Ni"
  450. _strptime._strptime_time("10", "%d")
  451. self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time)
  452. def test_TimeRE_recreation(self):
  453. # The TimeRE instance should be recreated upon changing the locale.
  454. locale_info = locale.getlocale(locale.LC_TIME)
  455. try:
  456. locale.setlocale(locale.LC_TIME, ('en_US', 'UTF8'))
  457. except locale.Error:
  458. return
  459. try:
  460. _strptime._strptime_time('10', '%d')
  461. # Get id of current cache object.
  462. first_time_re = _strptime._TimeRE_cache
  463. try:
  464. # Change the locale and force a recreation of the cache.
  465. locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8'))
  466. _strptime._strptime_time('10', '%d')
  467. # Get the new cache object's id.
  468. second_time_re = _strptime._TimeRE_cache
  469. # They should not be equal.
  470. self.assertIsNot(first_time_re, second_time_re)
  471. # Possible test locale is not supported while initial locale is.
  472. # If this is the case just suppress the exception and fall-through
  473. # to the resetting to the original locale.
  474. except locale.Error:
  475. pass
  476. # Make sure we don't trample on the locale setting once we leave the
  477. # test.
  478. finally:
  479. locale.setlocale(locale.LC_TIME, locale_info)
  480. def test_main():
  481. test_support.run_unittest(
  482. getlang_Tests,
  483. LocaleTime_Tests,
  484. TimeRETests,
  485. StrptimeTests,
  486. Strptime12AMPMTests,
  487. JulianTests,
  488. CalculationTests,
  489. CacheTests
  490. )
  491. if __name__ == '__main__':
  492. test_main()