Back to index

python3.2  3.2.2
Public Member Functions
test.test_strptime.CacheTests Class Reference

List of all members.

Public Member Functions

def test_time_re_recreation
def test_regex_cleanup
def test_new_localetime
def test_TimeRE_recreation

Detailed Description

Test that caching works properly.

Definition at line 483 of file test_strptime.py.


Member Function Documentation

Definition at line 510 of file test_strptime.py.

00510 
00511     def test_new_localetime(self):
00512         # A new LocaleTime instance should be created when a new TimeRE object
00513         # is created.
00514         locale_time_id = _strptime._TimeRE_cache.locale_time
00515         _strptime._TimeRE_cache.locale_time.lang = "Ni"
00516         _strptime._strptime_time("10", "%d")
00517         self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time)

Here is the call graph for this function:

Definition at line 497 of file test_strptime.py.

00497 
00498     def test_regex_cleanup(self):
00499         # Make sure cached regexes are discarded when cache becomes "full".
00500         try:
00501             del _strptime._regex_cache['%d']
00502         except KeyError:
00503             pass
00504         bogus_key = 0
00505         while len(_strptime._regex_cache) <= _strptime._CACHE_MAX_SIZE:
00506             _strptime._regex_cache[bogus_key] = None
00507             bogus_key += 1
00508         _strptime._strptime_time("10", "%d")
00509         self.assertEqual(len(_strptime._regex_cache), 1)

Here is the call graph for this function:

Definition at line 486 of file test_strptime.py.

00486 
00487     def test_time_re_recreation(self):
00488         # Make sure cache is recreated when current locale does not match what
00489         # cached object was created with.
00490         _strptime._strptime_time("10", "%d")
00491         _strptime._strptime_time("2005", "%Y")
00492         _strptime._TimeRE_cache.locale_time.lang = "Ni"
00493         original_time_re = _strptime._TimeRE_cache
00494         _strptime._strptime_time("10", "%d")
00495         self.assertIsNot(original_time_re, _strptime._TimeRE_cache)
00496         self.assertEqual(len(_strptime._regex_cache), 1)

Here is the call graph for this function:

Definition at line 518 of file test_strptime.py.

00518 
00519     def test_TimeRE_recreation(self):
00520         # The TimeRE instance should be recreated upon changing the locale.
00521         locale_info = locale.getlocale(locale.LC_TIME)
00522         try:
00523             locale.setlocale(locale.LC_TIME, ('en_US', 'UTF8'))
00524         except locale.Error:
00525             return
00526         try:
00527             _strptime._strptime_time('10', '%d')
00528             # Get id of current cache object.
00529             first_time_re = _strptime._TimeRE_cache
00530             try:
00531                 # Change the locale and force a recreation of the cache.
00532                 locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8'))
00533                 _strptime._strptime_time('10', '%d')
00534                 # Get the new cache object's id.
00535                 second_time_re = _strptime._TimeRE_cache
00536                 # They should not be equal.
00537                 self.assertIsNot(first_time_re, second_time_re)
00538             # Possible test locale is not supported while initial locale is.
00539             # If this is the case just suppress the exception and fall-through
00540             # to the resetting to the original locale.
00541             except locale.Error:
00542                 pass
00543         # Make sure we don't trample on the locale setting once we leave the
00544         # test.
00545         finally:
00546             locale.setlocale(locale.LC_TIME, locale_info)
00547 

Here is the call graph for this function:


The documentation for this class was generated from the following file: