From c6449b687a6b2fc95ec9f6afd938a20f60a731ab Mon Sep 17 00:00:00 2001 From: Daira Hopwood <daira@jacaranda.org> Date: Fri, 5 Feb 2016 19:12:01 +0000 Subject: [PATCH] Fix tests on platforms without time.tzset (e.g. Windows). fixes ticket:2725 Signed-off-by: Daira Hopwood <daira@jacaranda.org> --- src/allmydata/test/common_util.py | 3 +++ src/allmydata/test/test_util.py | 4 ++++ src/allmydata/test/test_web.py | 23 +++++++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index 9e8149d1..c95f7168 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -195,6 +195,9 @@ class TimezoneMixin(object): self.addCleanup(restoreTimezone) tzset_if_possible() + def have_working_tzset(self): + return hasattr(time, 'tzset') + try: import win32file diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 25b65615..be5541e8 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -932,6 +932,10 @@ class TimeFormat(unittest.TestCase, TimezoneMixin): # time_format.iso_utc_time_to_localseconds() breaks if the timezone is # Europe/London. (As soon as this unit test is done then I'll change # that implementation to something that works even in this case...) + + if not self.have_working_tzset(): + raise unittest.SkipTest("This test can't be run on a platform without time.tzset().") + self.setTimezone("Europe/London") return self._help_test_epoch() diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 18514a3a..2a968f9a 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -634,10 +634,25 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi self.failUnlessIn(u'<td>fake_nickname \u263A</td>', res_u) self.failUnlessIn(u'<div class="nickname">other_nickname \u263B</div>', res_u) self.failUnlessIn(u'Connected to <span>1</span>\n of <span>2</span> known storage servers', res_u) - self.failUnless(re.search(u'<div class="status-indicator"><img (src="img/connected-yes.png" |alt="Connected" ){2}/></div>\n <a( class="timestamp"| title="1970-01-01 13:00:10"){2}>1d\u00A00h\u00A00m\u00A050s</a>', res_u), repr(res_u)) - self.failUnless(re.search(u'<div class="status-indicator"><img (src="img/connected-no.png" |alt="Disconnected" ){2}/></div>\n <a( class="timestamp"| title="1970-01-01 13:00:25"){2}>1d\u00A00h\u00A00m\u00A035s</a>', res_u), repr(res_u)) - self.failUnless(re.search(u'<td class="service-last-received-data"><a( class="timestamp"| title="1970-01-01 13:00:30"){2}>1d\u00A00h\u00A00m\u00A030s</a></td>', res_u), repr(res_u)) - self.failUnless(re.search(u'<td class="service-last-received-data"><a( class="timestamp"| title="1970-01-01 13:00:35"){2}>1d\u00A00h\u00A00m\u00A025s</a></td>', res_u), repr(res_u)) + def timestamp(t): + return (u'"%s"' % (t,)) if self.have_working_tzset() else u'"[^"]*"' + self.failUnless(re.search( + u'<div class="status-indicator"><img (src="img/connected-yes.png" |alt="Connected" ){2}/>' + u'</div>\n <a( class="timestamp"| title=%s){2}>1d\u00A00h\u00A00m\u00A050s</a>' + % timestamp(u'1970-01-01 13:00:10'), res_u), repr(res_u)) + self.failUnless(re.search( + u'<div class="status-indicator"><img (src="img/connected-no.png" |alt="Disconnected" ){2}/>' + u'</div>\n <a( class="timestamp"| title=%s){2}>1d\u00A00h\u00A00m\u00A035s</a>' + % timestamp(u'1970-01-01 13:00:25'), res_u), repr(res_u)) + self.failUnless(re.search( + u'<td class="service-last-received-data"><a( class="timestamp"| title=%s){2}>' + u'1d\u00A00h\u00A00m\u00A030s</a></td>' + % timestamp(u'1970-01-01 13:00:30'), res_u), repr(res_u)) + self.failUnless(re.search( + u'<td class="service-last-received-data"><a( class="timestamp"| title=%s){2}>' + u'1d\u00A00h\u00A00m\u00A025s</a></td>' + % timestamp(u'1970-01-01 13:00:35'), res_u), repr(res_u)) + self.failUnlessIn(u'\u00A9 <a href="https://tahoe-lafs.org/">Tahoe-LAFS Software Foundation', res_u) self.failUnlessIn('<td><h3>Available</h3></td>', res) self.failUnlessIn('123.5kB', res) -- 2.45.2