Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
test.test_strftime.StrftimeTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_strftime
def strftest1
def strftest2

Public Attributes

 gmt
 ampm
 jan1
 tz
 clock12
 now

Private Member Functions

def _update_variables

Detailed Description

Definition at line 32 of file test_strftime.py.


Member Function Documentation

def test.test_strftime.StrftimeTest._update_variables (   self,
  now 
) [private]

Definition at line 34 of file test_strftime.py.

00034 
00035     def _update_variables(self, now):
00036         # we must update the local variables on every cycle
00037         self.gmt = time.gmtime(now)
00038         now = time.localtime(now)
00039 
00040         if now[3] < 12: self.ampm='(AM|am)'
00041         else: self.ampm='(PM|pm)'
00042 
00043         self.jan1 = time.localtime(time.mktime((now[0], 1, 1, 0, 0, 0, 0, 1, 0)))
00044 
00045         try:
00046             if now[8]: self.tz = time.tzname[1]
00047             else: self.tz = time.tzname[0]
00048         except AttributeError:
00049             self.tz = ''
00050 
00051         if now[3] > 12: self.clock12 = now[3] - 12
00052         elif now[3] > 0: self.clock12 = now[3]
00053         else: self.clock12 = 12
00054 
00055         self.now = now

Here is the caller graph for this function:

Definition at line 56 of file test_strftime.py.

00056 
00057     def setUp(self):
00058         try:
00059             import java
00060             java.util.Locale.setDefault(java.util.Locale.US)
00061         except ImportError:
00062             import locale
00063             locale.setlocale(locale.LC_TIME, 'C')

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_strftime.StrftimeTest.strftest1 (   self,
  now 
)

Definition at line 81 of file test_strftime.py.

00081 
00082     def strftest1(self, now):
00083         if support.verbose:
00084             print("strftime test for", time.ctime(now))
00085         now = self.now
00086         # Make sure any characters that could be taken as regex syntax is
00087         # escaped in escapestr()
00088         expectations = (
00089             ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
00090             ('%A', calendar.day_name[now[6]], 'full weekday name'),
00091             ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
00092             ('%B', calendar.month_name[now[1]], 'full month name'),
00093             # %c see below
00094             ('%d', '%02d' % now[2], 'day of month as number (00-31)'),
00095             ('%H', '%02d' % now[3], 'hour (00-23)'),
00096             ('%I', '%02d' % self.clock12, 'hour (01-12)'),
00097             ('%j', '%03d' % now[7], 'julian day (001-366)'),
00098             ('%m', '%02d' % now[1], 'month as number (01-12)'),
00099             ('%M', '%02d' % now[4], 'minute, (00-59)'),
00100             ('%p', self.ampm, 'AM or PM as appropriate'),
00101             ('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
00102             ('%U', '%02d' % ((now[7] + self.jan1[6])//7),
00103              'week number of the year (Sun 1st)'),
00104             ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
00105             ('%W', '%02d' % ((now[7] + (self.jan1[6] - 1)%7)//7),
00106             'week number of the year (Mon 1st)'),
00107             # %x see below
00108             ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
00109             ('%y', '%02d' % (now[0]%100), 'year without century'),
00110             ('%Y', '%d' % now[0], 'year with century'),
00111             # %Z see below
00112             ('%%', '%', 'single percent sign'),
00113         )
00114 
00115         for e in expectations:
00116             # musn't raise a value error
00117             try:
00118                 result = time.strftime(e[0], now)
00119             except ValueError as error:
00120                 self.fail("strftime '%s' format gave error: %s" % (e[0], error))
00121             if re.match(escapestr(e[1], self.ampm), result):
00122                 continue
00123             if not result or result[0] == '%':
00124                 self.fail("strftime does not support standard '%s' format (%s)"
00125                           % (e[0], e[2]))
00126             else:
00127                 self.fail("Conflict for %s (%s): expected %s, but got %s"
00128                           % (e[0], e[2], e[1], result))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_strftime.StrftimeTest.strftest2 (   self,
  now 
)

Definition at line 129 of file test_strftime.py.

00129 
00130     def strftest2(self, now):
00131         nowsecs = str(int(now))[:-1]
00132         now = self.now
00133 
00134         nonstandard_expectations = (
00135         # These are standard but don't have predictable output
00136             ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
00137             ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
00138             '%m/%d/%y %H:%M:%S'),
00139             ('%Z', '%s' % self.tz, 'time zone name'),
00140 
00141             # These are some platform specific extensions
00142             ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
00143             ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'),
00144             ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
00145             ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
00146             ('%n', '\n', 'newline character'),
00147             ('%r', '%02d:%02d:%02d %s' % (self.clock12, now[4], now[5], self.ampm),
00148             '%I:%M:%S %p'),
00149             ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
00150             ('%s', nowsecs, 'seconds since the Epoch in UCT'),
00151             ('%t', '\t', 'tab character'),
00152             ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
00153             ('%3y', '%03d' % (now[0]%100),
00154             'year without century rendered using fieldwidth'),
00155         )
00156 
00157 
00158         for e in nonstandard_expectations:
00159             try:
00160                 result = time.strftime(e[0], now)
00161             except ValueError as result:
00162                 msg = "Error for nonstandard '%s' format (%s): %s" % \
00163                       (e[0], e[2], str(result))
00164                 if support.verbose:
00165                     print(msg)
00166                 continue
00167             if re.match(escapestr(e[1], self.ampm), result):
00168                 if support.verbose:
00169                     print("Supports nonstandard '%s' format (%s)" % (e[0], e[2]))
00170             elif not result or result[0] == '%':
00171                 if support.verbose:
00172                     print("Does not appear to support '%s' format (%s)" % \
00173                            (e[0], e[2]))
00174             else:
00175                 if support.verbose:
00176                     print("Conflict for nonstandard '%s' format (%s):" % \
00177                            (e[0], e[2]))
00178                     print("  Expected %s, but got %s" % (e[1], result))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file test_strftime.py.

00064 
00065     def test_strftime(self):
00066         now = time.time()
00067         self._update_variables(now)
00068         self.strftest1(now)
00069         self.strftest2(now)
00070 
00071         if support.verbose:
00072             print("Strftime test, platform: %s, Python version: %s" % \
00073                   (sys.platform, sys.version.split()[0]))
00074 
00075         for j in range(-5, 5):
00076             for i in range(25):
00077                 arg = now + (i+j*100)*23*3603
00078                 self._update_variables(arg)
00079                 self.strftest1(arg)
00080                 self.strftest2(arg)

Here is the call graph for this function:


Member Data Documentation

Definition at line 39 of file test_strftime.py.

Definition at line 50 of file test_strftime.py.

Definition at line 36 of file test_strftime.py.

Definition at line 42 of file test_strftime.py.

Definition at line 54 of file test_strftime.py.

Definition at line 45 of file test_strftime.py.


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