mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 15:16:41 +00:00
test_cli_cp: test cleanups
* remove redundant test cases * add more internal asserts * clean up set usage
This commit is contained in:
parent
415b7b7bca
commit
f508a98622
@ -7,6 +7,7 @@ from allmydata.scripts import cli
|
|||||||
from allmydata.util import fileutil
|
from allmydata.util import fileutil
|
||||||
from allmydata.util.encodingutil import (quote_output, get_io_encoding,
|
from allmydata.util.encodingutil import (quote_output, get_io_encoding,
|
||||||
unicode_to_output, to_str)
|
unicode_to_output, to_str)
|
||||||
|
from allmydata.util.assertutil import _assert
|
||||||
from .no_network import GridTestMixin
|
from .no_network import GridTestMixin
|
||||||
from .test_cli import CLITestMixin
|
from .test_cli import CLITestMixin
|
||||||
|
|
||||||
@ -747,16 +748,11 @@ cp -r $DIRCAP to/missing/ : to/missing/file
|
|||||||
cp $DIRALIAS to/missing/ : E4-NEED-R
|
cp $DIRALIAS to/missing/ : E4-NEED-R
|
||||||
cp -r $DIRALIAS to/missing/ : to/missing/file
|
cp -r $DIRALIAS to/missing/ : to/missing/file
|
||||||
|
|
||||||
# multiple files to a missing target: should mkdir
|
|
||||||
cp $DIRCAP/file $PARENTCAP/dir2/file2 to/missing : to/missing/file,to/missing/file2
|
|
||||||
cp -r $DIRCAP/file $PARENTCAP/dir2/file2 to/missing : to/missing/file,to/missing/file2
|
|
||||||
|
|
||||||
cp $DIRCAP/file $PARENTCAP/dir2/file2 to/missing/ : to/missing/file,to/missing/file2
|
|
||||||
cp -r $DIRCAP/file $PARENTCAP/dir2/file2 to/missing/ : to/missing/file,to/missing/file2
|
|
||||||
|
|
||||||
# multiple things to a missing target: should mkdir
|
# multiple things to a missing target: should mkdir
|
||||||
cp $DIRCAP/file $PARENTCAP/dir2/file2 to/missing : to/missing/file,to/missing/file2
|
cp $DIRCAP/file $PARENTCAP/dir2/file2 to/missing : to/missing/file,to/missing/file2
|
||||||
|
cp -r $DIRCAP/file $PARENTCAP/dir2/file2 to/missing : to/missing/file,to/missing/file2
|
||||||
cp $DIRCAP/file $FILECAP to/missing : E2-DESTNAME
|
cp $DIRCAP/file $FILECAP to/missing : E2-DESTNAME
|
||||||
|
cp -r $DIRCAP/file $FILECAP to/missing : E2-DESTNAME
|
||||||
cp $DIRCAP $FILECAP to/missing : E4-NEED-R
|
cp $DIRCAP $FILECAP to/missing : E4-NEED-R
|
||||||
cp -r $DIRCAP $FILECAP to/missing : E2-DESTNAME
|
cp -r $DIRCAP $FILECAP to/missing : E2-DESTNAME
|
||||||
# namedfile, unnameddir, nameddir
|
# namedfile, unnameddir, nameddir
|
||||||
@ -767,7 +763,9 @@ cp $PARENTCAP/dir3/file3 $DIRCAP $PARENTCAP/dir2 $FILECAP to/missing : E4-NEE
|
|||||||
cp -r $PARENTCAP/dir3/file3 $DIRCAP $PARENTCAP/dir2 $FILECAP to/missing : E2-DESTNAME
|
cp -r $PARENTCAP/dir3/file3 $DIRCAP $PARENTCAP/dir2 $FILECAP to/missing : E2-DESTNAME
|
||||||
|
|
||||||
cp $DIRCAP/file $PARENTCAP/dir2/file2 to/missing/ : to/missing/file,to/missing/file2
|
cp $DIRCAP/file $PARENTCAP/dir2/file2 to/missing/ : to/missing/file,to/missing/file2
|
||||||
|
cp -r $DIRCAP/file $PARENTCAP/dir2/file2 to/missing/ : to/missing/file,to/missing/file2
|
||||||
cp $DIRCAP/file $FILECAP to/missing/ : E2-DESTNAME
|
cp $DIRCAP/file $FILECAP to/missing/ : E2-DESTNAME
|
||||||
|
cp -r $DIRCAP/file $FILECAP to/missing/ : E2-DESTNAME
|
||||||
cp $DIRCAP $FILECAP to/missing/ : E4-NEED-R
|
cp $DIRCAP $FILECAP to/missing/ : E4-NEED-R
|
||||||
cp -r $DIRCAP $FILECAP to/missing/ : E2-DESTNAME
|
cp -r $DIRCAP $FILECAP to/missing/ : E2-DESTNAME
|
||||||
# namedfile, unnameddir, nameddir
|
# namedfile, unnameddir, nameddir
|
||||||
@ -890,9 +888,7 @@ class CopyOut(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
here = "/".join(dirpath.split(os.sep)[len(top.split(os.sep))-1:])
|
here = "/".join(dirpath.split(os.sep)[len(top.split(os.sep))-1:])
|
||||||
results.add(here+"/")
|
results.add(here+"/")
|
||||||
for fn in filenames:
|
for fn in filenames:
|
||||||
f = open(os.path.join(dirpath, fn), "rb")
|
contents = fileutil.read(os.path.join(dirpath, fn))
|
||||||
contents = f.read()
|
|
||||||
f.close()
|
|
||||||
if contents == self.FILE_CONTENTS:
|
if contents == self.FILE_CONTENTS:
|
||||||
results.add("%s/%s" % (here, fn))
|
results.add("%s/%s" % (here, fn))
|
||||||
elif contents == self.FILE_CONTENTS_5:
|
elif contents == self.FILE_CONTENTS_5:
|
||||||
@ -911,12 +907,12 @@ class CopyOut(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
.replace("$FILECAP", self.FILECAP)
|
.replace("$FILECAP", self.FILECAP)
|
||||||
.split())
|
.split())
|
||||||
target = cmd[-1]
|
target = cmd[-1]
|
||||||
|
_assert(target == "to" or target.startswith("to/"), target)
|
||||||
cmd[-1] = os.path.abspath(os.path.join(self.basedir, cmd[-1]))
|
cmd[-1] = os.path.abspath(os.path.join(self.basedir, cmd[-1]))
|
||||||
|
|
||||||
# reset
|
# reset
|
||||||
targetdir = os.path.abspath(os.path.join(self.basedir, "to"))
|
targetdir = os.path.abspath(os.path.join(self.basedir, "to"))
|
||||||
if os.path.exists(targetdir):
|
fileutil.rm_dir(targetdir)
|
||||||
shutil.rmtree(targetdir)
|
|
||||||
os.mkdir(targetdir)
|
os.mkdir(targetdir)
|
||||||
|
|
||||||
if target.rstrip("/") == "to/existing-file":
|
if target.rstrip("/") == "to/existing-file":
|
||||||
@ -949,12 +945,12 @@ class CopyOut(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
d.addCallback(_check)
|
d.addCallback(_check)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def do_one_test(self, case, expected):
|
def do_one_test(self, case, orig_expected):
|
||||||
expected = expected.copy()
|
expected = set(orig_expected)
|
||||||
printable_expected = ",".join(sorted(expected))
|
printable_expected = ",".join(sorted(expected))
|
||||||
#print "---", case, ":", printable_expected
|
#print "---", case, ":", printable_expected
|
||||||
|
|
||||||
for f in list(expected):
|
for f in orig_expected:
|
||||||
# f is "dir/file" or "dir/sub/file" or "dir/" or "dir/sub/"
|
# f is "dir/file" or "dir/sub/file" or "dir/" or "dir/sub/"
|
||||||
# we want all parent directories in the set, with trailing /
|
# we want all parent directories in the set, with trailing /
|
||||||
pieces = f.rstrip("/").split("/")
|
pieces = f.rstrip("/").split("/")
|
||||||
@ -989,7 +985,7 @@ class CopyOut(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
continue
|
continue
|
||||||
case, expected = line.split(":")
|
case, expected = line.split(":")
|
||||||
case = case.strip()
|
case = case.strip()
|
||||||
expected = set(expected.strip().split(","))
|
expected = frozenset(expected.strip().split(","))
|
||||||
|
|
||||||
d.addCallback(lambda ign, case=case, expected=expected:
|
d.addCallback(lambda ign, case=case, expected=expected:
|
||||||
self.do_one_test(case, expected))
|
self.do_one_test(case, expected))
|
||||||
|
Loading…
Reference in New Issue
Block a user