mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
convert tests from nose to pytest
This commit is contained in:
parent
3ed5224238
commit
0d8f237754
|
@ -5,8 +5,7 @@ ignore = E123,E221,E226,E302,E41,E701
|
|||
max-line-length = 160
|
||||
max-complexity = 10
|
||||
|
||||
[nosetests]
|
||||
verbosity=3
|
||||
detailed-errors=1
|
||||
|
||||
[pytest]
|
||||
|
||||
[aliases]
|
||||
test=pytest
|
||||
|
|
14
setup.py
14
setup.py
|
@ -28,8 +28,13 @@ requirements = [
|
|||
# no external requirements
|
||||
]
|
||||
|
||||
setup_requirements = [
|
||||
'pytest-runner',
|
||||
]
|
||||
|
||||
test_requirements = [
|
||||
'nose',
|
||||
'pytest',
|
||||
'bacpypes',
|
||||
]
|
||||
|
||||
setup(
|
||||
|
@ -61,6 +66,9 @@ setup(
|
|||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
],
|
||||
test_suite='nose.collector',
|
||||
tests_require=test_requirements
|
||||
|
||||
setup_requires=setup_requirements,
|
||||
|
||||
test_suite='tests',
|
||||
tests_require=test_requirements,
|
||||
)
|
||||
|
|
|
@ -7,11 +7,12 @@ BACpypes Testing
|
|||
"""
|
||||
|
||||
from . import utilities
|
||||
from . import state_machine
|
||||
from . import time_machine
|
||||
|
||||
|
||||
def setUpPackage():
|
||||
utilities.setUpPackage()
|
||||
|
||||
|
||||
def tearDownPackage():
|
||||
utilities.tearDownPackage()
|
||||
from . import test_comm
|
||||
# from . import test_objects
|
||||
from . import test_pdu
|
||||
from . import test_primitive_data
|
||||
from . import test_utilities
|
||||
from . import test_vlan
|
||||
|
|
14
tests/conftest.py
Normal file
14
tests/conftest.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
Glue routines to simulate package setup and teardown.
|
||||
"""
|
||||
|
||||
from .utilities import setup_package, teardown_package
|
||||
|
||||
def pytest_configure(config):
|
||||
setup_package()
|
||||
|
||||
|
||||
def pytest_unconfigure():
|
||||
teardown_package()
|
|
@ -22,10 +22,6 @@ from bacpypes.task import FunctionTask as _FunctionTask
|
|||
_debug = 0
|
||||
_log = ModuleLogger(globals())
|
||||
|
||||
#
|
||||
# Transitions
|
||||
#
|
||||
|
||||
|
||||
class Transition:
|
||||
|
||||
|
@ -65,11 +61,7 @@ class TimeoutTransition(Transition):
|
|||
self.timeout = timeout
|
||||
|
||||
|
||||
#
|
||||
# State
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class State:
|
||||
|
||||
"""
|
||||
|
@ -297,14 +289,8 @@ class State:
|
|||
hex(id(self)),
|
||||
)
|
||||
|
||||
bacpypes_debugging(State)
|
||||
|
||||
|
||||
#
|
||||
# StateMachine
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class StateMachine:
|
||||
|
||||
"""
|
||||
|
@ -681,14 +667,8 @@ class StateMachine:
|
|||
hex(id(self)),
|
||||
)
|
||||
|
||||
bacpypes_debugging(StateMachine)
|
||||
|
||||
|
||||
#
|
||||
# StateMachineGroup
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class StateMachineGroup:
|
||||
|
||||
"""
|
||||
|
@ -849,14 +829,8 @@ class StateMachineGroup:
|
|||
at least one of them is in a 'fail' final state."""
|
||||
if _debug: StateMachineGroup._debug("fail")
|
||||
|
||||
bacpypes_debugging(StateMachineGroup)
|
||||
|
||||
|
||||
#
|
||||
# ClientStateMachine
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class ClientStateMachine(Client, StateMachine):
|
||||
|
||||
"""
|
||||
|
@ -882,14 +856,8 @@ class ClientStateMachine(Client, StateMachine):
|
|||
if _debug: ClientStateMachine._debug("confirmation %r", pdu)
|
||||
self.receive(pdu)
|
||||
|
||||
bacpypes_debugging(ClientStateMachine)
|
||||
|
||||
|
||||
#
|
||||
# ServerStateMachine
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class ServerStateMachine(Server, StateMachine):
|
||||
|
||||
"""
|
||||
|
@ -914,5 +882,3 @@ class ServerStateMachine(Server, StateMachine):
|
|||
def indication(self, pdu):
|
||||
if _debug: ServerStateMachine._debug("indication %r", pdu)
|
||||
self.receive(pdu)
|
||||
|
||||
bacpypes_debugging(ServerStateMachine)
|
||||
|
|
|
@ -15,6 +15,7 @@ _debug = 0
|
|||
_log = ModuleLogger(globals())
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TestSomething(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -25,5 +26,3 @@ class TestSomething(unittest.TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
if _debug: TestSomething._debug("tearDown")
|
||||
|
||||
bacpypes_debugging(TestSomething)
|
||||
|
|
|
@ -2,19 +2,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Nose Test Module Template
|
||||
-------------------------
|
||||
|
||||
This module is a template for creating MongoTree test cases. To create a
|
||||
module of new tests, make a copy of this template and rename the
|
||||
TestCaseTemplate and associated test_something functions.
|
||||
|
||||
In following with the nose testing methodology, setUpModule() will be called
|
||||
before all of the tests in this module, setUpClass() will be called before
|
||||
all of the tests in the class, and setUp() will be called before each test.
|
||||
Similarly, tearDown() will be called after each test, tearDownClass() will be
|
||||
called after all of the tests in the class, and tearDownModule() will be
|
||||
called after all of the classes in the module.
|
||||
Test Module Template
|
||||
--------------------
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
@ -27,38 +16,45 @@ _debug = 0
|
|||
_log = ModuleLogger(globals())
|
||||
|
||||
|
||||
def setUpModule():
|
||||
if _debug: setUpModule._debug("setUpModule")
|
||||
|
||||
bacpypes_debugging(setUpModule)
|
||||
@bacpypes_debugging
|
||||
def setup_module():
|
||||
if _debug: setup_module._debug("setup_module")
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
if _debug: tearDownModule._debug("tearDownModule")
|
||||
|
||||
bacpypes_debugging(tearDownModule)
|
||||
@bacpypes_debugging
|
||||
def teardown_module():
|
||||
if _debug: teardown_module._debug("teardown_module")
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def setup_function(function):
|
||||
if _debug: setup_function._debug("setup_function %r", function)
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def teardown_function(function):
|
||||
if _debug: teardown_function._debug("teardown_function %r", function)
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TestCaseTemplate(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if _debug: TestCaseTemplate._debug("setUpClass")
|
||||
def setup_class(cls):
|
||||
if _debug: TestCaseTemplate._debug("setup_class")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if _debug: TestCaseTemplate._debug("tearDownClass")
|
||||
def teardown_class(cls):
|
||||
if _debug: TestCaseTemplate._debug("teardown_class")
|
||||
|
||||
def setUp(self):
|
||||
if _debug: TestCaseTemplate._debug("setUp")
|
||||
def setup_method(self, method):
|
||||
if _debug: TestCaseTemplate._debug("setup_module %r", method)
|
||||
|
||||
def teardown_method(self, method):
|
||||
if _debug: TestCaseTemplate._debug("teardown_method %r", method)
|
||||
|
||||
def test_something(self):
|
||||
if _debug: TestCaseTemplate._debug("test_something")
|
||||
|
||||
def test_something_else(self):
|
||||
if _debug: TestCaseTemplate._debug("test_something_else")
|
||||
|
||||
def tearDown(self):
|
||||
if _debug: TestCaseTemplate._debug("tearDown")
|
||||
|
||||
bacpypes_debugging(TestCaseTemplate)
|
||||
|
|
|
@ -5,4 +5,9 @@ Test BACpypes Comm Module
|
|||
"""
|
||||
|
||||
from . import test_pci
|
||||
from . import test_pdudata
|
||||
from . import test_pdu
|
||||
|
||||
from . import test_client
|
||||
from . import test_server
|
||||
|
||||
|
|
|
@ -16,38 +16,11 @@ _debug = 0
|
|||
_log = ModuleLogger(globals())
|
||||
|
||||
|
||||
def setUpModule():
|
||||
if _debug: setUpModule._debug("setUpModule")
|
||||
|
||||
bacpypes_debugging(setUpModule)
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
if _debug: tearDownModule._debug("tearDownModule")
|
||||
|
||||
bacpypes_debugging(tearDownModule)
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TestPCI(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if _debug: TestPCI._debug("setUpClass")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if _debug: TestPCI._debug("tearDownClass")
|
||||
|
||||
def setUp(self):
|
||||
if _debug: TestPCI._debug("setUp")
|
||||
|
||||
def tearDown(self):
|
||||
if _debug: TestPCI._debug("tearDown")
|
||||
|
||||
def test_something(self):
|
||||
if _debug: TestPCI._debug("test_something")
|
||||
|
||||
def test_something_else(self):
|
||||
if _debug: TestPCI._debug("test_something_else")
|
||||
|
||||
bacpypes_debugging(TestPCI)
|
||||
|
|
|
@ -16,38 +16,11 @@ _debug = 0
|
|||
_log = ModuleLogger(globals())
|
||||
|
||||
|
||||
def setUpModule():
|
||||
if _debug: setUpModule._debug("setUpModule")
|
||||
|
||||
bacpypes_debugging(setUpModule)
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
if _debug: tearDownModule._debug("tearDownModule")
|
||||
|
||||
bacpypes_debugging(tearDownModule)
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TestPDU(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if _debug: TestPDU._debug("setUpClass")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if _debug: TestPDU._debug("tearDownClass")
|
||||
|
||||
def setUp(self):
|
||||
if _debug: TestPDU._debug("setUp")
|
||||
|
||||
def tearDown(self):
|
||||
if _debug: TestPDU._debug("tearDown")
|
||||
|
||||
def test_something(self):
|
||||
if _debug: TestPDU._debug("test_something")
|
||||
|
||||
def test_something_else(self):
|
||||
if _debug: TestPDU._debug("test_something_else")
|
||||
|
||||
bacpypes_debugging(TestPDU)
|
||||
|
|
|
@ -4,4 +4,19 @@
|
|||
Test Primitive Data Module
|
||||
"""
|
||||
|
||||
from . import test_tag
|
||||
|
||||
from . import test_bit_string
|
||||
from . import test_boolean
|
||||
from . import test_character_string
|
||||
from . import test_date
|
||||
from . import test_double
|
||||
from . import test_enumerated
|
||||
from . import test_integer
|
||||
from . import test_null
|
||||
from . import test_object_identifier
|
||||
from . import test_object_type
|
||||
from . import test_octet_string
|
||||
from . import test_real
|
||||
from . import test_time
|
||||
from . import test_unsigned
|
|
@ -41,6 +41,7 @@ def bit_string_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def bit_string_encode(obj):
|
||||
"""Encode an BitString object into a tag."""
|
||||
|
@ -161,4 +162,3 @@ class TestBitString(unittest.TestCase):
|
|||
bit_string_endec([1] * 2, '06c0')
|
||||
bit_string_endec([0] * 10, '060000')
|
||||
bit_string_endec([1] * 10, '06ffc0')
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ def boolean_tag(value):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def boolean_encode(obj):
|
||||
"""Encode an Boolean object into a tag."""
|
||||
|
|
|
@ -32,6 +32,7 @@ def character_string_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def character_string_encode(obj):
|
||||
"""Encode an CharacterString object into a tag."""
|
||||
|
|
|
@ -29,6 +29,7 @@ def date_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def date_encode(obj):
|
||||
"""Encode an Date object into a tag."""
|
||||
|
|
|
@ -31,6 +31,7 @@ def double_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def double_encode(obj):
|
||||
"""Encode an Double object into a tag."""
|
||||
|
|
|
@ -29,6 +29,7 @@ def enumerated_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def enumerated_encode(obj):
|
||||
"""Encode an Enumerated object into a tag."""
|
||||
|
|
|
@ -29,6 +29,7 @@ def integer_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def integer_encode(obj):
|
||||
"""Encode an Integer object into a tag."""
|
||||
|
|
|
@ -27,6 +27,7 @@ def null_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def null_encode(obj):
|
||||
"""Encode an Integer object into a tag."""
|
||||
|
|
|
@ -39,6 +39,7 @@ def object_type_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def object_type_encode(obj):
|
||||
"""Encode an ObjectType object into a tag."""
|
||||
|
|
|
@ -30,6 +30,7 @@ def octet_string_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def octet_string_encode(obj):
|
||||
"""Encode an OctetString object into a tag."""
|
||||
|
|
|
@ -31,6 +31,7 @@ def real_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def real_encode(obj):
|
||||
"""Encode an Real object into a tag."""
|
||||
|
|
|
@ -29,6 +29,7 @@ def time_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def time_encode(obj):
|
||||
"""Encode an Time object into a tag."""
|
||||
|
|
|
@ -29,6 +29,7 @@ def unsigned_tag(x):
|
|||
|
||||
return tag
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def unsigned_encode(obj):
|
||||
"""Encode an Unsigned object into a tag."""
|
||||
|
|
|
@ -7,6 +7,10 @@ Test Utilities
|
|||
This module tests the test utilities.
|
||||
"""
|
||||
|
||||
from . import trapped_classes
|
||||
|
||||
from . import test_state_machine
|
||||
from . import test_time_machine
|
||||
|
||||
from . import test_client_state_machine
|
||||
from . import test_server_state_machine
|
|
@ -62,6 +62,7 @@ class TestState(unittest.TestCase):
|
|||
def test_something_else(self):
|
||||
if _debug: TestState._debug("test_something_else")
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TestStateMachine(unittest.TestCase):
|
||||
|
||||
|
|
|
@ -21,14 +21,9 @@ _log = ModuleLogger(globals())
|
|||
# reference to time machine
|
||||
time_machine = None
|
||||
|
||||
#
|
||||
# setUpModule
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def setUpModule():
|
||||
if _debug: setUpModule._debug("setUpModule")
|
||||
def setup_module(module):
|
||||
if _debug: setup_module._debug("setup_module %r", module)
|
||||
global time_machine
|
||||
|
||||
# this is a singleton
|
||||
|
@ -40,18 +35,14 @@ def setUpModule():
|
|||
|
||||
|
||||
@bacpypes_debugging
|
||||
def tearDownModule():
|
||||
if _debug: tearDownModule._debug("tearDownModule")
|
||||
def teardown_module():
|
||||
if _debug: teardown_module._debug("teardown_module")
|
||||
global time_machine
|
||||
|
||||
# all done
|
||||
time_machine = None
|
||||
|
||||
|
||||
#
|
||||
# SampleOneShotTask
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
class SampleOneShotTask(OneShotTask):
|
||||
|
||||
|
@ -66,10 +57,6 @@ class SampleOneShotTask(OneShotTask):
|
|||
self.process_task_called += 1
|
||||
|
||||
|
||||
#
|
||||
# sample_task_function
|
||||
#
|
||||
|
||||
# flag to make sure the function was called
|
||||
sample_task_function_called = 0
|
||||
|
||||
|
@ -82,10 +69,6 @@ def sample_task_function(*args, **kwargs):
|
|||
sample_task_function_called += 1
|
||||
|
||||
|
||||
#
|
||||
# SampleRecurringTask
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
class SampleRecurringTask(RecurringTask):
|
||||
|
||||
|
|
|
@ -194,11 +194,8 @@ class TrappedStateMachine(StateMachine):
|
|||
# must be identical objects
|
||||
return pdu is transition_pdu
|
||||
|
||||
#
|
||||
# TrappedClient
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TrappedClient(Client):
|
||||
|
||||
"""
|
||||
|
@ -231,14 +228,8 @@ class TrappedClient(Client):
|
|||
# a reference for checking
|
||||
self.confirmation_received = pdu
|
||||
|
||||
bacpypes_debugging(TrappedClient)
|
||||
|
||||
|
||||
#
|
||||
# TrappedServer
|
||||
#
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
class TrappedServer(Server):
|
||||
|
||||
"""
|
||||
|
@ -270,5 +261,3 @@ class TrappedServer(Server):
|
|||
|
||||
# continue with processing
|
||||
Server.response(self, pdu)
|
||||
|
||||
bacpypes_debugging(TrappedServer)
|
||||
|
|
1
tests/test_vlan/__init__.py
Normal file
1
tests/test_vlan/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# placeholder
|
|
@ -20,9 +20,6 @@ _log = ModuleLogger(globals())
|
|||
# time machine
|
||||
time_machine = None
|
||||
|
||||
#
|
||||
# TimeMachine
|
||||
#
|
||||
|
||||
# @bacpypes_debugging - implicit via metaclass
|
||||
class TimeMachine(_TaskManager):
|
||||
|
@ -113,9 +110,6 @@ class TimeMachine(_TaskManager):
|
|||
|
||||
_TaskManager.process_task(self, task)
|
||||
|
||||
#
|
||||
# reset_time_machine
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
def reset_time_machine():
|
||||
|
@ -133,9 +127,6 @@ def reset_time_machine():
|
|||
time_machine.current_time = 0.0
|
||||
time_machine.time_limit = None
|
||||
|
||||
#
|
||||
# run_time_machine
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
def run_time_machine(time_limit):
|
||||
|
|
|
@ -26,19 +26,16 @@ BACPYPES_TEST_OPTION = ""
|
|||
test_options = None
|
||||
|
||||
|
||||
#
|
||||
# setUpPackage
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
def setUpPackage():
|
||||
def setup_package():
|
||||
global test_options
|
||||
|
||||
# create an argument parser
|
||||
parser = ArgumentParser(description=__doc__)
|
||||
|
||||
# add an option
|
||||
parser.add_argument('--option', help="this is an option",
|
||||
parser.add_argument(
|
||||
'--option', help="this is an option",
|
||||
default=os.getenv("BACPYPES_TEST_OPTION") or BACPYPES_TEST_OPTION,
|
||||
)
|
||||
|
||||
|
@ -46,17 +43,13 @@ def setUpPackage():
|
|||
arg_str = os.getenv("BACPYPES_TEST") or BACPYPES_TEST
|
||||
test_options = parser.parse_args(arg_str.split())
|
||||
|
||||
if _debug: setUpPackage._debug("setUpPackage")
|
||||
if _debug: setUpPackage._debug(" - test_options: %r", test_options)
|
||||
if _debug: setup_package._debug("setup_package")
|
||||
if _debug: setup_package._debug(" - test_options: %r", test_options)
|
||||
|
||||
time_machine = TimeMachine()
|
||||
if _debug: setUpPackage._debug(" - time_machine: %r", time_machine)
|
||||
|
||||
#
|
||||
# tearDownPackage
|
||||
#
|
||||
if _debug: setup_package._debug(" - time_machine: %r", time_machine)
|
||||
|
||||
|
||||
@bacpypes_debugging
|
||||
def tearDownPackage():
|
||||
if _debug: tearDownPackage._debug("tearDownPackage")
|
||||
def teardown_package():
|
||||
if _debug: teardown_package._debug("teardown_package")
|
||||
|
|
Loading…
Reference in New Issue
Block a user