]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/thelpers.py
thelpers: call tzset() after changing TZ
[bup.git] / lib / bup / t / thelpers.py
index d7d302d074f3fb2ac5dc146c22fc6f58765de4c4..60ef13ed1be3b4d61417c00da082e30c34d2a4b2 100644 (file)
@@ -1,8 +1,11 @@
 
+from __future__ import absolute_import
+from time import tzset
 import helpers, math, os, os.path, stat, subprocess
 
 from wvtest import *
 
+from bup.compat import environ
 from bup.helpers import (atomically_replaced_file, batchpipe, detect_fakeroot,
                          grafted_path_components, mkdirp, parse_num,
                          path_components, readpipe, stripped_path_components,
@@ -14,34 +17,6 @@ import bup._helpers as _helpers
 bup_tmp = os.path.realpath('../../../t/tmp')
 mkdirp(bup_tmp)
 
-@wvtest
-def test_next():
-    with no_lingering_errors():
-        # Test whatever you end up with for next() after import '*'.
-        WVPASSEQ(next(iter([]), None), None)
-        x = iter([1])
-        WVPASSEQ(next(x, None), 1)
-        WVPASSEQ(next(x, None), None)
-        x = iter([1])
-        WVPASSEQ(next(x, 'x'), 1)
-        WVPASSEQ(next(x, 'x'), 'x')
-        WVEXCEPT(StopIteration, next, iter([]))
-        x = iter([1])
-        WVPASSEQ(next(x), 1)
-        WVEXCEPT(StopIteration, next, x)
-
-
-@wvtest
-def test_fallback_next():
-    with no_lingering_errors():
-        global next
-        orig = next
-        next = helpers._fallback_next
-        try:
-            test_next()
-        finally:
-            next = orig
-
 
 @wvtest
 def test_parse_num():
@@ -130,7 +105,7 @@ def test_grafted_path_components():
 def test_readpipe():
     with no_lingering_errors():
         x = readpipe(['echo', '42'])
-        WVPASSEQ(x, '42\n')
+        WVPASSEQ(x, b'42\n')
         try:
             readpipe(['bash', '-c', 'exit 42'])
         except Exception as ex:
@@ -143,10 +118,10 @@ def test_batchpipe():
     with no_lingering_errors():
         for chunk in batchpipe(['echo'], []):
             WVPASS(False)
-        out = ''
+        out = b''
         for chunk in batchpipe(['echo'], ['42']):
             out += chunk
-        WVPASSEQ(out, '42\n')
+        WVPASSEQ(out, b'42\n')
         try:
             batchpipe(['bash', '-c'], ['exit 42'])
         except Exception as ex:
@@ -158,20 +133,20 @@ def test_batchpipe():
         arg_max = \
             helpers._argmax_base(['echo']) + helpers._argmax_args_size(args[:3])
         batches = batchpipe(['echo'], args, arg_max=arg_max)
-        WVPASSEQ(next(batches), '0 1 2\n')
-        WVPASSEQ(next(batches), '3 4 5\n')
+        WVPASSEQ(next(batches), b'0 1 2\n')
+        WVPASSEQ(next(batches), b'3 4 5\n')
         WVPASSEQ(next(batches, None), None)
         batches = batchpipe(['echo'], [str(x) for x in range(5)], arg_max=arg_max)
-        WVPASSEQ(next(batches), '0 1 2\n')
-        WVPASSEQ(next(batches), '3 4\n')
+        WVPASSEQ(next(batches), b'0 1 2\n')
+        WVPASSEQ(next(batches), b'3 4\n')
         WVPASSEQ(next(batches, None), None)
 
 
 @wvtest
 def test_atomically_replaced_file():
     with no_lingering_errors():
-        with test_tempdir('bup-thelper-') as tmpdir:
-            target_file = os.path.join(tmpdir, 'test-atomic-write')
+        with test_tempdir(b'bup-thelper-') as tmpdir:
+            target_file = os.path.join(tmpdir, b'test-atomic-write')
 
             with atomically_replaced_file(target_file, mode='w') as f:
                 f.write('asdf')
@@ -193,33 +168,42 @@ def test_atomically_replaced_file():
                 WVPASSEQ(f.mode, 'wb')
 
 
+def set_tz(tz):
+    if not tz:
+        del environ[b'TZ']
+    else:
+        environ[b'TZ'] = tz
+    tzset()
+
+
 @wvtest
 def test_utc_offset_str():
     with no_lingering_errors():
-        tz = os.environ.get('TZ')
+        tz = environ.get(b'TZ')
+        tzset()
         try:
-            os.environ['TZ'] = 'FOO+0:00'
-            WVPASSEQ(utc_offset_str(0), '+0000')
-            os.environ['TZ'] = 'FOO+1:00'
-            WVPASSEQ(utc_offset_str(0), '-0100')
-            os.environ['TZ'] = 'FOO-1:00'
-            WVPASSEQ(utc_offset_str(0), '+0100')
-            os.environ['TZ'] = 'FOO+3:3'
-            WVPASSEQ(utc_offset_str(0), '-0303')
-            os.environ['TZ'] = 'FOO-3:3'
-            WVPASSEQ(utc_offset_str(0), '+0303')
+            set_tz(b'FOO+0:00')
+            WVPASSEQ(utc_offset_str(0), b'+0000')
+            set_tz(b'FOO+1:00')
+            WVPASSEQ(utc_offset_str(0), b'-0100')
+            set_tz(b'FOO-1:00')
+            WVPASSEQ(utc_offset_str(0), b'+0100')
+            set_tz(b'FOO+3:3')
+            WVPASSEQ(utc_offset_str(0), b'-0303')
+            set_tz(b'FOO-3:3')
+            WVPASSEQ(utc_offset_str(0), b'+0303')
             # Offset is not an integer number of minutes
-            os.environ['TZ'] = 'FOO+3:3:3'
-            WVPASSEQ(utc_offset_str(1), '-0303')
-            os.environ['TZ'] = 'FOO-3:3:3'
-            WVPASSEQ(utc_offset_str(1), '+0303')
-            WVPASSEQ(utc_offset_str(314159), '+0303')
+            set_tz(b'FOO+3:3:3')
+            WVPASSEQ(utc_offset_str(1), b'-0303')
+            set_tz(b'FOO-3:3:3')
+            WVPASSEQ(utc_offset_str(1), b'+0303')
+            WVPASSEQ(utc_offset_str(314159), b'+0303')
         finally:
             if tz:
-                os.environ['TZ'] = tz
+                set_tz(tz)
             else:
                 try:
-                    del os.environ['TZ']
+                    set_tz(None)
                 except KeyError:
                     pass