Skip to content

Commit

Permalink
tests: Update suite for pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyfrosch committed May 9, 2020
1 parent 6c103b0 commit e4cd22b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 49 deletions.
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --doctest-modules --verbose
1 change: 0 additions & 1 deletion terminatorlib/borg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions terminatorlib/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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())))
Expand Down
11 changes: 6 additions & 5 deletions terminatorlib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,7 +70,7 @@ def prepare_attributes(self):
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')
Expand Down Expand Up @@ -98,7 +99,7 @@ def load_plugins(self, testing=False):
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:
Expand Down
10 changes: 3 additions & 7 deletions tests/testborg.py → tests/test_borg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Terminator by Chris Jones <[email protected]>
# 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()
Expand Down Expand Up @@ -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

Expand All @@ -46,6 +43,7 @@ def prepare_attributes(self):
if not self.attribute:
self.attribute = 0


class TestBorg2(Borg):
attribute = None

Expand All @@ -56,5 +54,3 @@ def __init__(self):
def prepare_attributes(self):
if not self.attribute:
self.attribute = 1

# TODO: implement test?
23 changes: 0 additions & 23 deletions tests/test_doctests.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/testsignalman.py → tests/test_signalman.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Terminator by Chris Jones <[email protected]>
# GPL v2 only
"""testsignalman.py - Test the signalman class
"""test_signalman.py - Test the signalman class
>>> widget = TestWidget()
>>> signalman = Signalman()
Expand Down

0 comments on commit e4cd22b

Please sign in to comment.