fix tests on windows

This commit is contained in:
ed 2024-04-25 22:25:38 +00:00
parent 27485a4cb1
commit e8db3dd37f
6 changed files with 66 additions and 14 deletions

View file

@ -62,6 +62,17 @@ class U2idx(object):
def log(self, msg: str, c: Union[int, str] = 0) -> None: def log(self, msg: str, c: Union[int, str] = 0) -> None:
self.log_func("u2idx", msg, c) 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( def fsearch(
self, uname: str, vols: list[VFS], body: dict[str, Any] self, uname: str, vols: list[VFS], body: dict[str, Any]
) -> list[dict[str, Any]]: ) -> list[dict[str, Any]]:

View file

@ -4379,6 +4379,18 @@ class Up2k(object):
for x in list(self.spools): for x in list(self.spools):
self._unspool(x) 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: def up2k_chunksize(filesize: int) -> int:
chunksize = 1024 * 1024 chunksize = 1024 * 1024

View file

@ -1,6 +1,21 @@
#!/bin/bash #!/bin/bash
set -ex 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 # osx support
gtar=$(command -v gtar || command -v gnutar) || true gtar=$(command -v gtar || command -v gnutar) || true
[ ! -z "$gtar" ] && command -v gfind >/dev/null && { [ ! -z "$gtar" ] && command -v gfind >/dev/null && {

View file

@ -80,6 +80,7 @@ class TestHttpCli(unittest.TestCase):
x = " ".join(sorted([x["rp"] for x in x[0]])) 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") 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.args = Cfg(v=vcfg, a=["u1:u1", "u2:u2"], dotsrch=False, e2d=True)
self.asrv = AuthSrv(self.args, self.log) self.asrv = AuthSrv(self.args, self.log)
u2idx = U2idx(self) u2idx = U2idx(self)
@ -89,6 +90,8 @@ class TestHttpCli(unittest.TestCase):
# u1 can see dotfiles in volB so they should be included # u1 can see dotfiles in volB so they should be included
xe = "a/da/f4 a/f3 f0 t/f1" xe = "a/da/f4 a/f3 f0 t/f1"
self.assertEqual(x, xe) self.assertEqual(x, xe)
u2idx.shutdown()
up2k.shutdown()
## ##
## dirkeys ## dirkeys
@ -147,4 +150,4 @@ class TestHttpCli(unittest.TestCase):
return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1) return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1)
def log(self, src, msg, c=0): def log(self, src, msg, c=0):
print(msg) print(msg, "\033[0m")

View file

