tests: Update suite for pytest

This commit is contained in:
Markus Frosch 2020-05-01 16:36:16 +02:00
parent 6c103b0e16
commit e4cd22b7bd
7 changed files with 27 additions and 49 deletions

2
pytest.ini Normal file
View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# Terminator by Chris Jones <cmsj@tenshu.net>
# 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?

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,7 +1,7 @@
#!/usr/bin/env python
# Terminator by Chris Jones <cmsj@tenshu.net>
# GPL v2 only
"""testsignalman.py - Test the signalman class
"""test_signalman.py - Test the signalman class
>>> widget = TestWidget()
>>> signalman = Signalman()