From 6c103b0e16cf52bd04ea50c3f3225d075c1b84b0 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Fri, 1 May 2020 08:36:09 +0100 Subject: [PATCH 01/10] Make failed tests fail the test --- run_tests | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run_tests b/run_tests index 3bf51e4a..cc7fb56a 100755 --- a/run_tests +++ b/run_tests @@ -4,10 +4,10 @@ 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} ;; + *[Pp]ython*) python ${t} || exit 1 ;; + *Bourne*) bash ${t} || exit 1 ;; + *bash*) bash ${t} || exit 1 ;; + *perl*) perl ${t} || exit 1 ;; *) echo "Unknown" ;; esac echo From e4cd22b7bd286c62c50b80479344aea1f3a7cd5b Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 16:36:16 +0200 Subject: [PATCH 02/10] tests: Update suite for pytest --- pytest.ini | 2 ++ terminatorlib/borg.py | 1 - terminatorlib/freebsd.py | 27 ++++++++++--------- terminatorlib/plugin.py | 11 ++++---- tests/{testborg.py => test_borg.py} | 10 +++---- tests/test_doctests.py | 23 ---------------- tests/{testsignalman.py => test_signalman.py} | 2 +- 7 files changed, 27 insertions(+), 49 deletions(-) create mode 100644 pytest.ini rename tests/{testborg.py => test_borg.py} (83%) delete mode 100644 tests/test_doctests.py rename tests/{testsignalman.py => test_signalman.py} (96%) 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/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/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/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 96% rename from tests/testsignalman.py rename to tests/test_signalman.py index 7db6aed3..0877dfb6 100755 --- a/tests/testsignalman.py +++ b/tests/test_signalman.py @@ -1,7 +1,7 @@ #!/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() From 8ae32539fe13f05b30233c36b93934f964275d24 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 16:43:20 +0200 Subject: [PATCH 03/10] Switch to setuptools and use pytest --- .github/workflows/python.yml | 5 +++-- .gitignore | 1 + MANIFEST.in | 2 +- run_tests | 14 -------------- setup.cfg | 2 ++ setup.py | 33 ++++++++++++--------------------- 6 files changed, 19 insertions(+), 38 deletions(-) delete mode 100755 run_tests create mode 100644 setup.cfg diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e97a0338..3758b961 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -33,9 +33,10 @@ jobs: 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: 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..f2d8d548 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include AUTHORS CHANGELOG* COPYING INSTALL README* remotinator setup.py terminator run_tests +include AUTHORS CHANGELOG* COPYING INSTALL README* remotinator setup.py terminator recursive-include data * recursive-include doc * recursive-include po * diff --git a/run_tests b/run_tests deleted file mode 100755 index cc7fb56a..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} || exit 1 ;; - *Bourne*) bash ${t} || exit 1 ;; - *bash*) bash ${t} || exit 1 ;; - *perl*) perl ${t} || exit 1 ;; - *) 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..90a48fac 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,7 @@ PO_DIR = 'po' MO_DIR = os.path.join('build', 'mo') CSS_DIR = os.path.join('terminatorlib', 'themes') + class TerminatorDist(Distribution): global_options = Distribution.global_options + [ ("build-documentation", None, "Build the documentation"), @@ -177,21 +178,6 @@ 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: @@ -232,6 +218,9 @@ setup(name=APP_NAME, 'terminatorlib', 'terminatorlib.plugins', ], + setup_requires=[ + 'pytest-runner', + ], install_requires=[ 'pycairo', 'configobj', @@ -239,8 +228,10 @@ setup(name=APP_NAME, 'pygobject', 'psutil', ], + tests_require=[ + 'pytest', + ], 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) From e2d9bf482ae1fda588a217b0a83f8abe820de3b3 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 16:59:37 +0200 Subject: [PATCH 04/10] Reduce MANIFEST to minimum required with setuptools --- MANIFEST.in | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index f2d8d548..33d8c9f3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,3 @@ -include AUTHORS CHANGELOG* COPYING INSTALL README* remotinator setup.py terminator -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 From 4ddd4d68919f74571976bb84aa2bce48ede39be6 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 17:01:34 +0200 Subject: [PATCH 05/10] Remove old pylint script --- terminatorlib/pylint.sh | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 terminatorlib/pylint.sh 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 From 2fd5296f8cac5d76854b6e5928a47e5296a0698c Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 17:13:48 +0200 Subject: [PATCH 06/10] ci: Add other native dependencies --- .github/workflows/python.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3758b961..aa67c4c5 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -27,7 +27,11 @@ 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 - name: Install dependencies run: | From 1878571bd1130db074573daf946bf90144ac49cd Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 17:38:28 +0200 Subject: [PATCH 07/10] ci: Use pip to install dependencies --- .github/workflows/python.yml | 4 +++- setup.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index aa67c4c5..dbcdb6b6 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -43,4 +43,6 @@ jobs: run: python -m compileall -f terminatorlib/ tests/ remotinator terminator - name: Run tests - run: python setup.py test + run: | + pip install -e '.[test]' + python setup.py test diff --git a/setup.py b/setup.py index 90a48fac..b5b22390 100755 --- a/setup.py +++ b/setup.py @@ -20,6 +20,11 @@ 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 + [ @@ -183,6 +188,10 @@ if platform.system() in ['FreeBSD', 'OpenBSD']: else: man_dir = 'share/man' +test_deps = [ + 'pytest' +] + setup(name=APP_NAME, version=APP_VERSION, description='Terminator, the robot future of terminals', @@ -228,9 +237,8 @@ setup(name=APP_NAME, 'pygobject', 'psutil', ], - tests_require=[ - 'pytest', - ], + tests_require=test_deps, + extras_require={'test': test_deps}, package_data={'terminatorlib': ['preferences.glade', 'layoutlauncher.glade']}, cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall}, distclass=TerminatorDist) From 294e5820f5a467ae06acaa931fca2cab96b1d42c Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 1 May 2020 17:38:34 +0200 Subject: [PATCH 08/10] Fix Python 2.7 compat --- terminatorlib/debugserver.py | 7 +++++-- tests/test_signalman.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) 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/tests/test_signalman.py b/tests/test_signalman.py index 0877dfb6..0044e11d 100755 --- a/tests/test_signalman.py +++ b/tests/test_signalman.py @@ -7,24 +7,24 @@ >>> 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) >>> From a81c04b7cfb2485b6b16d5eecfb35bdf1cf2e483 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Thu, 7 May 2020 22:14:32 +0200 Subject: [PATCH 09/10] ci: Run tests using xvfb-run --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index dbcdb6b6..c8083f61 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -32,6 +32,7 @@ jobs: 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: | @@ -45,4 +46,4 @@ jobs: - name: Run tests run: | pip install -e '.[test]' - python setup.py test + xvfb-run -a python setup.py test From ecdcd5f1e8d6e03c16cd1da4ba4bbece5488fac7 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Sat, 9 May 2020 10:24:05 +0200 Subject: [PATCH 10/10] ci: Disable buggy python version on GH actions --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c8083f61..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: