From 5c751eb3ed62273c00ed15efaa1f74c8e67a9d81 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 10 Dec 2016 16:14:54 -0800 Subject: [PATCH] fix tests on windows --- src/wormhole/test/test_scripts.py | 16 ++++++++++------ src/wormhole/test/test_util.py | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index ef7a716..e57f2fb 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -473,8 +473,10 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): if mode == "file": message = "test message\n" send_cfg.what = receive_name = send_filename = "testfile" - with open(os.path.join(send_dir, send_filename), "w") as f: + fn = os.path.join(send_dir, send_filename) + with open(fn, "w") as f: f.write(message) + size = os.stat(fn).st_size elif mode == "directory": # $send_dir/ @@ -484,12 +486,14 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): # cd $receive_dir && wormhole receive # expect: $receive_dir/$dirname/[12345] + size = 0 send_cfg.what = receive_name = send_dirname = "testdir" os.mkdir(os.path.join(send_dir, send_dirname)) for i in range(5): path = os.path.join(send_dir, send_dirname, str(i)) with open(path, "w") as f: f.write("test message %d\n" % i) + size += os.stat(path).st_size if failmode == "noclobber": PRESERVE = "don't clobber me\n" @@ -534,7 +538,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): # check sender if mode == "file": self.failUnlessIn("Sending {size:s} file named '{name}'{NL}" - .format(size=naturalsize(len(message)), + .format(size=naturalsize(size), name=send_filename, NL=NL), send_stdout) self.failUnlessIn("On the other computer, please run: " @@ -565,8 +569,8 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): .format(NL=NL), receive_stdout) else: self.failUnlessIn("Error: " - "insufficient free space (0B) for file (13B){NL}" - .format(NL=NL), receive_stdout) + "insufficient free space (0B) for file ({size:d}B){NL}" + .format(NL=NL, size=size), receive_stdout) elif mode == "directory": self.failIfIn("Received files written to {name}" .format(name=receive_name), receive_stdout) @@ -580,8 +584,8 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): .format(NL=NL), receive_stdout) else: self.failUnlessIn("Error: " - "insufficient free space (0B) for directory (75B){NL}" - .format(NL=NL), receive_stdout) + "insufficient free space (0B) for directory ({size:d}B){NL}" + .format(NL=NL, size=size), receive_stdout) if failmode == "noclobber": fn = os.path.join(receive_dir, receive_name) diff --git a/src/wormhole/test/test_util.py b/src/wormhole/test/test_util.py index ab6e1d6..f15962e 100644 --- a/src/wormhole/test/test_util.py +++ b/src/wormhole/test/test_util.py @@ -42,7 +42,7 @@ class Utils(unittest.TestCase): class Space(unittest.TestCase): def test_free_space(self): free = util.estimate_free_space(".") - self.assert_(isinstance(free, (int, None)), free) + self.assert_(isinstance(free, (int, type(None))), repr(free)) # some platforms (I think the VMs used by travis are in this # category) return 0, and windows will return None, so don't assert # anything more specific about the return value