[tests] add somewhat experimental import-time tests

add auto-generated tests that check that a given module can be imported,
if all prerequisites are followed.

see #641
This commit is contained in:
tobi-wan-kenobi 2020-07-20 13:56:18 +02:00
parent 9be1331e1b
commit 548ccc5e94
94 changed files with 624 additions and 2 deletions

View file

@ -36,16 +36,18 @@ def dependencies(filename):
dep = match.group(2) or match.group(3) dep = match.group(2) or match.group(3)
if "util.popup" in dep or ("util" in line and "popup" in line): if "util.popup" in dep or ("util" in line and "popup" in line):
deps.append("tkinter") deps.append("tkinter")
if ".datetimetz" in line:
deps.extend(dependencies("bumblebee_status/modules/contrib/datetimetz.py"))
elif not is_internal(dep): elif not is_internal(dep):
deps.append(dep) deps.append(dep)
return deps return deps
def write_test(testname, modname, deps): def write_test(testname, modname, deps):
fqmn = ".".join(["modules", testname.split(os.sep)[2], modname])
if not os.path.exists(testname): if not os.path.exists(testname):
with open(testname, "w") as f: with open(testname, "w") as f:
f.writelines([ f.writelines([
"import pytest\n\n", "import pytest\n\n",
"import core.module\n\n",
]) ])
for dep in deps: for dep in deps:
f.write("pytest.importorskip(\"{}\")\n\n".format(dep)) f.write("pytest.importorskip(\"{}\")\n\n".format(dep))
@ -60,7 +62,7 @@ def write_test(testname, modname, deps):
with open(testname, "a+") as f: with open(testname, "a+") as f:
f.writelines([ f.writelines([
"def test_load_module():\n", "def test_load_module():\n",
" core.module.load(\"{}\")\n\n".format(modname), " __import__(\"{}\")\n\n".format(fqmn),
]) ])
def main(): def main():

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.amixer")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.apt")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("tkinter")
def test_load_module():
__import__("modules.contrib.arandr")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.arch-update")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("dbus")
def test_load_module():
__import__("modules.contrib.battery-upower")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("power")
def test_load_module():
__import__("modules.contrib.battery")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("tkinter")
def test_load_module():
__import__("modules.contrib.bluetooth")

View file

@ -0,0 +1,11 @@
import pytest
pytest.importorskip("subprocess")
pytest.importorskip("dbus")
pytest.importorskip("dbus.mainloop.glib")
def test_load_module():
__import__("modules.contrib.bluetooth2")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.brightness")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("psutil")
def test_load_module():
__import__("modules.contrib.caffeine")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.cmus")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("psutil")
def test_load_module():
__import__("modules.contrib.cpu2")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("requests")
pytest.importorskip("babel.numbers")
def test_load_module():
__import__("modules.contrib.currency")

View file

@ -0,0 +1,11 @@
import pytest
pytest.importorskip("datetime")
pytest.importorskip("pytz")
pytest.importorskip("tzlocal")
def test_load_module():
__import__("modules.contrib.datetimetz")

View file

@ -0,0 +1,11 @@
import pytest
pytest.importorskip("datetime")
pytest.importorskip("pytz")
pytest.importorskip("tzlocal")
def test_load_module():
__import__("modules.contrib.datetz")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("subprocess")
def test_load_module():
__import__("modules.contrib.deadbeef")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("dbus")
def test_load_module():
__import__("modules.contrib.deezer")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.dnf")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("docker")
pytest.importorskip("requests.exceptions")
def test_load_module():
__import__("modules.contrib.docker_ps")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.dunst")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("requests")
pytest.importorskip("requests.exceptions")
def test_load_module():
__import__("modules.contrib.getcrypto")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("requests")
def test_load_module():
__import__("modules.contrib.github")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.gpmdp")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("socket")
def test_load_module():
__import__("modules.contrib.hddtemp")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.hostname")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("requests")
pytest.importorskip("psutil")
def test_load_module():
__import__("modules.contrib.http_status")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.indicator")

View file

@ -21,4 +21,8 @@ def test_full_text(mocker, kernel_module):
assert some_kernel == kernel_module.widget().full_text() assert some_kernel == kernel_module.widget().full_text()
def test_load_module():
__import__("modules.contrib.kernel")
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.layout-xkbswitch")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.layout")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("libvirt")
def test_load_module():
__import__("modules.contrib.libvirtvms")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("socket")
def test_load_module():
__import__("modules.contrib.messagereceiver")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.mocp")

