Commit 443f8518 authored by olivier R-D's avatar olivier R-D

Consequently Ua and not UA in code

parent 00ad7301
...@@ -106,13 +106,13 @@ class UASocketClient(object): ...@@ -106,13 +106,13 @@ class UASocketClient(object):
elif isinstance(msg, ua.ErrorMessage): elif isinstance(msg, ua.ErrorMessage):
self.logger.warning("Received an error: {}".format(msg)) self.logger.warning("Received an error: {}".format(msg))
else: else:
raise ua.UAError("Unsupported message type: {}".format(msg)) raise ua.UaError("Unsupported message type: {}".format(msg))
def _call_callback(self, request_id, body): def _call_callback(self, request_id, body):
with self._lock: with self._lock:
future = self._callbackmap.pop(request_id, None) future = self._callbackmap.pop(request_id, None)
if future is None: if future is None:
raise ua.UAError("No future object found for request: {}, callbacks in list are {}".format(request_id, self._callbackmap.keys())) raise ua.UaError("No future object found for request: {}, callbacks in list are {}".format(request_id, self._callbackmap.keys()))
future.set_result(body) future.set_result(body)
def _create_request_header(self, timeout=1000): def _create_request_header(self, timeout=1000):
......
...@@ -123,7 +123,7 @@ class Client(object): ...@@ -123,7 +123,7 @@ class Client(object):
return return
parts = string.split(',') parts = string.split(',')
if len(parts) < 4: if len(parts) < 4:
raise UAError('Wrong format: `{}`, expected at least 4 ' raise UaError('Wrong format: `{}`, expected at least 4 '
'comma-separated values'.format(string)) 'comma-separated values'.format(string))
policy_class = getattr(security_policies, 'SecurityPolicy' + parts[0]) policy_class = getattr(security_policies, 'SecurityPolicy' + parts[0])
mode = getattr(ua.MessageSecurityMode, parts[1]) mode = getattr(ua.MessageSecurityMode, parts[1])
...@@ -314,7 +314,7 @@ class Client(object): ...@@ -314,7 +314,7 @@ class Client(object):
if not self.security_policy.server_certificate: if not self.security_policy.server_certificate:
self.security_policy.server_certificate = response.ServerCertificate self.security_policy.server_certificate = response.ServerCertificate
elif self.security_policy.server_certificate != response.ServerCertificate: elif self.security_policy.server_certificate != response.ServerCertificate:
raise UAError("Server certificate mismatch") raise UaError("Server certificate mismatch")
# remember PolicyId's: we will use them in activate_session() # remember PolicyId's: we will use them in activate_session()
ep = Client.find_endpoint(response.ServerEndpoints, self.security_policy.Mode, self.security_policy.URI) ep = Client.find_endpoint(response.ServerEndpoints, self.security_policy.Mode, self.security_policy.URI)
self._policy_ids = ep.UserIdentityTokens self._policy_ids = ep.UserIdentityTokens
......
...@@ -194,10 +194,10 @@ def _vtype_to_argument(vtype): ...@@ -194,10 +194,10 @@ def _vtype_to_argument(vtype):
def _guess_uatype(variant): def _guess_uatype(variant):
if variant.VariantType == ua.VariantType.ExtensionObject: if variant.VariantType == ua.VariantType.ExtensionObject:
if variant.Value is None: if variant.Value is None:
raise ua.UAError("Cannot guess DataType from Null ExtensionObject") raise ua.UaError("Cannot guess DataType from Null ExtensionObject")
if type(variant.Value) in (list, tuple): if type(variant.Value) in (list, tuple):
if len(variant.Value) == 0: if len(variant.Value) == 0:
raise ua.UAError("Cannot guess DataType from Null ExtensionObject") raise ua.UaError("Cannot guess DataType from Null ExtensionObject")
extobj = variant.Value[0] extobj = variant.Value[0]
else: else:
extobj = variant.Value extobj = variant.Value
......
...@@ -24,7 +24,7 @@ class Node(object): ...@@ -24,7 +24,7 @@ class Node(object):
elif isinstance(nodeid, int): elif isinstance(nodeid, int):
self.nodeid = ua.NodeId(nodeid, 0) self.nodeid = ua.NodeId(nodeid, 0)
else: else:
raise ua.UAError("argument to node must be a NodeId object or a string defining a nodeid found {} of type {}".format(nodeid, type(nodeid))) raise ua.UaError("argument to node must be a NodeId object or a string defining a nodeid found {} of type {}".format(nodeid, type(nodeid)))
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, Node) and self.nodeid == other.nodeid: if isinstance(other, Node) and self.nodeid == other.nodeid:
......
...@@ -3,13 +3,13 @@ Define exceptions to be raised at various places in the stack ...@@ -3,13 +3,13 @@ Define exceptions to be raised at various places in the stack
""" """
class UAError(RuntimeError): class UaError(RuntimeError):
pass pass
class UAStatusCodeError(UAError): class UaStatusCodeError(UaError):
pass pass
class UAStringParsingError(UAError): class UaStringParsingError(UaError):
pass pass
...@@ -11,20 +11,20 @@ except ImportError: ...@@ -11,20 +11,20 @@ except ImportError:
import trollius as asyncio import trollius as asyncio
from opcua.common.uaerrors import UAError from opcua.common.uaerrors import UaError
class ServiceError(UAError): class ServiceError(UaError):
def __init__(self, code): def __init__(self, code):
super(ServiceError, self).__init__('UA Service Error') super(ServiceError, self).__init__('UA Service Error')
self.code = code self.code = code
class NotEnoughData(UAError): class NotEnoughData(UaError):
pass pass
class SocketClosedException(UAError): class SocketClosedException(UaError):
pass pass
......
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from opcua.ua import CryptographyNone, SecurityPolicy from opcua.ua import CryptographyNone, SecurityPolicy
from opcua.ua import MessageSecurityMode from opcua.ua import MessageSecurityMode
from opcua.ua import UAError from opcua.ua import UaError
try: try:
from opcua.crypto import uacrypto from opcua.crypto import uacrypto
CRYPTOGRAPHY_AVAILABLE = True CRYPTOGRAPHY_AVAILABLE = True
...@@ -15,7 +15,7 @@ def require_cryptography(obj): ...@@ -15,7 +15,7 @@ def require_cryptography(obj):
Call this function in constructors. Call this function in constructors.
""" """
if not CRYPTOGRAPHY_AVAILABLE: if not CRYPTOGRAPHY_AVAILABLE:
raise UAError("Can't use {}, cryptography module is not installed".format(obj.__class__.__name__)) raise UaError("Can't use {}, cryptography module is not installed".format(obj.__class__.__name__))
class Signer(object): class Signer(object):
......
...@@ -10,7 +10,7 @@ from threading import Thread ...@@ -10,7 +10,7 @@ from threading import Thread
from threading import Condition from threading import Condition
from opcua import ua from opcua import ua
from opcua.uaprocessor import UAProcessor from opcua.uaprocessor import UaProcessor
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -61,7 +61,7 @@ class UAHandler(socketserver.BaseRequestHandler): ...@@ -61,7 +61,7 @@ class UAHandler(socketserver.BaseRequestHandler):
def handle(self): def handle(self):
sock = ua.utils.SocketWrapper(self.request) sock = ua.utils.SocketWrapper(self.request)
processor = UAProcessor(self.server.internal_server, sock, self.client_address) processor = UaProcessor(self.server.internal_server, sock, self.client_address)
try: try:
while True: while True:
hdr = ua.Header.from_string(sock) hdr = ua.Header.from_string(sock)
......
...@@ -10,7 +10,7 @@ except ImportError: ...@@ -10,7 +10,7 @@ except ImportError:
from opcua import ua from opcua import ua
from opcua.server.uaprocessor import UAProcessor from opcua.server.uaprocessor import UaProcessor
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -49,7 +49,7 @@ class BinaryServer(object): ...@@ -49,7 +49,7 @@ class BinaryServer(object):
self.peername = transport.get_extra_info('peername') self.peername = transport.get_extra_info('peername')
self.logger.info('New connection from %s', self.peername) self.logger.info('New connection from %s', self.peername)
self.transport = transport self.transport = transport
self.processor = UAProcessor(self.iserver, self.transport) self.processor = UaProcessor(self.iserver, self.transport)
self.processor.set_policies(self.policies) self.processor.set_policies(self.policies)
self.data = b"" self.data = b""
......
...@@ -15,7 +15,7 @@ class PublishRequestData(object): ...@@ -15,7 +15,7 @@ class PublishRequestData(object):
self.seqhdr = None self.seqhdr = None
class UAProcessor(object): class UaProcessor(object):
def __init__(self, internal_server, socket): def __init__(self, internal_server, socket):
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
......
#AUTOGENERATED!!! #AUTOGENERATED!!!
from opcua.common.uaerrors import UAStatusCodeError from opcua.common.uaerrors import UaStatusCodeError
class StatusCodes(object): class StatusCodes(object):
Good = 0 Good = 0
......
...@@ -6,7 +6,7 @@ from datetime import datetime ...@@ -6,7 +6,7 @@ from datetime import datetime
from enum import Enum, IntEnum from enum import Enum, IntEnum
from opcua.common.utils import Buffer from opcua.common.utils import Buffer
from opcua.common.uaerrors import UAError from opcua.common.uaerrors import UaError
from opcua.ua.uatypes import * from opcua.ua.uatypes import *
from opcua.ua.object_ids import ObjectIds from opcua.ua.object_ids import ObjectIds
...@@ -14321,7 +14321,7 @@ def extensionobject_from_binary(data): ...@@ -14321,7 +14321,7 @@ def extensionobject_from_binary(data):
return e return e
klass = ExtensionClasses[TypeId.Identifier] klass = ExtensionClasses[TypeId.Identifier]
if body is None: if body is None:
raise UAError("parsing ExtensionObject {} without data".format(klass.__name__)) raise UaError("parsing ExtensionObject {} without data".format(klass.__name__))
return klass.from_binary(body) return klass.from_binary(body)
......
...@@ -380,7 +380,7 @@ class MessageChunk(uatypes.FrozenClass): ...@@ -380,7 +380,7 @@ class MessageChunk(uatypes.FrozenClass):
elif msg_type == MessageType.SecureOpen: elif msg_type == MessageType.SecureOpen:
self.SecurityHeader = AsymmetricAlgorithmHeader() self.SecurityHeader = AsymmetricAlgorithmHeader()
else: else:
raise UAError("Unsupported message type: {}".format(msg_type)) raise UaError("Unsupported message type: {}".format(msg_type))
self.SequenceHeader = SequenceHeader() self.SequenceHeader = SequenceHeader()
self.Body = body self.Body = body
self._security_policy = security_policy self._security_policy = security_policy
...@@ -402,7 +402,7 @@ class MessageChunk(uatypes.FrozenClass): ...@@ -402,7 +402,7 @@ class MessageChunk(uatypes.FrozenClass):
security_header = AsymmetricAlgorithmHeader.from_binary(data) security_header = AsymmetricAlgorithmHeader.from_binary(data)
crypto = security_policy.asymmetric_cryptography crypto = security_policy.asymmetric_cryptography
else: else:
raise UAError("Unsupported message type: {}".format(header.MessageType)) raise UaError("Unsupported message type: {}".format(header.MessageType))
obj = MessageChunk(crypto) obj = MessageChunk(crypto)
obj.MessageHeader = header obj.MessageHeader = header
obj.SecurityHeader = security_header obj.SecurityHeader = security_header
...@@ -532,7 +532,7 @@ class SecureConnection(object): ...@@ -532,7 +532,7 @@ class SecureConnection(object):
return return
if self._security_policy.URI != uri or (mode is not None and if self._security_policy.URI != uri or (mode is not None and
self._security_policy.Mode != mode): self._security_policy.Mode != mode):
raise UAError("No matching policy: {}, {}".format(uri, mode)) raise UaError("No matching policy: {}, {}".format(uri, mode))
def set_security_token(self, tok): def set_security_token(self, tok):
self._security_token = tok self._security_token = tok
...@@ -572,16 +572,16 @@ class SecureConnection(object): ...@@ -572,16 +572,16 @@ class SecureConnection(object):
assert isinstance(chunk, MessageChunk), "Expected chunk, got: {}".format(chunk) assert isinstance(chunk, MessageChunk), "Expected chunk, got: {}".format(chunk)
if chunk.MessageHeader.MessageType != MessageType.SecureOpen: if chunk.MessageHeader.MessageType != MessageType.SecureOpen:
if chunk.MessageHeader.ChannelId != self._security_token.ChannelId: if chunk.MessageHeader.ChannelId != self._security_token.ChannelId:
raise UAError("Wrong channel id {}, expected {}".format( raise UaError("Wrong channel id {}, expected {}".format(
chunk.MessageHeader.ChannelId, chunk.MessageHeader.ChannelId,
self._security_token.ChannelId)) self._security_token.ChannelId))
if chunk.SecurityHeader.TokenId != self._security_token.TokenId: if chunk.SecurityHeader.TokenId != self._security_token.TokenId:
raise UAError("Wrong token id {}, expected {}".format( raise UaError("Wrong token id {}, expected {}".format(
chunk.SecurityHeader.TokenId, chunk.SecurityHeader.TokenId,
self._security_token.TokenId)) self._security_token.TokenId))
if self._incoming_parts: if self._incoming_parts:
if self._incoming_parts[0].SequenceHeader.RequestId != chunk.SequenceHeader.RequestId: if self._incoming_parts[0].SequenceHeader.RequestId != chunk.SequenceHeader.RequestId:
raise UAError("Wrong request id {}, expected {}".format( raise UaError("Wrong request id {}, expected {}".format(
chunk.SequenceHeader.RequestId, chunk.SequenceHeader.RequestId,
self._incoming_parts[0].SequenceHeader.RequestId)) self._incoming_parts[0].SequenceHeader.RequestId))
...@@ -595,7 +595,7 @@ class SecureConnection(object): ...@@ -595,7 +595,7 @@ class SecureConnection(object):
logger.debug("Sequence number wrapped: %d -> %d", logger.debug("Sequence number wrapped: %d -> %d",
self._peer_sequence_number, num) self._peer_sequence_number, num)
else: else:
raise UAError( raise UaError(
"Wrong sequence {} -> {} (server bug or replay attack)" "Wrong sequence {} -> {} (server bug or replay attack)"
.format(self._peer_sequence_number, num)) .format(self._peer_sequence_number, num))
self._peer_sequence_number = num self._peer_sequence_number = num
...@@ -630,7 +630,7 @@ class SecureConnection(object): ...@@ -630,7 +630,7 @@ class SecureConnection(object):
logger.warning("Received an error: {}".format(msg)) logger.warning("Received an error: {}".format(msg))
return msg return msg
else: else:
raise UAError("Unsupported message type {}".format(header.MessageType)) raise UaError("Unsupported message type {}".format(header.MessageType))
def receive_from_socket(self, socket): def receive_from_socket(self, socket):
""" """
...@@ -643,7 +643,7 @@ class SecureConnection(object): ...@@ -643,7 +643,7 @@ class SecureConnection(object):
logger.info("received header: %s", header) logger.info("received header: %s", header)
body = socket.read(header.body_size) body = socket.read(header.body_size)
if len(body) != header.body_size: if len(body) != header.body_size:
raise UAError("{} bytes expected, {} available".format(header.body_size, len(body))) raise UaError("{} bytes expected, {} available".format(header.body_size, len(body)))
return self.receive_from_header_and_body(header, utils.Buffer(body)) return self.receive_from_header_and_body(header, utils.Buffer(body))
def _receive(self, msg): def _receive(self, msg):
...@@ -663,7 +663,7 @@ class SecureConnection(object): ...@@ -663,7 +663,7 @@ class SecureConnection(object):
self._incoming_parts = [] self._incoming_parts = []
return message return message
else: else:
raise UAError("Unsupported chunk type: {}".format(msg)) raise UaError("Unsupported chunk type: {}".format(msg))
# FIXES for missing switchfield in NodeAttributes classes # FIXES for missing switchfield in NodeAttributes classes
......
...@@ -13,8 +13,8 @@ if sys.version_info.major > 2: ...@@ -13,8 +13,8 @@ if sys.version_info.major > 2:
unicode = str unicode = str
from opcua.ua import status_codes from opcua.ua import status_codes
from opcua.common.uaerrors import UAError from opcua.common.uaerrors import UaError
from opcua.common.uaerrors import UAStatusCodeError from opcua.common.uaerrors import UaStatusCodeError
logger = logging.getLogger('opcua.uaprotocol') logger = logging.getLogger('opcua.uaprotocol')
...@@ -171,7 +171,7 @@ def unpack_uatype(uatype, data): ...@@ -171,7 +171,7 @@ def unpack_uatype(uatype, data):
klass = glbs[uatype] klass = glbs[uatype]
if hasattr(klass, 'from_binary'): if hasattr(klass, 'from_binary'):
return klass.from_binary(data) return klass.from_binary(data)
raise UAError("can not unpack unknown uatype %s" % uatype) raise UaError("can not unpack unknown uatype %s" % uatype)
def unpack_uatype_array(uatype, data): def unpack_uatype_array(uatype, data):
...@@ -319,7 +319,7 @@ class StatusCode(FrozenClass): ...@@ -319,7 +319,7 @@ class StatusCode(FrozenClass):
use is is_good() method if not exception is desired use is is_good() method if not exception is desired
""" """
if self.value != 0: if self.value != 0:
raise UAStatusCodeError("{}({})".format(self.doc, self.name)) raise UaStatusCodeError("{}({})".format(self.doc, self.name))
def is_good(self): def is_good(self):
""" """
...@@ -383,7 +383,7 @@ class NodeId(FrozenClass): ...@@ -383,7 +383,7 @@ class NodeId(FrozenClass):
elif isinstance(self.Identifier, bytes): elif isinstance(self.Identifier, bytes):
self.NodeIdType = NodeIdType.ByteString self.NodeIdType = NodeIdType.ByteString
else: else:
raise UAError("NodeId: Could not guess type of NodeId, set NodeIdType") raise UaError("NodeId: Could not guess type of NodeId, set NodeIdType")
def __key(self): def __key(self):
if self.NodeIdType in (NodeIdType.TwoByte, NodeIdType.FourByte, NodeIdType.Numeric): # twobyte, fourbyte and numeric may represent the same node if self.NodeIdType in (NodeIdType.TwoByte, NodeIdType.FourByte, NodeIdType.Numeric): # twobyte, fourbyte and numeric may represent the same node
...@@ -430,7 +430,7 @@ class NodeId(FrozenClass): ...@@ -430,7 +430,7 @@ class NodeId(FrozenClass):
elif k == "nsu": elif k == "nsu":
nsu = v nsu = v
if identifier is None: if identifier is None:
raise UAError("Could not parse nodeid string: " + string) raise UaError("Could not parse nodeid string: " + string)
nodeid = NodeId(identifier, namespace, ntype) nodeid = NodeId(identifier, namespace, ntype)
nodeid.NamespaceUri = nsu nodeid.NamespaceUri = nsu
nodeid.ServerIndex = srv nodeid.ServerIndex = srv
...@@ -504,7 +504,7 @@ class NodeId(FrozenClass): ...@@ -504,7 +504,7 @@ class NodeId(FrozenClass):
nid.NamespaceIndex = uatype_UInt16.unpack(data.read(2))[0] nid.NamespaceIndex = uatype_UInt16.unpack(data.read(2))[0]
nid.Identifier = Guid.from_binary(data) nid.Identifier = Guid.from_binary(data)
else: else:
raise UAError("Unknown NodeId encoding: " + str(nid.NodeIdType)) raise UaError("Unknown NodeId encoding: " + str(nid.NodeIdType))
if test_bit(encoding, 7): if test_bit(encoding, 7):
nid.NamespaceUri = unpack_string(data) nid.NamespaceUri = unpack_string(data)
...@@ -561,7 +561,7 @@ class QualifiedName(FrozenClass): ...@@ -561,7 +561,7 @@ class QualifiedName(FrozenClass):
def __init__(self, name="", namespaceidx=0): def __init__(self, name="", namespaceidx=0):
if not isinstance(namespaceidx, int): if not isinstance(namespaceidx, int):
raise UAError("namespaceidx must be an int") raise UaError("namespaceidx must be an int")
self.NamespaceIndex = namespaceidx self.NamespaceIndex = namespaceidx
self.Name = name self.Name = name
self._freeze = True self._freeze = True
...@@ -777,7 +777,7 @@ class VariantTypeCustom(object): ...@@ -777,7 +777,7 @@ class VariantTypeCustom(object):
self.name = "Custom" self.name = "Custom"
self.value = val self.value = val
if self.value > 0b00111111: if self.value > 0b00111111:
raise UAError("Cannot create VariantType. VariantType must be %s > x > %s", 0b111111, 25) raise UaError("Cannot create VariantType. VariantType must be %s > x > %s", 0b111111, 25)
def __str__(self): def __str__(self):
return "VariantType.Custom:{}".format(self.value) return "VariantType.Custom:{}".format(self.value)
...@@ -824,7 +824,7 @@ class Variant(FrozenClass): ...@@ -824,7 +824,7 @@ class Variant(FrozenClass):
def _guess_type(self, val): def _guess_type(self, val):
while isinstance(val, (list, tuple)): while isinstance(val, (list, tuple)):
if len(val) == 0: if len(val) == 0:
raise UAError("could not guess UA variable type") raise UaError("could not guess UA variable type")
val = val[0] val = val[0]
if val is None: if val is None:
return VariantType.Null return VariantType.Null
...@@ -847,7 +847,7 @@ class Variant(FrozenClass): ...@@ -847,7 +847,7 @@ class Variant(FrozenClass):
except AttributeError: except AttributeError:
return VariantType.ExtensionObject return VariantType.ExtensionObject
else: else:
raise UAError("Could not guess UA type of {} with type {}, specify UA type".format(val, type(val))) raise UaError("Could not guess UA type of {} with type {}, specify UA type".format(val, type(val)))
def __str__(self): def __str__(self):
return "Variant(val:{!s},type:{})".format(self.Value, self.VariantType) return "Variant(val:{!s},type:{})".format(self.Value, self.VariantType)
......
...@@ -135,7 +135,7 @@ class Unit(unittest.TestCase): ...@@ -135,7 +135,7 @@ class Unit(unittest.TestCase):
self.assertEqual(l, l2) self.assertEqual(l, l2)
def test_custom_variant(self): def test_custom_variant(self):
with self.assertRaises(ua.UAError): with self.assertRaises(ua.UaError):
v = ua.Variant(b"ljsdfljds", ua.VariantTypeCustom(89)) v = ua.Variant(b"ljsdfljds", ua.VariantTypeCustom(89))
v = ua.Variant(b"ljsdfljds", ua.VariantTypeCustom(61)) v = ua.Variant(b"ljsdfljds", ua.VariantTypeCustom(61))
v2 = ua.Variant.from_binary(ua.utils.Buffer(v.to_binary())) v2 = ua.Variant.from_binary(ua.utils.Buffer(v.to_binary()))
...@@ -464,11 +464,11 @@ class CommonTests(object): ...@@ -464,11 +464,11 @@ class CommonTests(object):
def test_subscribe_events_to_wrong_node(self): def test_subscribe_events_to_wrong_node(self):
sub = self.opc.create_subscription(100, sclt) sub = self.opc.create_subscription(100, sclt)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
handle = sub.subscribe_events(self.opc.get_node("i=85")) handle = sub.subscribe_events(self.opc.get_node("i=85"))
o = self.opc.get_objects_node() o = self.opc.get_objects_node()
v = o.add_variable(3, 'VariableNoEventNofierAttribute', 4) v = o.add_variable(3, 'VariableNoEventNofierAttribute', 4)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
handle = sub.subscribe_events(v) handle = sub.subscribe_events(v)
sub.delete() sub.delete()
...@@ -522,12 +522,12 @@ class CommonTests(object): ...@@ -522,12 +522,12 @@ class CommonTests(object):
def test_non_existing_path(self): def test_non_existing_path(self):
root = self.opc.get_root_node() root = self.opc.get_root_node()
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
server_time_node = root.get_child(['0:Objects', '0:Server', '0:nonexistingnode']) server_time_node = root.get_child(['0:Objects', '0:Server', '0:nonexistingnode'])
def test_bad_attribute(self): def test_bad_attribute(self):
root = self.opc.get_root_node() root = self.opc.get_root_node()
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
root.set_value(99) root.set_value(99)
def test_get_node_by_nodeid(self): def test_get_node_by_nodeid(self):
...@@ -677,7 +677,7 @@ class CommonTests(object): ...@@ -677,7 +677,7 @@ class CommonTests(object):
def test_add_exception(self): def test_add_exception(self):
objects = self.opc.get_objects_node() objects = self.opc.get_objects_node()
o = objects.add_object('ns=2;i=103;', '2:AddReadObject') o = objects.add_object('ns=2;i=103;', '2:AddReadObject')
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
o2 = objects.add_object('ns=2;i=103;', '2:AddReadObject') o2 = objects.add_object('ns=2;i=103;', '2:AddReadObject')
def test_negative_value(self): def test_negative_value(self):
...@@ -694,13 +694,13 @@ class CommonTests(object): ...@@ -694,13 +694,13 @@ class CommonTests(object):
def test_bad_node(self): def test_bad_node(self):
bad = self.opc.get_node(ua.NodeId(999, 999)) bad = self.opc.get_node(ua.NodeId(999, 999))
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
bad.get_browse_name() bad.get_browse_name()
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
bad.set_value(89) bad.set_value(89)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
bad.add_object(0, "0:myobj") bad.add_object(0, "0:myobj")
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
bad.get_child("0:myobj") bad.get_child("0:myobj")
def test_value(self): def test_value(self):
...@@ -759,7 +759,7 @@ class CommonTests(object): ...@@ -759,7 +759,7 @@ class CommonTests(object):
msclt = MySubHandler() msclt = MySubHandler()
o = self.opc.get_objects_node() o = self.opc.get_objects_node()
sub = self.opc.create_subscription(100, msclt) sub = self.opc.create_subscription(100, msclt)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
handle1 = sub.subscribe_data_change(o) # we can only subscribe to variables so this should fail handle1 = sub.subscribe_data_change(o) # we can only subscribe to variables so this should fail
sub.delete() sub.delete()
...@@ -830,13 +830,13 @@ class CommonTests(object): ...@@ -830,13 +830,13 @@ class CommonTests(object):
self.assertEqual(node, v1) self.assertEqual(node, v1)
self.assertEqual(val, [5]) self.assertEqual(val, [5])
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(999) # non existing handle sub.unsubscribe(999) # non existing handle
sub.unsubscribe(handle1) sub.unsubscribe(handle1)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # second try should fail sub.unsubscribe(handle1) # second try should fail
sub.delete() sub.delete()
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # sub does not exist anymore sub.unsubscribe(handle1) # sub does not exist anymore
def test_subscription_data_change(self): def test_subscription_data_change(self):
...@@ -870,13 +870,13 @@ class CommonTests(object): ...@@ -870,13 +870,13 @@ class CommonTests(object):
self.assertEqual(node, v1) self.assertEqual(node, v1)
self.assertEqual(val, [5]) self.assertEqual(val, [5])
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(999) # non existing handle sub.unsubscribe(999) # non existing handle
sub.unsubscribe(handle1) sub.unsubscribe(handle1)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # second try should fail sub.unsubscribe(handle1) # second try should fail
sub.delete() sub.delete()
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # sub does not exist anymore sub.unsubscribe(handle1) # sub does not exist anymore
...@@ -980,10 +980,10 @@ class CommonTests(object): ...@@ -980,10 +980,10 @@ class CommonTests(object):
m = o.get_child("2:ServerMethod") m = o.get_child("2:ServerMethod")
result = o.call_method("2:ServerMethod", 2.1) result = o.call_method("2:ServerMethod", 2.1)
self.assertEqual(result, 4.2) self.assertEqual(result, 4.2)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
# FIXME: we should raise a more precise exception # FIXME: we should raise a more precise exception
result = o.call_method("2:ServerMethod", 2.1, 89, 9) result = o.call_method("2:ServerMethod", 2.1, 89, 9)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
result = o.call_method(ua.NodeId(999), 2.1) # non existing method result = o.call_method(ua.NodeId(999), 2.1) # non existing method
def test_method_array(self): def test_method_array(self):
...@@ -1073,14 +1073,14 @@ class AdminTestClient(unittest.TestCase, CommonTests): ...@@ -1073,14 +1073,14 @@ class AdminTestClient(unittest.TestCase, CommonTests):
def test_service_fault(self): def test_service_fault(self):
request = ua.ReadRequest() request = ua.ReadRequest()
request.TypeId = ua.FourByteNodeId(999) # bad type! request.TypeId = ua.FourByteNodeId(999) # bad type!
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
self.clt.bclient._uasocket.send_request(request) self.clt.bclient._uasocket.send_request(request)
def test_objects_anonymous(self): def test_objects_anonymous(self):
objects = self.ro_clt.get_objects_node() objects = self.ro_clt.get_objects_node()
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
objects.set_attribute(ua.AttributeIds.WriteMask, ua.DataValue(999)) objects.set_attribute(ua.AttributeIds.WriteMask, ua.DataValue(999))
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
f = objects.add_folder(3, 'MyFolder') f = objects.add_folder(3, 'MyFolder')
def test_folder_anonymous(self): def test_folder_anonymous(self):
...@@ -1088,7 +1088,7 @@ class AdminTestClient(unittest.TestCase, CommonTests): ...@@ -1088,7 +1088,7 @@ class AdminTestClient(unittest.TestCase, CommonTests):
f = objects.add_folder(3, 'MyFolderRO') f = objects.add_folder(3, 'MyFolderRO')
f_ro = self.ro_clt.get_node(f.nodeid) f_ro = self.ro_clt.get_node(f.nodeid)
self.assertEqual(f, f_ro) self.assertEqual(f, f_ro)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
f2 = f_ro.add_folder(3, 'MyFolder2') f2 = f_ro.add_folder(3, 'MyFolder2')
def test_variable_anonymous(self): def test_variable_anonymous(self):
...@@ -1096,14 +1096,14 @@ class AdminTestClient(unittest.TestCase, CommonTests): ...@@ -1096,14 +1096,14 @@ class AdminTestClient(unittest.TestCase, CommonTests):
v = objects.add_variable(3, 'MyROVariable', 6) v = objects.add_variable(3, 'MyROVariable', 6)
v.set_value(4) #this should work v.set_value(4) #this should work
v_ro = self.ro_clt.get_node(v.nodeid) v_ro = self.ro_clt.get_node(v.nodeid)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
v_ro.set_value(2) v_ro.set_value(2)
self.assertEqual(v_ro.get_value(), 4) self.assertEqual(v_ro.get_value(), 4)
v.set_writable(True) v.set_writable(True)
v_ro.set_value(2) #now it should work v_ro.set_value(2) #now it should work
self.assertEqual(v_ro.get_value(), 2) self.assertEqual(v_ro.get_value(), 2)
v.set_writable(False) v.set_writable(False)
with self.assertRaises(ua.UAStatusCodeError): with self.assertRaises(ua.UaStatusCodeError):
v_ro.set_value(9) v_ro.set_value(9)
self.assertEqual(v_ro.get_value(), 2) self.assertEqual(v_ro.get_value(), 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment