]> arthur.barton.de Git - bup.git/blobdiff - t/test-ftp
ftp: accommodate python 3 and test there
[bup.git] / t / test-ftp
index 3a8e5db38073199f887b735f1ea5bbc11c52eafc..e9f4166467b18e757d83f4c081a96ecd6c5bad22 100755 (executable)
@@ -6,21 +6,23 @@ exec "$bup_python" "$0" ${1+"$@"}
 # end of bup preamble
 
 from __future__ import absolute_import, print_function
-from os import environ, chdir, mkdir, symlink, unlink
+from os import chdir, mkdir, symlink, unlink
 from os.path import abspath, dirname
 from subprocess import PIPE
 from time import localtime, strftime
 import os, sys
 
-script_home = abspath(dirname(sys.argv[0] or '.'))
-sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
-top = os.getcwd()
-bup_cmd = top + '/bup'
+# For buptest, wvtest, ...
+sys.path[:0] = (abspath(os.path.dirname(__file__) + '/..'),)
 
 from buptest import ex, exo, logcmd, test_tempdir
 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
 
+from bup.compat import environ
 from bup.helpers import unlink as unlink_if_exists
+import bup.path
+
+bup_cmd = bup.path.exe()
 
 def bup(*args, **kwargs):
     if 'stdout' not in kwargs:
@@ -28,106 +30,108 @@ def bup(*args, **kwargs):
     return ex((bup_cmd,) + args, **kwargs)
 
 def jl(*lines):
-    return ''.join(line + '\n' for line in lines)
+    return b''.join(line + b'\n' for line in lines)
 
-environ['GIT_AUTHOR_NAME'] = 'bup test'
-environ['GIT_COMMITTER_NAME'] = 'bup test'
-environ['GIT_AUTHOR_EMAIL'] = 'bup@a425bc70a02811e49bdf73ee56450e6f'
-environ['GIT_COMMITTER_EMAIL'] = 'bup@a425bc70a02811e49bdf73ee56450e6f'
+environ[b'GIT_AUTHOR_NAME'] = b'bup test'
+environ[b'GIT_COMMITTER_NAME'] = b'bup test'
+environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
+environ[b'GIT_COMMITTER_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
 
-with test_tempdir('ftp-') as tmpdir:
-    environ['BUP_DIR'] = tmpdir + '/repo'
-    environ['GIT_DIR'] = tmpdir + '/repo'
+with test_tempdir(b'ftp-') as tmpdir:
+    environ[b'BUP_DIR'] = tmpdir + b'/repo'
+    environ[b'GIT_DIR'] = tmpdir + b'/repo'
 
     chdir(tmpdir)
-    mkdir('src')
-    chdir('src')
-    mkdir('dir')
-    with open('file-1', 'wb') as f:
-        print('excitement!', file=f)
-    with open('dir/file-2', 'wb') as f:
-        print('more excitement!', file=f)
-    symlink('file-1', 'file-symlink')
-    symlink('dir', 'dir-symlink')
-    symlink('not-there', 'bad-symlink')
+    mkdir(b'src')
+    chdir(b'src')
+    mkdir(b'dir')
+    with open(b'file-1', 'wb') as f:
+        f.write(b'excitement!\n')
+    with open(b'dir/file-2', 'wb') as f:
+        f.write(b'more excitement!\n')
+    symlink(b'file-1', b'file-symlink')
+    symlink(b'dir', b'dir-symlink')
+    symlink(b'not-there', b'bad-symlink')
 
     chdir(tmpdir)    
-    bup('init')
-    bup('index', 'src')
-    bup('save', '-n', 'src', '--strip', 'src')
-    save_utc = int(exo(('git', 'show', '-s', '--format=%at', 'src')).out.strip())
-    save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc))
+    bup(b'init')
+    bup(b'index', b'src')
+    bup(b'save', b'-n', b'src', b'--strip', b'src')
+    save_utc = int(exo((b'git', b'show',
+                        b'-s', b'--format=%at', b'src')).out.strip())
+    save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc)).encode('ascii')
     
     wvstart('help')
-    wvpasseq('Commands: ls cd pwd cat get mget help quit\n',
-             exo((bup_cmd, 'ftp'), input='help\n', stderr=PIPE).err)
+    wvpasseq(b'Commands: ls cd pwd cat get mget help quit\n',
+             exo((bup_cmd, b'ftp'), input=b'help\n', stderr=PIPE).err)
 
     wvstart('pwd/cd')
-    wvpasseq('/\n', bup('ftp', input='pwd\n').out)
-    wvpasseq('', bup('ftp', input='cd src\n').out)
-    wvpasseq('/src\n', bup('ftp', input=jl('cd src', 'pwd')).out)
-    wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
-                                              'cd ..', 'pwd')).out)
-    wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
-                                              'cd ..', 'cd ..', 'pwd')).out)
-    wvpasseq('/src/%s/dir\n' % save_name,
-             bup('ftp', input=jl('cd src/latest/dir-symlink', 'pwd')).out)
-    wvpasseq('/src/%s/dir\n' % save_name,
-             bup('ftp', input=jl('cd src latest dir-symlink', 'pwd')).out)
-    wvpassne(0, bup('ftp',
-                    input=jl('cd src/latest/bad-symlink', 'pwd'),
+    wvpasseq(b'/\n', bup(b'ftp', input=b'pwd\n').out)
+    wvpasseq(b'', bup(b'ftp', input=b'cd src\n').out)
+    wvpasseq(b'/src\n', bup(b'ftp', input=jl(b'cd src', b'pwd')).out)
+    wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
+                                                b'cd ..', b'pwd')).out)
+    wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
+                                                b'cd ..', b'cd ..',
+                                                b'pwd')).out)
+    wvpasseq(b'/src/%s/dir\n' % save_name,
+             bup(b'ftp', input=jl(b'cd src/latest/dir-symlink', b'pwd')).out)
+    wvpasseq(b'/src/%s/dir\n' % save_name,
+             bup(b'ftp', input=jl(b'cd src latest dir-symlink', b'pwd')).out)
+    wvpassne(0, bup(b'ftp',
+                    input=jl(b'cd src/latest/bad-symlink', b'pwd'),
                     check=False, stdout=None).rc)