View file

@ -65,3 +65,8 @@ def test_update_calls_load_song(mocker, mpd_module):
def test_default_layout(mpd_module): def test_default_layout(mpd_module):
assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat" assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat"
def test_load_module():
__import__("modules.contrib.mpd")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("psutil")
pytest.importorskip("netifaces")
def test_load_module():
__import__("modules.contrib.network_traffic")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.notmuch_count")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.nvidiagpu")

View file

@ -0,0 +1,13 @@
import pytest
pytest.importorskip("tkinter")
pytest.importorskip("PIL")
pytest.importorskip("requests")
pytest.importorskip("simplejson")
def test_load_module():
__import__("modules.contrib.octoprint")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("bumblebee_status.discover")
def test_load_module():
__import__("modules.contrib.pacman")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("requests")
def test_load_module():
__import__("modules.contrib.pihole")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.playerctl")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("datetime")
pytest.importorskip("math")
def test_load_module():
__import__("modules.contrib.pomodoro")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.portage_status")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.prime")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.progress")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.publicip")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.rotation")

View file

@ -0,0 +1,13 @@
import pytest
pytest.importorskip("feedparser")
pytest.importorskip("webbrowser")
pytest.importorskip("tempfile")
pytest.importorskip("random")
def test_load_module():
__import__("modules.contrib.rss")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.sensors")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("subprocess")
def test_load_module():
__import__("modules.contrib.shell")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.shortcut")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.smartstatus")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("requests")
def test_load_module():
__import__("modules.contrib.spaceapi")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("dbus")
def test_load_module():
__import__("modules.contrib.spotify")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("urllib.request")
def test_load_module():
__import__("modules.contrib.stock")

View file

@ -0,0 +1,13 @@
import pytest
pytest.importorskip("suntime")
pytest.importorskip("requests")
pytest.importorskip("dateutil.tz")
pytest.importorskip("datetime")
def test_load_module():
__import__("modules.contrib.sun")

View file

@ -0,0 +1,11 @@
import pytest
pytest.importorskip("tkinter")
pytest.importorskip("tkinter")
pytest.importorskip("tkinter")
def test_load_module():
__import__("modules.contrib.system")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("taskw")
def test_load_module():
__import__("modules.contrib.taskwarrior")

View file

@ -0,0 +1,11 @@
import pytest
pytest.importorskip("datetime")
pytest.importorskip("pytz")
pytest.importorskip("tzlocal")
def test_load_module():
__import__("modules.contrib.timetz")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("i3ipc")
def test_load_module():
__import__("modules.contrib.title")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.todo")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("psutil")
pytest.importorskip("netifaces")
def test_load_module():
__import__("modules.contrib.traffic")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.twmn")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("datetime")
def test_load_module():
__import__("modules.contrib.uptime")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("tkinter")
def test_load_module():
__import__("modules.contrib.vpn")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.watson")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("requests")
pytest.importorskip("requests.exceptions")
def test_load_module():
__import__("modules.contrib.weather")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.contrib.xkcd")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("yubico")
def test_load_module():
__import__("modules.contrib.yubikey")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("pkg_resources")
def test_load_module():
__import__("modules.contrib.zpool")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("psutil")
def test_load_module():
__import__("modules.core.cpu")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.date")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("datetime")
def test_load_module():
__import__("modules.core.datetime")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.debug")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.disk")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.error")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("pygit2")
def test_load_module():
__import__("modules.core.git")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("xkbgroup")
def test_load_module():
__import__("modules.core.layout-xkb")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("multiprocessing")
def test_load_module():
__import__("modules.core.load")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.memory")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("netifaces")
pytest.importorskip("subprocess")
def test_load_module():
__import__("modules.core.nic")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.pasink")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.pasource")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.ping")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.pulseaudio")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.redshift")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.sensors2")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.spacer")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("speedtest")
def test_load_module():
__import__("modules.core.speedtest")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.test")

View file

@ -0,0 +1,5 @@
import pytest
def test_load_module():
__import__("modules.core.time")

View file

@ -0,0 +1,7 @@
import pytest
pytest.importorskip("tkinter")
def test_load_module():
__import__("modules.core.vault")

View file

@ -0,0 +1,9 @@
import pytest
pytest.importorskip("bumblebee_status.discover")
pytest.importorskip("i3")
def test_load_module():
__import__("modules.core.xrandr")