]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/thelpers.py
Remove vfs (replaced by vfs2)
[bup.git] / lib / bup / t / thelpers.py
index 8c02a110b0a8a57ca059a39fa54b06cff1d444e8..c707839fdb956ce7a6dfdb50ff27510479fbd53e 100644 (file)
@@ -14,34 +14,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():
@@ -169,27 +141,28 @@ def test_batchpipe():
 
 @wvtest
 def test_atomically_replaced_file():
-    with no_lingering_errors(), test_tempdir('bup-thelper-') as tmpdir:
-        target_file = os.path.join(tmpdir, 'test-atomic-write')
-
-        with atomically_replaced_file(target_file, mode='w') as f:
-            f.write('asdf')
-            WVPASSEQ(f.mode, 'w')
-        f = open(target_file, 'r')
-        WVPASSEQ(f.read(), 'asdf')
+    with no_lingering_errors():
+        with test_tempdir('bup-thelper-') as tmpdir:
+            target_file = os.path.join(tmpdir, 'test-atomic-write')
 
-        try:
             with atomically_replaced_file(target_file, mode='w') as f:
-                f.write('wxyz')
-                raise Exception()
-        except:
-            pass
-        with open(target_file) as f:
+                f.write('asdf')
+                WVPASSEQ(f.mode, 'w')
+            f = open(target_file, 'r')
             WVPASSEQ(f.read(), 'asdf')
 
-        with atomically_replaced_file(target_file, mode='wb') as f:
-            f.write(os.urandom(20))
-            WVPASSEQ(f.mode, 'wb')
+            try:
+                with atomically_replaced_file(target_file, mode='w') as f:
+                    f.write('wxyz')
+                    raise Exception()
+            except:
+                pass
+            with open(target_file) as f:
+                WVPASSEQ(f.read(), 'asdf')
+
+            with atomically_replaced_file(target_file, mode='wb') as f:
+                f.write(os.urandom(20))
+                WVPASSEQ(f.mode, 'wb')
 
 
 @wvtest
@@ -221,3 +194,29 @@ def test_utc_offset_str():
                     del os.environ['TZ']
                 except KeyError:
                     pass
+
+@wvtest
+def test_valid_save_name():
+    with no_lingering_errors():
+        valid = helpers.valid_save_name
+        WVPASS(valid('x'))
+        WVPASS(valid('x@'))
+        WVFAIL(valid('@'))
+        WVFAIL(valid('/'))
+        WVFAIL(valid('/foo'))
+        WVFAIL(valid('foo/'))
+        WVFAIL(valid('/foo/'))
+        WVFAIL(valid('foo//bar'))
+        WVFAIL(valid('.'))
+        WVFAIL(valid('bar.'))
+        WVFAIL(valid('foo@{'))
+        for x in ' ~^:?*[\\':
+            WVFAIL(valid('foo' + x))
+        for i in range(20):
+            WVFAIL(valid('foo' + chr(i)))
+        WVFAIL(valid('foo' + chr(0x7f)))
+        WVFAIL(valid('foo..bar'))
+        WVFAIL(valid('bar.lock/baz'))
+        WVFAIL(valid('foo/bar.lock/baz'))
+        WVFAIL(valid('.bar/baz'))
+        WVFAIL(valid('foo/.bar/baz'))