diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e97a0338..fda516dc 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -14,8 +14,8 @@ jobs: matrix: python: - '2.7' - - '3.6' - - '3.7' + # - '3.6' + # - '3.7' - '3.8' steps: @@ -27,15 +27,23 @@ jobs: python-version: ${{ matrix.python }} - name: Install native dependencies - run: sudo apt-get install -y --no-install-recommends gobject-introspection gir1.2-keybinder-3.0 gettext intltool libdbus-glib-1-dev libgirepository1.0-dev libcairo-dev + run: > + sudo apt-get install -y --no-install-recommends + gobject-introspection gir1.2-glib-2.0 gir1.2-keybinder-3.0 gir1.2-gtk-3.0 gir1.2-vte-2.91 gir1.2-notify-0.7 + gettext intltool + libdbus-glib-1-dev libgirepository1.0-dev libcairo-dev + xvfb - name: Install dependencies run: | python -m pip install --upgrade pip pip install -e . + python setup.py develop - name: Compile all scripts run: python -m compileall -f terminatorlib/ tests/ remotinator terminator - - name: Run legacy tests - run: bash run_tests + - name: Run tests + run: | + pip install -e '.[test]' + xvfb-run -a python setup.py test diff --git a/.gitignore b/.gitignore index 7f74dcdf..d7a0e263 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ /.bzr ## Python +/.eggs *.pyc *.egg-info /build diff --git a/MANIFEST.in b/MANIFEST.in index 65fbcd51..33d8c9f3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,3 @@ -include AUTHORS CHANGELOG* COPYING INSTALL README* remotinator setup.py terminator run_tests -recursive-include data * -recursive-include doc * -recursive-include po * -recursive-include terminatorlib *.py *.glade *.css -recursive-include tests *.py - +include .gitignore exclude data/terminator.appdata.xml data/terminator.desktop exclude po/.intltool-merge-cache diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..68d55666 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = --doctest-modules --verbose diff --git a/run_tests b/run_tests deleted file mode 100755 index 3bf51e4a..00000000 --- a/run_tests +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -for t in tests/test*; do - echo $t - file_type=$(file -b $t) - case ${file_type} in - *[Pp]ython*) python ${t} ;; - *Bourne*) bash ${t} ;; - *bash*) bash ${t} ;; - *perl*) perl ${t} ;; - *) echo "Unknown" ;; - esac - echo -done diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..b7e47898 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[aliases] +test=pytest diff --git a/setup.py b/setup.py index 38a819a9..b5b22390 100755 --- a/setup.py +++ b/setup.py @@ -1,13 +1,13 @@ #!/usr/bin/env python -from distutils.core import setup -from distutils.dist import Distribution -from distutils.cmd import Command +from setuptools import setup, Distribution, Command + from distutils.command.install_data import install_data from distutils.command.build import build from distutils.dep_util import newer from distutils.log import warn, info, error from distutils.errors import DistutilsFileError + import glob import os import sys @@ -20,6 +20,12 @@ PO_DIR = 'po' MO_DIR = os.path.join('build', 'mo') CSS_DIR = os.path.join('terminatorlib', 'themes') +if sys.version_info < (3, 0): + PYTEST_VERSION = '<5' +else: + PYTEST_VERSION = '>0' + + class TerminatorDist(Distribution): global_options = Distribution.global_options + [ ("build-documentation", None, "Build the documentation"), @@ -177,26 +183,15 @@ class InstallData(install_data): return data_files -class Test(Command): - user_options = [] - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - import subprocess - import sys - errno = subprocess.call(['bash', 'run_tests']) - raise SystemExit(errno) - - if platform.system() in ['FreeBSD', 'OpenBSD']: man_dir = 'man' else: man_dir = 'share/man' +test_deps = [ + 'pytest' +] + setup(name=APP_NAME, version=APP_VERSION, description='Terminator, the robot future of terminals', @@ -232,6 +227,9 @@ setup(name=APP_NAME, 'terminatorlib', 'terminatorlib.plugins', ], + setup_requires=[ + 'pytest-runner', + ], install_requires=[ 'pycairo', 'configobj', @@ -239,8 +237,9 @@ setup(name=APP_NAME, 'pygobject', 'psutil', ], + tests_require=test_deps, + extras_require={'test': test_deps}, package_data={'terminatorlib': ['preferences.glade', 'layoutlauncher.glade']}, - cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall, 'test':Test}, - distclass=TerminatorDist - ) + cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall}, + distclass=TerminatorDist) diff --git a/terminatorlib/borg.py b/terminatorlib/borg.py index 6082c4d5..d52f1b60 100644 --- a/terminatorlib/borg.py +++ b/terminatorlib/borg.py @@ -16,7 +16,6 @@ class Borg: """Definition of a class that can never be duplicated. Correct usage is thus: - >>> from borg import Borg >>> class foo(Borg): ... # All attributes on a borg class *must* = None ... attribute = None diff --git a/terminatorlib/debugserver.py b/terminatorlib/debugserver.py index b0c4b2ec..731dd377 100644 --- a/terminatorlib/debugserver.py +++ b/terminatorlib/debugserver.py @@ -8,9 +8,12 @@ from terminatorlib.version import APP_NAME, APP_VERSION import socket import threading -import socketserver -import code import sys +if sys.version_info < (3, 0): + import SocketServer as socketserver +else: + import socketserver +import code import readline import rlcompleter import re diff --git a/terminatorlib/freebsd.py b/terminatorlib/freebsd.py index 67badf34..09c3d52b 100755 --- a/terminatorlib/freebsd.py +++ b/terminatorlib/freebsd.py @@ -12,6 +12,7 @@ Tested on FreeBSD 7-STABLE/amd64 from April 11 2008. """ +import platform from ctypes import * from ctypes.util import find_library @@ -44,18 +45,6 @@ class kinfo_file(Structure): ('kf_sa_peer', sockaddr_storage), ] -libc = CDLL(find_library('c')) - -uintlen = c_size_t(sizeof(c_uint)) -ver = c_uint(0) - -if (libc.sysctlbyname('kern.osreldate', byref(ver), byref(uintlen), None, 0) < 0): - raise OSError("sysctlbyname returned < 0") - -# kern.proc.filedesc added for procstat(1) after these __FreeBSD_versions -if ver.value < 700104 and ver.value < 800019: - raise NotImplementedError("cwd detection requires a recent 7.0-STABLE or 8-CURRENT") - def get_process_cwd(pid): """Return string containing the current working directory of the given pid, @@ -78,6 +67,20 @@ def get_process_cwd(pid): return kif.kf_path +if platform.system() in ['FreeBSD', 'OpenBSD']: + libc = CDLL(find_library('c')) + + uintlen = c_size_t(sizeof(c_uint)) + ver = c_uint(0) + + if (libc.sysctlbyname('kern.osreldate', byref(ver), byref(uintlen), None, 0) < 0): + raise OSError("sysctlbyname returned < 0") + + # kern.proc.filedesc added for procstat(1) after these __FreeBSD_versions + if ver.value < 700104 and ver.value < 800019: + raise NotImplementedError("cwd detection requires a recent 7.0-STABLE or 8-CURRENT") + + if __name__ == '__main__': import os, sys print(" => %d cwd = %s" % (os.getpid(), get_process_cwd(os.getpid()))) diff --git a/terminatorlib/plugin.py b/terminatorlib/plugin.py index fb4c386d..7e76d9c5 100644 --- a/terminatorlib/plugin.py +++ b/terminatorlib/plugin.py @@ -7,9 +7,10 @@ considered BSD licenced, per the authors wishes) >>> registry = PluginRegistry() ->>> registry.instances -{} ->>> registry.load_plugins(True) +>>> isinstance(registry.instances, dict) +True +>>> registry.enable('TestPlugin') +>>> registry.load_plugins() >>> plugins = registry.get_plugins_by_capability('test') >>> len(plugins) 1 @@ -69,7 +70,7 @@ class PluginRegistry(borg.Borg): if not self.available_plugins: self.available_plugins = {} - def load_plugins(self, testing=False): + def load_plugins(self): """Load all plugins present in the plugins/ directory in our module""" if self.done: dbg('PluginRegistry::load_plugins: Already loaded') @@ -98,7 +99,7 @@ class PluginRegistry(borg.Borg): func = getattr(module, item) self.available_plugins[item] = func - if not testing and item not in config['enabled_plugins']: + if item not in config['enabled_plugins']: dbg('plugin %s not enabled, skipping' % item) continue if item not in self.instances: diff --git a/terminatorlib/pylint.sh b/terminatorlib/pylint.sh deleted file mode 100644 index 208bdb7a..00000000 --- a/terminatorlib/pylint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -for file in *.py; do - line=$(pylint $file 2>&1 | grep "^Your code has been rated") - rating=$(echo $line | cut -f 7 -d ' ') - previous=$(echo $line | cut -f 10 -d ' ') - - if [ "$rating" != "10.00/10" ]; then - echo "$file rated $rating (previously $previous)" - fi -done diff --git a/tests/testborg.py b/tests/test_borg.py similarity index 83% rename from tests/testborg.py rename to tests/test_borg.py index 032872f8..d4ed6d3b 100755 --- a/tests/testborg.py +++ b/tests/test_borg.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # Terminator by Chris Jones # GPL v2 only -"""testborg.py - We are the borg. Resistance is futile. +"""test_borg.py - We are the borg. Resistance is futile. doctests for borg.py >>> obj1 = TestBorg() @@ -29,12 +29,9 @@ """ -import os -import sys, os.path -sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))) - from terminatorlib.borg import Borg + class TestBorg(Borg): attribute = None @@ -46,6 +43,7 @@ class TestBorg(Borg): if not self.attribute: self.attribute = 0 + class TestBorg2(Borg): attribute = None @@ -56,5 +54,3 @@ class TestBorg2(Borg): def prepare_attributes(self): if not self.attribute: self.attribute = 1 - -# TODO: implement test? diff --git a/tests/test_doctests.py b/tests/test_doctests.py deleted file mode 100644 index 55f586d1..00000000 --- a/tests/test_doctests.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python -"""Load up the tests.""" - -import os -import sys, os.path -sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))) - -from unittest import TestSuite -from doctest import DocTestSuite, ELLIPSIS - -def test_suite(): - suite = TestSuite() - for name in ( - 'config', - 'plugin', - 'cwd', - 'factory', - 'util', - 'tests.testborg', - 'tests.testsignalman', - ): - suite.addTest(DocTestSuite('terminatorlib.' + name)) - return suite diff --git a/tests/testsignalman.py b/tests/test_signalman.py similarity index 79% rename from tests/testsignalman.py rename to tests/test_signalman.py index 7db6aed3..0044e11d 100755 --- a/tests/testsignalman.py +++ b/tests/test_signalman.py @@ -1,30 +1,30 @@ #!/usr/bin/env python # Terminator by Chris Jones # GPL v2 only -"""testsignalman.py - Test the signalman class +"""test_signalman.py - Test the signalman class >>> widget = TestWidget() >>> signalman = Signalman() >>> signalman.new(widget, 'test1', handler) 1 ->>> signalman.cnxids[widget].keys() -dict_keys(['test1']) ->>> widget.signals.values() -dict_values(['test1']) +>>> list(signalman.cnxids[widget].keys()) +['test1'] +>>> list(widget.signals.values()) +['test1'] >>> signalman.remove_widget(widget) >>> widget in signalman.cnxids False ->>> widget.signals.values() -dict_values([]) +>>> list(widget.signals.values()) +[] >>> signalman.new(widget, 'test2', handler) 2 >>> signalman.new(widget, 'test3', handler) 3 >>> signalman.remove_signal(widget, 'test2') ->>> signalman.cnxids[widget].keys() -dict_keys(['test3']) ->>> widget.signals.values() -dict_values(['test3']) +>>> list(signalman.cnxids[widget].keys()) +['test3'] +>>> list(widget.signals.values()) +['test3'] >>> signalman.remove_widget(widget) >>>