@ -6,6 +6,7 @@ import json
import os import os
import unittest import unittest
from copyparty.__init__ import ANYWIN
from copyparty.authsrv import AuthSrv from copyparty.authsrv import AuthSrv
from tests.util import Cfg from tests.util import Cfg
@ -51,6 +52,12 @@ class TestVFS(unittest.TestCase):
vn = self.nav(au, vp) vn = self.nav(au, vp)
self.assertNodes(vn, expected) 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): def prep(self):
here = os.path.abspath(os.path.dirname(__file__)) here = os.path.abspath(os.path.dirname(__file__))
cfgdir = os.path.join(here, "res", "idp") 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) au = AuthSrv(Cfg(c=[cfgdir + "/1.conf"], **xcfg), self.log)
self.assertEqual(au.vfs.vpath, "") self.assertEqual(au.vfs.vpath, "")
self.assertEqual(au.vfs.realpath, "/") self.assertApEq(au.vfs.realpath, "/")
self.assertNodes(au.vfs, ["vb"]) self.assertNodes(au.vfs, ["vb"])
self.assertNodes(au.vfs.nodes["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) au = AuthSrv(Cfg(c=[cfgdir + "/2.conf"], **xcfg), self.log)
self.assertEqual(au.vfs.vpath, "") 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, ["vb", "vc"])
self.assertNodes(au.vfs.nodes["vb"], []) self.assertNodes(au.vfs.nodes["vb"], [])
self.assertNodes(au.vfs.nodes["vc"], []) self.assertNodes(au.vfs.nodes["vc"], [])
@ -103,7 +110,7 @@ class TestVFS(unittest.TestCase):
au = AuthSrv(Cfg(c=[cfgdir + "/3.conf"], **xcfg), self.log) au = AuthSrv(Cfg(c=[cfgdir + "/3.conf"], **xcfg), self.log)
self.assertEqual(au.vfs.vpath, "") self.assertEqual(au.vfs.vpath, "")
self.assertEqual(au.vfs.realpath, "") self.assertApEq(au.vfs.realpath, "")
self.assertNodes(au.vfs, []) self.assertNodes(au.vfs, [])
self.assertAxs(au.vfs.axs, []) self.assertAxs(au.vfs.axs, [])
@ -112,8 +119,8 @@ class TestVFS(unittest.TestCase):
self.assertNodesAt(au, "vu", ["iua"]) # same as: self.assertNodesAt(au, "vu", ["iua"]) # same as:
self.assertNodes(au.vfs.nodes["vu"], ["iua"]) self.assertNodes(au.vfs.nodes["vu"], ["iua"])
self.assertNodes(au.vfs.nodes["vg"], ["iga"]) self.assertNodes(au.vfs.nodes["vg"], ["iga"])
self.assertEqual(au.vfs.nodes["vu"].realpath, "") self.assertApEq(au.vfs.nodes["vu"].realpath, "")
self.assertEqual(au.vfs.nodes["vg"].realpath, "") self.assertApEq(au.vfs.nodes["vg"].realpath, "")
self.assertAxs(au.vfs.axs, []) self.assertAxs(au.vfs.axs, [])
self.assertAxsAt(au, "vu/iua", [["iua"]]) # same as: self.assertAxsAt(au, "vu/iua", [["iua"]]) # same as:
self.assertAxs(self.nav(au, "vu/iua").axs, [["iua"]]) 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) au = AuthSrv(Cfg(c=[cfgdir + "/4.conf"], **xcfg), self.log)
self.assertEqual(au.vfs.vpath, "") self.assertEqual(au.vfs.vpath, "")
self.assertEqual(au.vfs.realpath, "") self.assertApEq(au.vfs.realpath, "")
self.assertNodes(au.vfs, ["vu"]) self.assertNodes(au.vfs, ["vu"])
self.assertNodesAt(au, "vu", ["ua", "ub"]) self.assertNodesAt(au, "vu", ["ua", "ub"])
self.assertAxs(au.vfs.axs, []) self.assertAxs(au.vfs.axs, [])
@ -147,10 +154,10 @@ class TestVFS(unittest.TestCase):
self.assertAxsAt(au, "vg", []) self.assertAxsAt(au, "vg", [])
self.assertAxsAt(au, "vg/iga1", [["iua"]]) self.assertAxsAt(au, "vg/iga1", [["iua"]])
self.assertAxsAt(au, "vg/iga2", [["iua", "ua"]]) self.assertAxsAt(au, "vg/iga2", [["iua", "ua"]])
self.assertEqual(self.nav(au, "vu/ua").realpath, "/u-ua") self.assertApEq(self.nav(au, "vu/ua").realpath, "/u-ua")
self.assertEqual(self.nav(au, "vu/iua").realpath, "/u-iua") self.assertApEq(self.nav(au, "vu/iua").realpath, "/u-iua")
self.assertEqual(self.nav(au, "vg/iga1").realpath, "/g1-iga") self.assertApEq(self.nav(au, "vg/iga1").realpath, "/g1-iga")
self.assertEqual(self.nav(au, "vg/iga2").realpath, "/g2-iga") self.assertApEq(self.nav(au, "vg/iga2").realpath, "/g2-iga")
au.idp_checkin(None, "iub", "iga") au.idp_checkin(None, "iub", "iga")
self.assertAxsAt(au, "vu/iua", [["iua"]]) self.assertAxsAt(au, "vu/iua", [["iua"]])
@ -165,7 +172,7 @@ class TestVFS(unittest.TestCase):
au = AuthSrv(Cfg(c=[cfgdir + "/5.conf"], **xcfg), self.log) au = AuthSrv(Cfg(c=[cfgdir + "/5.conf"], **xcfg), self.log)
self.assertEqual(au.vfs.vpath, "") self.assertEqual(au.vfs.vpath, "")
self.assertEqual(au.vfs.realpath, "") self.assertApEq(au.vfs.realpath, "")
self.assertNodes(au.vfs, ["g", "ga", "gb"]) self.assertNodes(au.vfs, ["g", "ga", "gb"])
self.assertAxs(au.vfs.axs, []) self.assertAxs(au.vfs.axs, [])
@ -196,7 +203,7 @@ class TestVFS(unittest.TestCase):
self.assertAxs(au.vfs.axs, []) self.assertAxs(au.vfs.axs, [])
self.assertEqual(au.vfs.vpath, "") self.assertEqual(au.vfs.vpath, "")
self.assertEqual(au.vfs.realpath, "") self.assertApEq(au.vfs.realpath, "")
self.assertNodes(au.vfs, []) self.assertNodes(au.vfs, [])
au.idp_checkin(None, "iua", "") au.idp_checkin(None, "iua", "")

View file

@ -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" 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()}) 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()}) 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" 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.u2fh = FHC()
self.get_u2idx = self.hsrv.get_u2idx self.get_u2idx = self.hsrv.get_u2idx
if WINDOWS:
os.system("rem")