X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2Fallmydata%2Ftest%2Fcommon_util.py;h=c95f71681ff10dca701bcb4d238aaeec02abfe63;hb=c6449b687a6b2fc95ec9f6afd938a20f60a731ab;hp=70a072454feb3c4dc04a1b4ff0419d0422de4c88;hpb=db22fdc20dc93a3e1d8a084f8847d16d4bcaad55;p=tahoe-lafs%2Ftahoe-lafs.git diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index 70a07245..c95f7168 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -45,9 +45,12 @@ class NonASCIIPathMixin: try: fileutil.rm_dir(dirpath) finally: - log.err("We were unable to delete a non-ASCII directory %r created by the test. " - "This is liable to cause failures on future builds." % (dirpath,)) - self.addCleanup(self._cleanup_nonascii, dirpath) + if os.path.exists(dirpath): + msg = ("We were unable to delete a non-ASCII directory %r created by the test. " + "This is liable to cause failures on future builds." % (dirpath,)) + print msg + log.err(msg) + self.addCleanup(_cleanup) os.mkdir(dirpath) def unicode_or_fallback(self, unicode_name, fallback_name): @@ -170,6 +173,32 @@ class TestMixin(SignalMixin): if required_to_quiesce and active: 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