mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
merge resolved - testing in wrong branch
This commit is contained in:
commit
4570f1dbfc
|
@ -115,8 +115,7 @@ class ArgumentParser(_ArgumentParser):
|
|||
|
||||
# check to dump labels
|
||||
if result_args.buggers:
|
||||
loggers = logging.Logger.manager.loggerDict.keys()
|
||||
loggers.sort()
|
||||
loggers = sorted(logging.Logger.manager.loggerDict.keys())
|
||||
for loggerName in loggers:
|
||||
sys.stdout.write(loggerName + '\n')
|
||||
sys.exit(0)
|
||||
|
|
|
@ -83,7 +83,7 @@ class Address:
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, str):
|
||||
|
@ -133,7 +133,7 @@ class Address:
|
|||
if (addr > 255):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif re.match(r"^\d+:[*]$", addr):
|
||||
|
@ -161,7 +161,7 @@ class Address:
|
|||
|
||||
self.addrType = Address.remoteStationAddr
|
||||
self.addrNet = net
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif re.match(r"^0x([0-9A-Fa-f][0-9A-Fa-f])+$",addr):
|
||||
|
@ -337,17 +337,17 @@ class LocalStation(Address):
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
if _debug: Address._debug(" - bytes or bytearray")
|
||||
elif isinstance(addr, str):
|
||||
if _debug: Address._debug(" - string (bytes)")
|
||||
|
||||
self.addrAddr = bytes(addr)
|
||||
self.addrAddr = addr
|
||||
self.addrLen = len(addr)
|
||||
|
||||
else:
|
||||
raise TypeError("integer, bytes or bytearray required")
|
||||
raise TypeError("integer or string (bytes) required")
|
||||
|
||||
#
|
||||
# RemoteStation
|
||||
|
@ -366,17 +366,17 @@ class RemoteStation(Address):
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
if _debug: Address._debug(" - bytes or bytearray")
|
||||
elif isinstance(addr, str):
|
||||
if _debug: Address._debug(" - string (bytes)")
|
||||
|
||||
self.addrAddr = bytes(addr)
|
||||
self.addrAddr = addr
|
||||
self.addrLen = len(addr)
|
||||
|
||||
else:
|
||||
raise TypeError("integer, bytes or bytearray required")
|
||||
raise TypeError("integer or string (bytes) required")
|
||||
|
||||
#
|
||||
# LocalBroadcast
|
||||
|
|
|
@ -189,7 +189,7 @@ class Tag(object):
|
|||
|
||||
# context booleans have value in data
|
||||
if (dataType == Tag.booleanAppTag):
|
||||
return Tag(Tag.applicationTagClass, Tag.booleanAppTag, struct.unpack('b', self.tagData)[0], '')
|
||||
return Tag(Tag.applicationTagClass, Tag.booleanAppTag, struct.unpack('B', self.tagData)[0], '')
|
||||
else:
|
||||
return ApplicationTag(dataType, self.tagData)
|
||||
|
||||
|
|
|
@ -106,8 +106,7 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||
|
||||
# check to dump labels
|
||||
if result_args.buggers:
|
||||
loggers = logging.Logger.manager.loggerDict.keys()
|
||||
loggers.sort()
|
||||
loggers = sorted(logging.Logger.manager.loggerDict.keys())
|
||||
for loggerName in loggers:
|
||||
sys.stdout.write(loggerName + '\n')
|
||||
sys.exit(0)
|
||||
|
|
|
@ -84,7 +84,7 @@ class Address:
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, str):
|
||||
|
@ -134,7 +134,7 @@ class Address:
|
|||
if (addr > 255):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif re.match(r"^\d+:[*]$", addr):
|
||||
|
@ -162,7 +162,7 @@ class Address:
|
|||
|
||||
self.addrType = Address.remoteStationAddr
|
||||
self.addrNet = net
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif re.match(r"^0x([0-9A-Fa-f][0-9A-Fa-f])+$",addr):
|
||||
|
@ -336,7 +336,7 @@ class LocalStation(Address):
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
|
@ -365,7 +365,7 @@ class RemoteStation(Address):
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
|
|
|
@ -189,7 +189,7 @@ class Tag(object):
|
|||
|
||||
# context booleans have value in data
|
||||
if (dataType == Tag.booleanAppTag):
|
||||
return Tag(Tag.applicationTagClass, Tag.booleanAppTag, struct.unpack('b', self.tagData)[0], b'')
|
||||
return Tag(Tag.applicationTagClass, Tag.booleanAppTag, struct.unpack('B', self.tagData)[0], b'')
|
||||
else:
|
||||
return ApplicationTag(dataType, self.tagData)
|
||||
|
||||
|
|
|
@ -106,8 +106,7 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||
|
||||
# check to dump labels
|
||||
if result_args.buggers:
|
||||
loggers = logging.Logger.manager.loggerDict.keys()
|
||||
loggers.sort()
|
||||
loggers = sorted(logging.Logger.manager.loggerDict.keys())
|
||||
for loggerName in loggers:
|
||||
sys.stdout.write(loggerName + '\n')
|
||||
sys.exit(0)
|
||||
|
|
|
@ -84,7 +84,7 @@ class Address:
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
|
@ -150,7 +150,7 @@ class Address:
|
|||
if (addr > 255):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif re.match(r"^\d+:[*]$", addr):
|
||||
|
@ -178,7 +178,7 @@ class Address:
|
|||
|
||||
self.addrType = Address.remoteStationAddr
|
||||
self.addrNet = net
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif re.match(r"^0x([0-9A-Fa-f][0-9A-Fa-f])+$",addr):
|
||||
|
@ -265,7 +265,7 @@ class Address:
|
|||
elif self.addrType == Address.localStationAddr:
|
||||
rslt = ''
|
||||
if self.addrLen == 1:
|
||||
rslt += str(self.addrAddr)
|
||||
rslt += str(self.addrAddr[0])
|
||||
else:
|
||||
port = struct.unpack('!H', self.addrAddr[-2:])[0]
|
||||
if (len(self.addrAddr) == 6) and (port >= 47808) and (port <= 47823):
|
||||
|
@ -282,7 +282,7 @@ class Address:
|
|||
elif self.addrType == Address.remoteStationAddr:
|
||||
rslt = '%d:' % (self.addrNet,)
|
||||
if self.addrLen == 1:
|
||||
rslt += str(self.addrAddr)
|
||||
rslt += str(self.addrAddr[0])
|
||||
else:
|
||||
port = struct.unpack('!H', self.addrAddr[-2:])[0]
|
||||
if (len(self.addrAddr) == 6) and (port >= 47808) and (port <= 47823):
|
||||
|
@ -351,7 +351,7 @@ class LocalStation(Address):
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
|
@ -380,7 +380,7 @@ class RemoteStation(Address):
|
|||
if (addr < 0) or (addr >= 256):
|
||||
raise ValueError("address out of range")
|
||||
|
||||
self.addrAddr = struct.pack('b', addr)
|
||||
self.addrAddr = struct.pack('B', addr)
|
||||
self.addrLen = 1
|
||||
|
||||
elif isinstance(addr, (bytes, bytearray)):
|
||||
|
|
|
@ -189,7 +189,7 @@ class Tag(object):
|
|||
|
||||
# context booleans have value in data
|
||||
if (dataType == Tag.booleanAppTag):
|
||||
return Tag(Tag.applicationTagClass, Tag.booleanAppTag, struct.unpack('b', self.tagData)[0], b'')
|
||||
return Tag(Tag.applicationTagClass, Tag.booleanAppTag, struct.unpack('B', self.tagData)[0], b'')
|
||||
else:
|
||||
return ApplicationTag(dataType, self.tagData)
|
||||
|
||||
|
|
7
tests/test_pdu/__init__.py
Normal file
7
tests/test_pdu/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
Test BACpypes PDU Module
|
||||
"""
|
||||
|
||||
from . import test_address
|
95
tests/test_pdu/test_address.py
Normal file
95
tests/test_pdu/test_address.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Nose Test PDU Address
|
||||
---------------------
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from bacpypes.debugging import bacpypes_debugging, ModuleLogger, btox, xtob
|
||||
from bacpypes.pdu import Address, LocalStation, RemoteStation, \
|
||||
LocalBroadcast, RemoteBroadcast, GlobalBroadcast
|
||||
|
||||
# some debugging
|
||||
_debug = 0
|
||||
_log = ModuleLogger(globals())
|
||||
|
||||
|
||||
class TestAddress(unittest.TestCase):
|
||||
|
||||
def assertMatch(self, addr, t, n, l, a):
|
||||
assert addr.addrType == t
|
||||
assert addr.addrNet == n
|
||||
assert addr.addrLen == l
|
||||
assert addr.addrAddr == (a and xtob(a))
|
||||
|
||||
def test_address(self):
|
||||
if _debug: TestAddress._debug("test_address")
|
||||
|
||||
def test_local_station(self):
|
||||
if _debug: TestAddress._debug("test_local_station")
|
||||
|
||||
# one parameter
|
||||
with self.assertRaises(TypeError):
|
||||
LocalStation()
|
||||
|
||||
# test integer
|
||||
test_addr = LocalStation(1)
|
||||
self.assertMatch(test_addr, 2, None, 1, '01')
|
||||
assert str(test_addr) == "1"
|
||||
|
||||
test_addr = LocalStation(254)
|
||||
self.assertMatch(test_addr, 2, None, 1, 'fe')
|
||||
assert str(test_addr) == "254"
|
||||
|
||||
# test bad integer
|
||||
with self.assertRaises(ValueError):
|
||||
LocalStation(-1)
|
||||
LocalStation(256)
|
||||
|
||||
# test bytes
|
||||
test_addr = LocalStation(xtob('01'))
|
||||
self.assertMatch(test_addr, 2, None, 1, '01')
|
||||
assert str(test_addr) == "1"
|
||||
|
||||
test_addr = LocalStation(xtob('fe'))
|
||||
self.assertMatch(test_addr, 2, None, 1, 'fe')
|
||||
assert str(test_addr) == "254"
|
||||
|
||||
# multi-byte strings are hex encoded
|
||||
test_addr = LocalStation(xtob('0102'))
|
||||
self.assertMatch(test_addr, 2, None, 2, '0102')
|
||||
assert str(test_addr) == "0x0102"
|
||||
|
||||
test_addr = LocalStation(xtob('010203'))
|
||||
self.assertMatch(test_addr, 2, None, 3, '010203')
|
||||
assert str(test_addr) == "0x010203"
|
||||
|
||||
# match with an IPv4 address
|
||||
test_addr = LocalStation(xtob('01020304bac0'))
|
||||
self.assertMatch(test_addr, 2, None, 6, '01020304bac0')
|
||||
assert str(test_addr) == "1.2.3.4"
|
||||
|
||||
def test_remote_station(self):
|
||||
if _debug: TestAddress._debug("test_remote_station")
|
||||
|
||||
def test_local_broadcast(self):
|
||||
if _debug: TestAddress._debug("test_local_broadcast")
|
||||
|
||||
test_addr = LocalBroadcast()
|
||||
self.assertMatch(test_addr, 1, None, None, None)
|
||||
assert str(test_addr) == "*"
|
||||
|
||||
def test_remote_broadcast(self):
|
||||
if _debug: TestAddress._debug("test_remote_broadcast")
|
||||
|
||||
def test_global_broadcast(self):
|
||||
if _debug: TestAddress._debug("test_global_broadcast")
|
||||
|
||||
test_addr = GlobalBroadcast()
|
||||
self.assertMatch(test_addr, 5, None, None, None)
|
||||
assert str(test_addr) == "*:*"
|
||||
|
||||
bacpypes_debugging(TestAddress)
|
Loading…
Reference in New Issue
Block a user