-    wvpassne(0, bup('ftp',
-                    input=jl('cd src/latest/not-there', 'pwd'),
+    wvpassne(0, bup(b'ftp',
+                    input=jl(b'cd src/latest/not-there', b'pwd'),
                     check=False, stdout=None).rc)
 
     wvstart('ls')
     # FIXME: elaborate
-    wvpasseq('src\n', bup('ftp', input='ls\n').out)
-    wvpasseq(save_name + '\nlatest\n',
-             bup('ftp', input='ls src\n').out)
+    wvpasseq(b'src\n', bup(b'ftp', input=b'ls\n').out)
+    wvpasseq(save_name + b'\nlatest\n',
+             bup(b'ftp', input=b'ls src\n').out)
 
     wvstart('cat')
-    wvpasseq('excitement!\n',
-             bup('ftp', input='cat src/latest/file-1\n').out)
-    wvpasseq('excitement!\nmore excitement!\n',
-             bup('ftp',
-                 input='cat src/latest/file-1 src/latest/dir/file-2\n').out)
+    wvpasseq(b'excitement!\n',
+             bup(b'ftp', input=b'cat src/latest/file-1\n').out)
+    wvpasseq(b'excitement!\nmore excitement!\n',
+             bup(b'ftp',
+                 input=b'cat src/latest/file-1 src/latest/dir/file-2\n').out)
     
     wvstart('get')
-    bup('ftp', input=jl('get src/latest/file-1 dest'))
-    with open('dest', 'rb') as f:
-        wvpasseq('excitement!\n', f.read())
-    unlink('dest')
-    bup('ftp', input=jl('get src/latest/file-symlink dest'))
-    with open('dest', 'rb') as f:
-        wvpasseq('excitement!\n', f.read())
-    unlink('dest')
-    wvpassne(0, bup('ftp',
-                    input=jl('get src/latest/bad-symlink dest'),
+    bup(b'ftp', input=jl(b'get src/latest/file-1 dest'))
+    with open(b'dest', 'rb') as f:
+        wvpasseq(b'excitement!\n', f.read())
+    unlink(b'dest')
+    bup(b'ftp', input=jl(b'get src/latest/file-symlink dest'))
+    with open(b'dest', 'rb') as f:
+        wvpasseq(b'excitement!\n', f.read())
+    unlink(b'dest')
+    wvpassne(0, bup(b'ftp',
+                    input=jl(b'get src/latest/bad-symlink dest'),
                     check=False, stdout=None).rc)
-    wvpassne(0, bup('ftp',
-                    input=jl('get src/latest/not-there'),
+    wvpassne(0, bup(b'ftp',
+                    input=jl(b'get src/latest/not-there'),
                     check=False, stdout=None).rc)
     
     wvstart('mget')
-    unlink_if_exists('file-1')
-    bup('ftp', input=jl('mget src/latest/file-1'))
-    with open('file-1', 'rb') as f:
-        wvpasseq('excitement!\n', f.read())
-    unlink_if_exists('file-1')
-    unlink_if_exists('file-2')
-    bup('ftp', input=jl('mget src/latest/file-1 src/latest/dir/file-2'))
-    with open('file-1', 'rb') as f:
-        wvpasseq('excitement!\n', f.read())
-    with open('file-2', 'rb') as f:
-        wvpasseq('more excitement!\n', f.read())
-    unlink_if_exists('file-symlink')
-    bup('ftp', input=jl('mget src/latest/file-symlink'))
-    with open('file-symlink', 'rb') as f:
-        wvpasseq('excitement!\n', f.read())
-    wvpassne(0, bup('ftp',
-                    input=jl('mget src/latest/bad-symlink dest'),
+    unlink_if_exists(b'file-1')
+    bup(b'ftp', input=jl(b'mget src/latest/file-1'))
+    with open(b'file-1', 'rb') as f:
+        wvpasseq(b'excitement!\n', f.read())
+    unlink_if_exists(b'file-1')
+    unlink_if_exists(b'file-2')
+    bup(b'ftp', input=jl(b'mget src/latest/file-1 src/latest/dir/file-2'))
+    with open(b'file-1', 'rb') as f:
+        wvpasseq(b'excitement!\n', f.read())
+    with open(b'file-2', 'rb') as f:
+        wvpasseq(b'more excitement!\n', f.read())
+    unlink_if_exists(b'file-symlink')
+    bup(b'ftp', input=jl(b'mget src/latest/file-symlink'))
+    with open(b'file-symlink', 'rb') as f:
+        wvpasseq(b'excitement!\n', f.read())
+    wvpassne(0, bup(b'ftp',
+                    input=jl(b'mget src/latest/bad-symlink dest'),
                     check=False, stdout=None).rc)
     # bup mget currently always does pattern matching
-    bup('ftp', input='mget src/latest/not-there\n')
+    bup(b'ftp', input=b'mget src/latest/not-there\n')