From ecfd46d16d9077f1ec92277bbeb03e4e40d05a14 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Tue, 23 May 2017 21:51:40 -0400 Subject: [PATCH] Add test_broken_symlink_is_ignored. --- src/wormhole/cli/cmd_send.py | 3 ++- src/wormhole/test/test_cli.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index 4c96d9b..aaa274a 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -282,7 +282,8 @@ class Sender: except OSError as e: errmsg = u"{}: {}".format(fn, e.strerror) if self._args.ignore_unsendable_files: - print(u"{} (ignoring error)".format(errmsg)) + print(u"{} (ignoring error)".format(errmsg), + file=args.stderr) else: raise UnsendableFileError(errmsg) fd_to_send.seek(0,2) diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index c6ede48..c0eca38 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -66,7 +66,7 @@ class OfferData(unittest.TestCase): self.assertEqual(fd_to_send.tell(), 0) self.assertEqual(fd_to_send.read(), message) - def test_broken_symlink(self): + def _create_broken_symlink(self): if not hasattr(os, 'symlink'): raise unittest.SkipTest("host OS does not support symlinks") @@ -81,9 +81,20 @@ class OfferData(unittest.TestCase): self.cfg.what = send_dir_arg self.cfg.cwd = parent_dir + def test_broken_symlink_raises_err(self): + self._create_broken_symlink() + self.cfg.ignore_unsendable_files = False e = self.assertRaises(UnsendableFileError, build_offer, self.cfg) self.assertEqual(str(e), "linky: No such file or directory") + def test_broken_symlink_is_ignored(self): + self._create_broken_symlink() + self.cfg.ignore_unsendable_files = True + d, fd_to_send = build_offer(self.cfg) + self.assertIn('(ignoring error)', self.cfg.stderr.getvalue()) + self.assertEqual(d['directory']['numfiles'], 0) + self.assertEqual(d['directory']['numbytes'], 0) + def test_missing_file(self): self.cfg.what = filename = "missing" send_dir = self.mktemp()