/Lib/test/test_strptime.py

http://unladen-swallow.googlecode.com/ · Python · 567 lines · 436 code · 51 blank · 80 comment · 30 complexity · 22dd3847fce2ad518511470930ece64f 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.failUnlessEqual(_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.failUnless(strftime_output in testing, "%s: not found in tuple" %
  31. error_msg)
  32. self.failUnless(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.failUnless(strftime_output in 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.failUnless(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.failUnless(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.failUnless(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.failUnless(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.failUnless(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.failUnless(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.failUnlessEqual(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.failUnless(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.failUnless(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.failUnless(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.failUnless(r"\\d\+" in 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.failUnless(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.failUnless(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.failUnless(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.failUnless(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.failUnless(_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.failUnless(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.failUnless(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.failUnless(not re.match(pattern, "180"))
  174. self.failUnless(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.failUnless(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.failUnless(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.failUnless(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. import datetime
  240. now = datetime.datetime.now()
  241. tup, frac = _strptime._strptime(str(now), format="%Y-%m-%d %H:%M:%S.%f")
  242. self.assertEqual(frac, now.microsecond)
  243. def test_weekday(self):
  244. # Test weekday directives
  245. for directive in ('A', 'a', 'w'):
  246. self.helper(directive,6)
  247. def test_julian(self):
  248. # Test julian directives
  249. self.helper('j', 7)
  250. def test_timezone(self):
  251. # Test timezone directives.
  252. # When gmtime() is used with %Z, entire result of strftime() is empty.
  253. # Check for equal timezone names deals with bad locale info when this
  254. # occurs; first found in FreeBSD 4.4.
  255. strp_output = _strptime._strptime_time("UTC", "%Z")
  256. self.failUnlessEqual(strp_output.tm_isdst, 0)
  257. strp_output = _strptime._strptime_time("GMT", "%Z")
  258. self.failUnlessEqual(strp_output.tm_isdst, 0)
  259. if sys.platform == "mac":
  260. # Timezones don't really work on MacOS9
  261. return
  262. time_tuple = time.localtime()
  263. strf_output = time.strftime("%Z") #UTC does not have a timezone
  264. strp_output = _strptime._strptime_time(strf_output, "%Z")
  265. locale_time = _strptime.LocaleTime()
  266. if time.tzname[0] != time.tzname[1] or not time.daylight:
  267. self.failUnless(strp_output[8] == time_tuple[8],
  268. "timezone check failed; '%s' -> %s != %s" %
  269. (strf_output, strp_output[8], time_tuple[8]))
  270. else:
  271. self.failUnless(strp_output[8] == -1,
  272. "LocaleTime().timezone has duplicate values and "
  273. "time.daylight but timezone value not set to -1")
  274. def test_bad_timezone(self):
  275. # Explicitly test possibility of bad timezone;
  276. # when time.tzname[0] == time.tzname[1] and time.daylight
  277. if sys.platform == "mac":
  278. return #MacOS9 has severely broken timezone support.
  279. tz_name = time.tzname[0]
  280. if tz_name.upper() in ("UTC", "GMT"):
  281. return
  282. try:
  283. original_tzname = time.tzname
  284. original_daylight = time.daylight
  285. time.tzname = (tz_name, tz_name)
  286. time.daylight = 1
  287. tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
  288. self.failUnlessEqual(tz_value, -1,
  289. "%s lead to a timezone value of %s instead of -1 when "
  290. "time.daylight set to %s and passing in %s" %
  291. (time.tzname, tz_value, time.daylight, tz_name))
  292. finally:
  293. time.tzname = original_tzname
  294. time.daylight = original_daylight
  295. def test_date_time(self):
  296. # Test %c directive
  297. for position in range(6):
  298. self.helper('c', position)
  299. def test_date(self):
  300. # Test %x directive
  301. for position in range(0,3):
  302. self.helper('x', position)
  303. def test_time(self):
  304. # Test %X directive
  305. for position in range(3,6):
  306. self.helper('X', position)
  307. def test_percent(self):
  308. # Make sure % signs are handled properly
  309. strf_output = time.strftime("%m %% %Y", self.time_tuple)
  310. strp_output = _strptime._strptime_time(strf_output, "%m %% %Y")
  311. self.failUnless(strp_output[0] == self.time_tuple[0] and
  312. strp_output[1] == self.time_tuple[1],
  313. "handling of percent sign failed")
  314. def test_caseinsensitive(self):
  315. # Should handle names case-insensitively.
  316. strf_output = time.strftime("%B", self.time_tuple)
  317. self.failUnless(_strptime._strptime_time(strf_output.upper(), "%B"),
  318. "strptime does not handle ALL-CAPS names properly")
  319. self.failUnless(_strptime._strptime_time(strf_output.lower(), "%B"),
  320. "strptime does not handle lowercase names properly")
  321. self.failUnless(_strptime._strptime_time(strf_output.capitalize(), "%B"),
  322. "strptime does not handle capword names properly")
  323. def test_defaults(self):
  324. # Default return value should be (1900, 1, 1, 0, 0, 0, 0, 1, 0)
  325. defaults = (1900, 1, 1, 0, 0, 0, 0, 1, -1)
  326. strp_output = _strptime._strptime_time('1', '%m')
  327. self.failUnless(strp_output == defaults,
  328. "Default values for strptime() are incorrect;"
  329. " %s != %s" % (strp_output, defaults))
  330. def test_escaping(self):
  331. # Make sure all characters that have regex significance are escaped.
  332. # Parentheses are in a purposeful order; will cause an error of
  333. # unbalanced parentheses when the regex is compiled if they are not
  334. # escaped.
  335. # Test instigated by bug #796149 .
  336. need_escaping = ".^$*+?{}\[]|)("
  337. self.failUnless(_strptime._strptime_time(need_escaping, need_escaping))
  338. class Strptime12AMPMTests(unittest.TestCase):
  339. """Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
  340. def test_twelve_noon_midnight(self):
  341. eq = self.assertEqual
  342. eq(time.strptime('12 PM', '%I %p')[3], 12)
  343. eq(time.strptime('12 AM', '%I %p')[3], 0)
  344. eq(_strptime._strptime_time('12 PM', '%I %p')[3], 12)
  345. eq(_strptime._strptime_time('12 AM', '%I %p')[3], 0)
  346. class JulianTests(unittest.TestCase):
  347. """Test a _strptime regression that all julian (1-366) are accepted"""
  348. def test_all_julian_days(self):
  349. eq = self.assertEqual
  350. for i in range(1, 367):
  351. # use 2004, since it is a leap year, we have 366 days
  352. eq(_strptime._strptime_time('%d 2004' % i, '%j %Y')[7], i)
  353. class CalculationTests(unittest.TestCase):
  354. """Test that strptime() fills in missing info correctly"""
  355. def setUp(self):
  356. self.time_tuple = time.gmtime()
  357. def test_julian_calculation(self):
  358. # Make sure that when Julian is missing that it is calculated
  359. format_string = "%Y %m %d %H %M %S %w %Z"
  360. result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
  361. format_string)
  362. self.failUnless(result.tm_yday == self.time_tuple.tm_yday,
  363. "Calculation of tm_yday failed; %s != %s" %
  364. (result.tm_yday, self.time_tuple.tm_yday))
  365. def test_gregorian_calculation(self):
  366. # Test that Gregorian date can be calculated from Julian day
  367. format_string = "%Y %H %M %S %w %j %Z"
  368. result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
  369. format_string)
  370. self.failUnless(result.tm_year == self.time_tuple.tm_year and
  371. result.tm_mon == self.time_tuple.tm_mon and
  372. result.tm_mday == self.time_tuple.tm_mday,
  373. "Calculation of Gregorian date failed;"
  374. "%s-%s-%s != %s-%s-%s" %
  375. (result.tm_year, result.tm_mon, result.tm_mday,
  376. self.time_tuple.tm_year, self.time_tuple.tm_mon,
  377. self.time_tuple.tm_mday))
  378. def test_day_of_week_calculation(self):
  379. # Test that the day of the week is calculated as needed
  380. format_string = "%Y %m %d %H %S %j %Z"
  381. result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
  382. format_string)
  383. self.failUnless(result.tm_wday == self.time_tuple.tm_wday,
  384. "Calculation of day of the week failed;"
  385. "%s != %s" % (result.tm_wday, self.time_tuple.tm_wday))
  386. def test_week_of_year_and_day_of_week_calculation(self):
  387. # Should be able to infer date if given year, week of year (%U or %W)
  388. # and day of the week
  389. def test_helper(ymd_tuple, test_reason):
  390. for directive in ('W', 'U'):
  391. format_string = "%%Y %%%s %%w" % directive
  392. dt_date = datetime_date(*ymd_tuple)
  393. strp_input = dt_date.strftime(format_string)
  394. strp_output = _strptime._strptime_time(strp_input, format_string)
  395. self.failUnless(strp_output[:3] == ymd_tuple,
  396. "%s(%s) test failed w/ '%s': %s != %s (%s != %s)" %
  397. (test_reason, directive, strp_input,
  398. strp_output[:3], ymd_tuple,
  399. strp_output[7], dt_date.timetuple()[7]))
  400. test_helper((1901, 1, 3), "week 0")
  401. test_helper((1901, 1, 8), "common case")
  402. test_helper((1901, 1, 13), "day on Sunday")
  403. test_helper((1901, 1, 14), "day on Monday")
  404. test_helper((1905, 1, 1), "Jan 1 on Sunday")
  405. test_helper((1906, 1, 1), "Jan 1 on Monday")
  406. test_helper((1906, 1, 7), "first Sunday in a year starting on Monday")
  407. test_helper((1905, 12, 31), "Dec 31 on Sunday")
  408. test_helper((1906, 12, 31), "Dec 31 on Monday")
  409. test_helper((2008, 12, 29), "Monday in the last week of the year")
  410. test_helper((2008, 12, 22), "Monday in the second-to-last week of the "
  411. "year")
  412. test_helper((1978, 10, 23), "randomly chosen date")
  413. test_helper((2004, 12, 18), "randomly chosen date")
  414. test_helper((1978, 10, 23), "year starting and ending on Monday while "
  415. "date not on Sunday or Monday")
  416. test_helper((1917, 12, 17), "year starting and ending on Monday with "
  417. "a Monday not at the beginning or end "
  418. "of the year")
  419. test_helper((1917, 12, 31), "Dec 31 on Monday with year starting and "
  420. "ending on Monday")
  421. test_helper((2007, 01, 07), "First Sunday of 2007")
  422. test_helper((2007, 01, 14), "Second Sunday of 2007")
  423. test_helper((2006, 12, 31), "Last Sunday of 2006")
  424. test_helper((2006, 12, 24), "Second to last Sunday of 2006")
  425. class CacheTests(unittest.TestCase):
  426. """Test that caching works properly."""
  427. def test_time_re_recreation(self):
  428. # Make sure cache is recreated when current locale does not match what
  429. # cached object was created with.
  430. _strptime._strptime_time("10", "%d")
  431. _strptime._strptime_time("2005", "%Y")
  432. _strptime._TimeRE_cache.locale_time.lang = "Ni"
  433. original_time_re = id(_strptime._TimeRE_cache)
  434. _strptime._strptime_time("10", "%d")
  435. self.failIfEqual(original_time_re, id(_strptime._TimeRE_cache))
  436. self.failUnlessEqual(len(_strptime._regex_cache), 1)
  437. def test_regex_cleanup(self):
  438. # Make sure cached regexes are discarded when cache becomes "full".
  439. try:
  440. del _strptime._regex_cache['%d']
  441. except KeyError:
  442. pass
  443. bogus_key = 0
  444. while len(_strptime._regex_cache) <= _strptime._CACHE_MAX_SIZE:
  445. _strptime._regex_cache[bogus_key] = None
  446. bogus_key += 1
  447. _strptime._strptime_time("10", "%d")
  448. self.failUnlessEqual(len(_strptime._regex_cache), 1)
  449. def test_new_localetime(self):
  450. # A new LocaleTime instance should be created when a new TimeRE object
  451. # is created.
  452. locale_time_id = id(_strptime._TimeRE_cache.locale_time)
  453. _strptime._TimeRE_cache.locale_time.lang = "Ni"
  454. _strptime._strptime_time("10", "%d")
  455. self.failIfEqual(locale_time_id,
  456. id(_strptime._TimeRE_cache.locale_time))
  457. def test_TimeRE_recreation(self):
  458. # The TimeRE instance should be recreated upon changing the locale.
  459. locale_info = locale.getlocale(locale.LC_TIME)
  460. try:
  461. locale.setlocale(locale.LC_TIME, ('en_US', 'UTF8'))
  462. except locale.Error:
  463. return
  464. try:
  465. _strptime._strptime_time('10', '%d')
  466. # Get id of current cache object.
  467. first_time_re_id = id(_strptime._TimeRE_cache)
  468. try:
  469. # Change the locale and force a recreation of the cache.
  470. locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8'))
  471. _strptime._strptime_time('10', '%d')
  472. # Get the new cache object's id.
  473. second_time_re_id = id(_strptime._TimeRE_cache)
  474. # They should not be equal.
  475. self.failIfEqual(first_time_re_id, second_time_re_id)
  476. # Possible test locale is not supported while initial locale is.
  477. # If this is the case just suppress the exception and fall-through
  478. # to the reseting to the original locale.
  479. except locale.Error:
  480. pass
  481. # Make sure we don't trample on the locale setting once we leave the
  482. # test.
  483. finally:
  484. locale.setlocale(locale.LC_TIME, locale_info)
  485. def test_main():
  486. test_support.run_unittest(
  487. getlang_Tests,
  488. LocaleTime_Tests,
  489. TimeRETests,
  490. StrptimeTests,
  491. Strptime12AMPMTests,
  492. JulianTests,
  493. CalculationTests,
  494. CacheTests
  495. )
  496. if __name__ == '__main__':
  497. test_main()