From e90d1f38d22bb3e8d5550c4d03d083cc61f91d9b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 16 Jul 2020 15:44:41 -0400 Subject: [PATCH] Make TimezoneMixin importable on Python 3. --- src/allmydata/test/common_util.py | 25 ------------------------- src/allmydata/test/test_time_format.py | 2 +- src/allmydata/test/test_util.py | 2 +- src/allmydata/test/web/test_web.py | 3 ++- src/allmydata/util/_python3.py | 1 + 5 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index bf44785a5..2e8bbd006 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -185,31 +185,6 @@ class TestMixin(SignalMixin): self.fail("Reactor was still active when it was required to be quiescent.") -class TimezoneMixin(object): - - def setTimezone(self, timezone): - def tzset_if_possible(): - # Windows doesn't have time.tzset(). - if hasattr(time, 'tzset'): - time.tzset() - - unset = object() - originalTimezone = os.environ.get('TZ', unset) - def restoreTimezone(): - if originalTimezone is unset: - del os.environ['TZ'] - else: - os.environ['TZ'] = originalTimezone - tzset_if_possible() - - os.environ['TZ'] = timezone - self.addCleanup(restoreTimezone) - tzset_if_possible() - - def have_working_tzset(self): - return hasattr(time, 'tzset') - - try: import win32file import win32con diff --git a/src/allmydata/test/test_time_format.py b/src/allmydata/test/test_time_format.py index ae655ff3e..7edf9f12d 100644 --- a/src/allmydata/test/test_time_format.py +++ b/src/allmydata/test/test_time_format.py @@ -6,7 +6,7 @@ import time from twisted.trial import unittest -from allmydata.test.common_util import TimezoneMixin +from allmydata.test.common_py3 import TimezoneMixin from allmydata.util import time_format diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 40a05e9c5..c290903a7 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -21,7 +21,7 @@ from allmydata.util import statistics, dictutil, pipeline, yamlutil from allmydata.util import log as tahoe_log from allmydata.util.spans import Spans, overlap, DataSpans from allmydata.util.fileutil import EncryptedTemporaryFile -from allmydata.test.common_util import ReallyEqualMixin, TimezoneMixin +from allmydata.test.common_util import ReallyEqualMixin if six.PY3: long = int diff --git a/src/allmydata/test/web/test_web.py b/src/allmydata/test/web/test_web.py index b3c8c7f46..5678a98f8 100644 --- a/src/allmydata/test/web/test_web.py +++ b/src/allmydata/test/web/test_web.py @@ -60,6 +60,7 @@ from .common import ( from allmydata.interfaces import IMutableFileNode, SDMF_VERSION, MDMF_VERSION from allmydata.mutable import servermap, publish, retrieve from .. import common_util as testutil +from ..common_py3 import TimezoneMixin from ..common_web import ( do_http, Error, @@ -311,7 +312,7 @@ class FakeClient(_Client): MUTABLE_SIZELIMIT = FakeMutableFileNode.MUTABLE_SIZELIMIT -class WebMixin(testutil.TimezoneMixin): +class WebMixin(TimezoneMixin): def setUp(self): self.setTimezone('UTC-13:00') self.s = FakeClient() diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index aa4e5f386..19bd35890 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -22,6 +22,7 @@ PORTED_MODULES = [ "allmydata.util.namespace", "allmydata.util.pollmixin", "allmydata.util._python3", + "allmydata.test.common_py3", ] PORTED_TEST_MODULES = [