mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 00:52:16 -06:00
run tests on commit
This commit is contained in:
parent
d6f516b34f
commit
273ca0c8da
12
scripts/install-githooks.sh
Executable file
12
scripts/install-githooks.sh
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
[ -e setup.py ] || ..
|
||||||
|
[ -e setup.py ] || {
|
||||||
|
echo u wot
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cd .git/hooks
|
||||||
|
rm -f pre-commit
|
||||||
|
ln -s ../../scripts/run-tests.sh pre-commit
|
12
scripts/run-tests.sh
Executable file
12
scripts/run-tests.sh
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
pids=()
|
||||||
|
for py in python{2,3}; do
|
||||||
|
$py -m unittest discover -s tests >/dev/null &
|
||||||
|
pids+=($!)
|
||||||
|
done
|
||||||
|
|
||||||
|
for pid in ${pids[@]}; do
|
||||||
|
wait $pid
|
||||||
|
done
|
|
@ -8,6 +8,7 @@ import time
|
||||||
import shutil
|
import shutil
|
||||||
import pprint
|
import pprint
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
@ -42,13 +43,15 @@ class Cfg(Namespace):
|
||||||
|
|
||||||
|
|
||||||
class TestHttpCli(unittest.TestCase):
|
class TestHttpCli(unittest.TestCase):
|
||||||
def test(self):
|
def setUp(self):
|
||||||
td = os.path.join(tu.get_ramdisk(), "vfs")
|
self.td = tu.get_ramdisk()
|
||||||
try:
|
|
||||||
shutil.rmtree(td)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(tempfile.gettempdir())
|
||||||
|
shutil.rmtree(self.td)
|
||||||
|
|
||||||
|
def test(self):
|
||||||
|
td = os.path.join(self.td, "vfs")
|
||||||
os.mkdir(td)
|
os.mkdir(td)
|
||||||
os.chdir(td)
|
os.chdir(td)
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,13 @@ class Cfg(Namespace):
|
||||||
|
|
||||||
|
|
||||||
class TestVFS(unittest.TestCase):
|
class TestVFS(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.td = tu.get_ramdisk()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(tempfile.gettempdir())
|
||||||
|
shutil.rmtree(self.td)
|
||||||
|
|
||||||
def dump(self, vfs):
|
def dump(self, vfs):
|
||||||
print(json.dumps(vfs, indent=4, sort_keys=True, default=lambda o: o.__dict__))
|
print(json.dumps(vfs, indent=4, sort_keys=True, default=lambda o: o.__dict__))
|
||||||
|
|
||||||
|
@ -55,12 +62,7 @@ class TestVFS(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
td = os.path.join(tu.get_ramdisk(), "vfs")
|
td = os.path.join(self.td, "vfs")
|
||||||
try:
|
|
||||||
shutil.rmtree(td)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
os.mkdir(td)
|
os.mkdir(td)
|
||||||
os.chdir(td)
|
os.chdir(td)
|
||||||
|
|
||||||
|
@ -227,7 +229,7 @@ class TestVFS(unittest.TestCase):
|
||||||
self.assertEqual(list(v1), list(v2))
|
self.assertEqual(list(v1), list(v2))
|
||||||
|
|
||||||
# config file parser
|
# config file parser
|
||||||
cfg_path = os.path.join(tu.get_ramdisk(), "test.cfg")
|
cfg_path = os.path.join(self.td, "test.cfg")
|
||||||
with open(cfg_path, "wb") as f:
|
with open(cfg_path, "wb") as f:
|
||||||
f.write(
|
f.write(
|
||||||
dedent(
|
dedent(
|
||||||
|
@ -260,6 +262,4 @@ class TestVFS(unittest.TestCase):
|
||||||
self.assertEqual(n.uwrite, ["asd"])
|
self.assertEqual(n.uwrite, ["asd"])
|
||||||
self.assertEqual(len(n.nodes), 0)
|
self.assertEqual(len(n.nodes), 0)
|
||||||
|
|
||||||
os.chdir(tempfile.gettempdir())
|
|
||||||
shutil.rmtree(td)
|
|
||||||
os.unlink(cfg_path)
|
os.unlink(cfg_path)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import shutil
|
||||||
import jinja2
|
import jinja2
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
@ -28,18 +29,25 @@ def chkcmd(*argv):
|
||||||
|
|
||||||
|
|
||||||
def get_ramdisk():
|
def get_ramdisk():
|
||||||
|
def subdir(top):
|
||||||
|
ret = os.path.join(top, "cptd-{}".format(os.getpid()))
|
||||||
|
shutil.rmtree(ret, True)
|
||||||
|
os.mkdir(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
for vol in ["/dev/shm", "/Volumes/cptd"]: # nosec (singleton test)
|
for vol in ["/dev/shm", "/Volumes/cptd"]: # nosec (singleton test)
|
||||||
if os.path.exists(vol):
|
if os.path.exists(vol):
|
||||||
return vol
|
return subdir(vol)
|
||||||
|
|
||||||
if os.path.exists("/Volumes"):
|
if os.path.exists("/Volumes"):
|
||||||
devname, _ = chkcmd("hdiutil", "attach", "-nomount", "ram://32768")
|
# hdiutil eject /Volumes/cptd/
|
||||||
|
devname, _ = chkcmd("hdiutil", "attach", "-nomount", "ram://65536")
|
||||||
devname = devname.strip()
|
devname = devname.strip()
|
||||||
print("devname: [{}]".format(devname))
|
print("devname: [{}]".format(devname))
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
try:
|
try:
|
||||||
_, _ = chkcmd("diskutil", "eraseVolume", "HFS+", "cptd", devname)
|
_, _ = chkcmd("diskutil", "eraseVolume", "HFS+", "cptd", devname)
|
||||||
return "/Volumes/cptd"
|
return subdir("/Volumes/cptd")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(repr(ex))
|
print(repr(ex))
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
@ -50,7 +58,7 @@ def get_ramdisk():
|
||||||
try:
|
try:
|
||||||
os.mkdir(ret)
|
os.mkdir(ret)
|
||||||
finally:
|
finally:
|
||||||
return ret
|
return subdir(ret)
|
||||||
|
|
||||||
|
|
||||||
class NullBroker(object):
|
class NullBroker(object):
|
||||||
|
|
Loading…
Reference in a new issue