Merge pull request #50 from gnome-terminator/feature/better-tests

This commit is contained in:
Markus Frosch 2020-05-09 10:27:37 +02:00 committed by GitHub
commit 7f1192c441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 79 additions and 119 deletions

View File

@ -14,8 +14,8 @@ jobs:
matrix: matrix:
python: python:
- '2.7' - '2.7'
- '3.6' # - '3.6'
- '3.7' # - '3.7'
- '3.8' - '3.8'
steps: steps:
@ -27,15 +27,23 @@ jobs:
python-version: ${{ matrix.python }} python-version: ${{ matrix.python }}
- name: Install native dependencies - 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 - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -e . pip install -e .
python setup.py develop
- name: Compile all scripts - name: Compile all scripts
run: python -m compileall -f terminatorlib/ tests/ remotinator terminator run: python -m compileall -f terminatorlib/ tests/ remotinator terminator
- name: Run legacy tests - name: Run tests
run: bash run_tests run: |
pip install -e '.[test]'
xvfb-run -a python setup.py test

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
/.bzr /.bzr
## Python ## Python
/.eggs
*.pyc *.pyc
*.egg-info *.egg-info
/build /build

View File

@ -1,9 +1,3 @@
include AUTHORS CHANGELOG* COPYING INSTALL README* remotinator setup.py terminator run_tests include .gitignore
recursive-include data *
recursive-include doc *
recursive-include po *
recursive-include terminatorlib *.py *.glade *.css
recursive-include tests *.py
exclude data/terminator.appdata.xml data/terminator.desktop exclude data/terminator.appdata.xml data/terminator.desktop
exclude po/.intltool-merge-cache exclude po/.intltool-merge-cache

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
addopts = --doctest-modules --verbose

View File

@ -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

2
setup.cfg Normal file
View File

@ -0,0 +1,2 @@
[aliases]
test=pytest

View File

@ -1,13 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
from distutils.core import setup from setuptools import setup, Distribution, Command
from distutils.dist import Distribution
from distutils.cmd import Command
from distutils.command.install_data import install_data from distutils.command.install_data import install_data
from distutils.command.build import build from distutils.command.build import build
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils.log import warn, info, error from distutils.log import warn, info, error
from distutils.errors import DistutilsFileError from distutils.errors import DistutilsFileError
import glob import glob
import os import os
import sys import sys
@ -20,6 +20,12 @@ PO_DIR = 'po'
MO_DIR = os.path.join('build', 'mo') MO_DIR = os.path.join('build', 'mo')
CSS_DIR = os.path.join('terminatorlib', 'themes') CSS_DIR = os.path.join('terminatorlib', 'themes')
if sys.version_info < (3, 0):
PYTEST_VERSION = '<5'
else:
PYTEST_VERSION = '>0'
class TerminatorDist(Distribution): class TerminatorDist(Distribution):
global_options = Distribution.global_options + [ global_options = Distribution.global_options + [
("build-documentation", None, "Build the documentation"), ("build-documentation", None, "Build the documentation"),
@ -177,26 +183,15 @@ class InstallData(install_data):
return data_files 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']: if platform.system() in ['FreeBSD', 'OpenBSD']:
man_dir = 'man' man_dir = 'man'
else: else:
man_dir = 'share/man' man_dir = 'share/man'
test_deps = [
'pytest'
]
setup(name=APP_NAME, setup(name=APP_NAME,
version=APP_VERSION, version=APP_VERSION,
description='Terminator, the robot future of terminals', description='Terminator, the robot future of terminals',
@ -232,6 +227,9 @@ setup(name=APP_NAME,
'terminatorlib', 'terminatorlib',
'terminatorlib.plugins', 'terminatorlib.plugins',
], ],
setup_requires=[
'pytest-runner',
],
install_requires=[ install_requires=[
'pycairo', 'pycairo',
'configobj', 'configobj',
@ -239,8 +237,9 @@ setup(name=APP_NAME,
'pygobject', 'pygobject',
'psutil', 'psutil',
], ],
tests_require=test_deps,
extras_require={'test': test_deps},
package_data={'terminatorlib': ['preferences.glade', 'layoutlauncher.glade']}, package_data={'terminatorlib': ['preferences.glade', 'layoutlauncher.glade']},
cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall, 'test':Test}, cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall},
distclass=TerminatorDist distclass=TerminatorDist)
)

View File

@ -16,7 +16,6 @@ class Borg:
"""Definition of a class that can never be duplicated. Correct usage is """Definition of a class that can never be duplicated. Correct usage is
thus: thus:
>>> from borg import Borg
>>> class foo(Borg): >>> class foo(Borg):
... # All attributes on a borg class *must* = None ... # All attributes on a borg class *must* = None
... attribute = None ... attribute = None

View File

