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():
@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
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'))