Ticket #1606 (closed defect: fixed)
Date formatting causes trac-admin unit tests to fail / trac-admin should use ISO format for datetimes
| Reported by: | Ian Leader <__ian.leader__@…> | Owned by: | cmlenz |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.9 |
| Component: | admin/console | Version: | devel |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Windows XP SP2 Python 2.3 UK Locale settings
On above platform, as of [1793], 5 unit tests in trac\scripts\tests\admin.py fail because of date formatting issues:
C:\temp\working\trac>python trac\scripts\tests\admin.py
.............F.F.F...................................F......F
======================================================================
FAIL: test_milestone_add_ok (__main__.TracadminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "trac\scripts\tests\admin.py", line 679, in test_milestone_add_ok
self.assertEquals(self.expected_results[test_name], test_results)
File "c:\python23\lib\unittest.py", line 302, in failUnlessEqual
raise self.failureException, \
AssertionError: '\nName Due Completed\n---------
-----------------------------------------\nnew_milestone Thu Jan 1 00:00:00 20
04\nmilestone1\nmilestone2\nmilestone3\nmilestone4\n\n' != '\nName Due
Completed\n-------------------------------------------\nnew_mile
stone 01/01/04 00:00:00\nmilestone1\nmilestone2\nmilestone3\nmilestone4\n\n'
======================================================================
FAIL: test_milestone_completed_ok (__main__.TracadminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "trac\scripts\tests\admin.py", line 741, in test_milestone_completed_ok
self.assertEquals(self.expected_results[test_name], test_results)
File "c:\python23\lib\unittest.py", line 302, in failUnlessEqual
raise self.failureException, \
AssertionError: '\nName Due Completed\n---------------------------------
--------\nmilestone1\nmilestone2 Thu Jan 1 00:00:00 2004\nmilestone3\nmil
estone4\n\n' != '\nName Due Completed\n---------------------------------
-\nmilestone1\nmilestone2 01/01/04 00:00:00\nmilestone3\nmilestone4\n\n'
======================================================================
FAIL: test_milestone_due_ok (__main__.TracadminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "trac\scripts\tests\admin.py", line 720, in test_milestone_due_ok
self.assertEquals(self.expected_results[test_name], test_results)
File "c:\python23\lib\unittest.py", line 302, in failUnlessEqual
raise self.failureException, \
AssertionError: '\nName Due Completed\n------------
-----------------------------------\nmilestone2 Thu Jan 1 00:00:00 2004\nmiles
tone1\nmilestone3\nmilestone4\n\n' != '\nName Due Complete
d\n----------------------------------------\nmilestone2 01/01/04 00:00:00\nmile
stone1\nmilestone3\nmilestone4\n\n'
======================================================================
FAIL: test_version_add_ok (__main__.TracadminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "trac\scripts\tests\admin.py", line 586, in test_version_add_ok
self.assertEquals(self.expected_results[test_name], test_results)
File "c:\python23\lib\unittest.py", line 302, in failUnlessEqual
raise self.failureException, \
AssertionError: '\nName Time\n------------------------------\n1.0\n2.0\n9.9 T
hu Jan 1 00:00:00 2004\n\n' != '\nName Time\n------------------------------\n1
.0\n2.0\n9.9 Thu Jan 01 00:00:00 2004\n\n'
======================================================================
FAIL: test_version_time_ok (__main__.TracadminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "trac\scripts\tests\admin.py", line 627, in test_version_time_ok
self.assertEquals(self.expected_results[test_name], test_results)
File "c:\python23\lib\unittest.py", line 302, in failUnlessEqual
raise self.failureException, \
AssertionError: '\nName Time\n------------------------------\n1.0\n2.0 Thu Ja
n 1 00:00:00 2004\n\n' != '\nName Time\n------------------------------\n1.0\n2
.0 Thu Jan 01 00:00:00 2004\n\n'
----------------------------------------------------------------------
Ran 61 tests in 2.464s
FAILED (failures=5)
C:\temp\working\trac>
There appear to be two distinct issues:
- Inconsistancies in the code for presentation of dates/times in trac-admin
- Differences in the formatting applied by time.strftime('%c', ...) on different platforms/locales
Inconsistancies in the date presentation in trac-admin
In admin.py, _do_version_list uses time.ctime, whereas _do_milestone_list uses time.strftime(c%, ...). These produce different formats on some platforms and locales.
(as an aside, _do_wiki_list also uses time.ctime and presents using yet another format)
This would probably be best resolved by modifying all commands in trac-admin to present in local time format using strftime(c%, ...)
Differences in formatting on different platforms/locales
The expected results for the trac-admin unit tests are hardcoded in admin-tests.txt. I'm guessing the format of the dates in this file is the default format on a European UNIX system of some flavour. The specific problem I'm seeing is that the day of month in 1st Jan 2004 is appearing as "1" in the expected results, but "01" on my system.
To get around this problem on my system, I can change 'new year' to be 11th Jan instead of 1st Jan, but this will not solve the problem for (e.g.) US date formatting. Better solution would be to replace the dates in the expected resuls file by a token which is converted into the appropriate date on the system running the tests.