@ -8,9 +8,12 @@ from terminatorlib.version import APP_NAME, APP_VERSION
import socket import socket
import threading import threading
import socketserver
import code
import sys import sys
if sys.version_info < (3, 0):
import SocketServer as socketserver
else:
import socketserver
import code
import readline import readline
import rlcompleter import rlcompleter
import re import re

View File

@ -12,6 +12,7 @@
Tested on FreeBSD 7-STABLE/amd64 from April 11 2008. Tested on FreeBSD 7-STABLE/amd64 from April 11 2008.
""" """
import platform
from ctypes import * from ctypes import *
from ctypes.util import find_library from ctypes.util import find_library
@ -44,18 +45,6 @@ class kinfo_file(Structure):
('kf_sa_peer', sockaddr_storage), ('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): def get_process_cwd(pid):
"""Return string containing the current working directory of the given 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 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__': if __name__ == '__main__':
import os, sys import os, sys
print(" => %d cwd = %s" % (os.getpid(), get_process_cwd(os.getpid()))) print(" => %d cwd = %s" % (os.getpid(), get_process_cwd(os.getpid())))

View File

@ -7,9 +7,10 @@
considered BSD licenced, per the authors wishes) considered BSD licenced, per the authors wishes)
>>> registry = PluginRegistry() >>> registry = PluginRegistry()
>>> registry.instances >>> isinstance(registry.instances, dict)
{} True
>>> registry.load_plugins(True) >>> registry.enable('TestPlugin')
>>> registry.load_plugins()
>>> plugins = registry.get_plugins_by_capability('test') >>> plugins = registry.get_plugins_by_capability('test')
>>> len(plugins) >>> len(plugins)
1 1
@ -69,7 +70,7 @@ class PluginRegistry(borg.Borg):
if not self.available_plugins: if not self.available_plugins:
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""" """Load all plugins present in the plugins/ directory in our module"""
if self.done: if self.done:
dbg('PluginRegistry::load_plugins: Already loaded') dbg('PluginRegistry::load_plugins: Already loaded')
@ -98,7 +99,7 @@ class PluginRegistry(borg.Borg):
func = getattr(module, item) func = getattr(module, item)
self.available_plugins[item] = func 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) dbg('plugin %s not enabled, skipping' % item)
continue continue
if item not in self.instances: if item not in self.instances:

View File

@ -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

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# Terminator by Chris Jones <cmsj@tenshu.net> # Terminator by Chris Jones <cmsj@tenshu.net>
# GPL v2 only # 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 doctests for borg.py
>>> obj1 = TestBorg() >>> 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 from terminatorlib.borg import Borg
class TestBorg(Borg): class TestBorg(Borg):
attribute = None attribute = None
@ -46,6 +43,7 @@ class TestBorg(Borg):
if not self.attribute: if not self.attribute:
self.attribute = 0 self.attribute = 0
class TestBorg2(Borg): class TestBorg2(Borg):
attribute = None attribute = None
@ -56,5 +54,3 @@ class TestBorg2(Borg):
def prepare_attributes(self): def prepare_attributes(self):
if not self.attribute: if not self.attribute:
self.attribute = 1 self.attribute = 1
# TODO: implement test?

View File

@ -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

View File

@ -1,30 +1,30 @@
#!/usr/bin/env python #!/usr/bin/env python
# Terminator by Chris Jones <cmsj@tenshu.net> # Terminator by Chris Jones <cmsj@tenshu.net>
# GPL v2 only # GPL v2 only
"""testsignalman.py - Test the signalman class """test_signalman.py - Test the signalman class
>>> widget = TestWidget() >>> widget = TestWidget()
>>> signalman = Signalman() >>> signalman = Signalman()
>>> signalman.new(widget, 'test1', handler) >>> signalman.new(widget, 'test1', handler)
1 1
>>> signalman.cnxids[widget].keys() >>> list(signalman.cnxids[widget].keys())
dict_keys(['test1']) ['test1']
>>> widget.signals.values() >>> list(widget.signals.values())
dict_values(['test1']) ['test1']
>>> signalman.remove_widget(widget) >>> signalman.remove_widget(widget)
>>> widget in signalman.cnxids >>> widget in signalman.cnxids
False False
>>> widget.signals.values() >>> list(widget.signals.values())
dict_values([]) []
>>> signalman.new(widget, 'test2', handler) >>> signalman.new(widget, 'test2', handler)
2 2
>>> signalman.new(widget, 'test3', handler) >>> signalman.new(widget, 'test3', handler)
3 3
>>> signalman.remove_signal(widget, 'test2') >>> signalman.remove_signal(widget, 'test2')
>>> signalman.cnxids[widget].keys() >>> list(signalman.cnxids[widget].keys())
dict_keys(['test3']) ['test3']
>>> widget.signals.values() >>> list(widget.signals.values())
dict_values(['test3']) ['test3']
>>> signalman.remove_widget(widget) >>> signalman.remove_widget(widget)
>>> >>>