From e8db3dd37f8568f099de4b72e7119817ace01245 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 25 Apr 2024 22:25:38 +0000 Subject: [PATCH] fix tests on windows --- copyparty/u2idx.py | 11 +++++++++++ copyparty/up2k.py | 12 ++++++++++++ scripts/run-tests.sh | 15 +++++++++++++++ tests/test_dots.py | 5 ++++- tests/test_idp.py | 31 +++++++++++++++++++------------ tests/util.py | 6 +++++- 6 files changed, 66 insertions(+), 14 deletions(-) diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index c9ffe141..bde7bdbf 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -62,6 +62,17 @@ class U2idx(object): def log(self, msg: str, c: Union[int, str] = 0) -> None: self.log_func("u2idx", msg, c) + def shutdown(self) -> None: + for cur in self.cur.values(): + db = cur.connection + try: + db.interrupt() + except: + pass + + cur.close() + db.close() + def fsearch( self, uname: str, vols: list[VFS], body: dict[str, Any] ) -> list[dict[str, Any]]: diff --git a/copyparty/up2k.py b/copyparty/up2k.py index db993541..92d040a2 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -4379,6 +4379,18 @@ class Up2k(object): for x in list(self.spools): self._unspool(x) + for cur in self.cur.values(): + db = cur.connection + try: + db.interrupt() + except: + pass + + cur.close() + db.close() + + self.registry = {} + def up2k_chunksize(filesize: int) -> int: chunksize = 1024 * 1024 diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 10083ba7..545a4b56 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,6 +1,21 @@ #!/bin/bash set -ex +if uname | grep -iE '^(msys|mingw)'; then + pids=() + + python -m unittest discover -s tests >/dev/null & + pids+=($!) + + python scripts/test/smoketest.py & + pids+=($!) + + for pid in ${pids[@]}; do + wait $pid + done + exit $? +fi + # osx support gtar=$(command -v gtar || command -v gnutar) || true [ ! -z "$gtar" ] && command -v gfind >/dev/null && { diff --git a/tests/test_dots.py b/tests/test_dots.py index 577d52d6..dd568867 100644 --- a/tests/test_dots.py +++ b/tests/test_dots.py @@ -80,6 +80,7 @@ class TestHttpCli(unittest.TestCase): x = " ".join(sorted([x["rp"] for x in x[0]])) self.assertEqual(x, ".f0 .t/.f2 .t/f2 a/da/f4 a/f3 f0 t/.f1 t/f1") + u2idx.shutdown() self.args = Cfg(v=vcfg, a=["u1:u1", "u2:u2"], dotsrch=False, e2d=True) self.asrv = AuthSrv(self.args, self.log) u2idx = U2idx(self) @@ -89,6 +90,8 @@ class TestHttpCli(unittest.TestCase): # u1 can see dotfiles in volB so they should be included xe = "a/da/f4 a/f3 f0 t/f1" self.assertEqual(x, xe) + u2idx.shutdown() + up2k.shutdown() ## ## dirkeys @@ -147,4 +150,4 @@ class TestHttpCli(unittest.TestCase): return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1) def log(self, src, msg, c=0): - print(msg) + print(msg, "\033[0m") diff --git a/tests/test_idp.py b/tests/test_idp.py index 03fb628f..8c12b569 100644 --- a/tests/test_idp.py +++ b/tests/test_idp.py @@ -6,6 +6,7 @@ import json import os import unittest +from copyparty.__init__ import ANYWIN from copyparty.authsrv import AuthSrv from tests.util import Cfg @@ -51,6 +52,12 @@ class TestVFS(unittest.TestCase): vn = self.nav(au, vp) self.assertNodes(vn, expected) + def assertApEq(self, ap, rhs): + if ANYWIN and len(ap) > 2 and ap[1] == ":": + ap = ap[2:].replace("\\", "/") + + return self.assertEqual(ap, rhs) + def prep(self): here = os.path.abspath(os.path.dirname(__file__)) cfgdir = os.path.join(here, "res", "idp") @@ -70,7 +77,7 @@ class TestVFS(unittest.TestCase): au = AuthSrv(Cfg(c=[cfgdir + "/1.conf"], **xcfg), self.log) self.assertEqual(au.vfs.vpath, "") - self.assertEqual(au.vfs.realpath, "/") + self.assertApEq(au.vfs.realpath, "/") self.assertNodes(au.vfs, ["vb"]) self.assertNodes(au.vfs.nodes["vb"], []) @@ -85,7 +92,7 @@ class TestVFS(unittest.TestCase): au = AuthSrv(Cfg(c=[cfgdir + "/2.conf"], **xcfg), self.log) self.assertEqual(au.vfs.vpath, "") - self.assertEqual(au.vfs.realpath, "/") + self.assertApEq(au.vfs.realpath, "/") self.assertNodes(au.vfs, ["vb", "vc"]) self.assertNodes(au.vfs.nodes["vb"], []) self.assertNodes(au.vfs.nodes["vc"], []) @@ -103,7 +110,7 @@ class TestVFS(unittest.TestCase): au = AuthSrv(Cfg(c=[cfgdir + "/3.conf"], **xcfg), self.log) self.assertEqual(au.vfs.vpath, "") - self.assertEqual(au.vfs.realpath, "") + self.assertApEq(au.vfs.realpath, "") self.assertNodes(au.vfs, []) self.assertAxs(au.vfs.axs, []) @@ -112,8 +119,8 @@ class TestVFS(unittest.TestCase): self.assertNodesAt(au, "vu", ["iua"]) # same as: self.assertNodes(au.vfs.nodes["vu"], ["iua"]) self.assertNodes(au.vfs.nodes["vg"], ["iga"]) - self.assertEqual(au.vfs.nodes["vu"].realpath, "") - self.assertEqual(au.vfs.nodes["vg"].realpath, "") + self.assertApEq(au.vfs.nodes["vu"].realpath, "") + self.assertApEq(au.vfs.nodes["vg"].realpath, "") self.assertAxs(au.vfs.axs, []) self.assertAxsAt(au, "vu/iua", [["iua"]]) # same as: self.assertAxs(self.nav(au, "vu/iua").axs, [["iua"]]) @@ -127,7 +134,7 @@ class TestVFS(unittest.TestCase): au = AuthSrv(Cfg(c=[cfgdir + "/4.conf"], **xcfg), self.log) self.assertEqual(au.vfs.vpath, "") - self.assertEqual(au.vfs.realpath, "") + self.assertApEq(au.vfs.realpath, "") self.assertNodes(au.vfs, ["vu"]) self.assertNodesAt(au, "vu", ["ua", "ub"]) self.assertAxs(au.vfs.axs, []) @@ -147,10 +154,10 @@ class TestVFS(unittest.TestCase): self.assertAxsAt(au, "vg", []) self.assertAxsAt(au, "vg/iga1", [["iua"]]) self.assertAxsAt(au, "vg/iga2", [["iua", "ua"]]) - self.assertEqual(self.nav(au, "vu/ua").realpath, "/u-ua") - self.assertEqual(self.nav(au, "vu/iua").realpath, "/u-iua") - self.assertEqual(self.nav(au, "vg/iga1").realpath, "/g1-iga") - self.assertEqual(self.nav(au, "vg/iga2").realpath, "/g2-iga") + self.assertApEq(self.nav(au, "vu/ua").realpath, "/u-ua") + self.assertApEq(self.nav(au, "vu/iua").realpath, "/u-iua") + self.assertApEq(self.nav(au, "vg/iga1").realpath, "/g1-iga") + self.assertApEq(self.nav(au, "vg/iga2").realpath, "/g2-iga") au.idp_checkin(None, "iub", "iga") self.assertAxsAt(au, "vu/iua", [["iua"]]) @@ -165,7 +172,7 @@ class TestVFS(unittest.TestCase): au = AuthSrv(Cfg(c=[cfgdir + "/5.conf"], **xcfg), self.log) self.assertEqual(au.vfs.vpath, "") - self.assertEqual(au.vfs.realpath, "") + self.assertApEq(au.vfs.realpath, "") self.assertNodes(au.vfs, ["g", "ga", "gb"]) self.assertAxs(au.vfs.axs, []) @@ -196,7 +203,7 @@ class TestVFS(unittest.TestCase): self.assertAxs(au.vfs.axs, []) self.assertEqual(au.vfs.vpath, "") - self.assertEqual(au.vfs.realpath, "") + self.assertApEq(au.vfs.realpath, "") self.assertNodes(au.vfs, []) au.idp_checkin(None, "iua", "") diff --git a/tests/util.py b/tests/util.py index 2cc02e17..1998f102 100644 --- a/tests/util.py +++ b/tests/util.py @@ -113,7 +113,7 @@ class Cfg(Namespace): ex = "daw dav_auth dav_inf dav_mac dav_rt e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp early_ban ed emp exp force_js getmod grid hardlink ih ihead magic never_symlink nid nih no_acode no_athumb no_dav no_dedup no_del no_dupe no_lifetime no_logues no_mv no_pipe no_readme no_robots no_sb_md no_sb_lg no_scandir no_tarcmp no_thumb no_vthumb no_zip nrand nw q rand smb srch_dbg stats vague_403 vc ver xdev xlink xvol" ka.update(**{k: False for k in ex.split()}) - ex = "dotpart dotsrch no_dhash no_fastboot no_rescan no_sendfile no_voldump re_dhash plain_ip" + ex = "dotpart dotsrch no_dhash no_fastboot no_rescan no_sendfile no_snap no_voldump re_dhash plain_ip" ka.update(**{k: True for k in ex.split()}) ex = "ah_cli ah_gen css_browser hist js_browser no_forget no_hash no_idx nonsus_urls" @@ -260,3 +260,7 @@ class VHttpConn(object): self.u2fh = FHC() self.get_u2idx = self.hsrv.get_u2idx + + +if WINDOWS: + os.system("rem")