00001 import unittest 00002 import opcua.ua.uaerrors as uaerrors 00003 from opcua.ua.uaerrors import UaStatusCodeError 00004 00005 class TestUaErrors(unittest.TestCase): 00006 status_code_bad_internal = 0x80020000 00007 status_code_unknown = "Definitely Not A Status Code" 00008 00009 def setUp(self): 00010 self.direct = uaerrors.BadInternalError() 00011 self.indirect = UaStatusCodeError(self.status_code_bad_internal) 00012 self.unknown = UaStatusCodeError(self.status_code_unknown) 00013 00014 def test_subclass_selection(self): 00015 self.assertIs(type(self.direct), uaerrors.BadInternalError) 00016 self.assertIs(type(self.indirect), uaerrors.BadInternalError) 00017 self.assertIs(type(self.unknown), UaStatusCodeError) 00018 00019 def test_code(self): 00020 self.assertEqual(self.direct.code, self.status_code_bad_internal) 00021 self.assertEqual(self.indirect.code, self.status_code_bad_internal) 00022 self.assertEqual(self.unknown.code, self.status_code_unknown) 00023 00024 def test_string_repr(self): 00025 self.assertIn("BadInternal", str(self.direct)) 00026 self.assertIn("BadInternal", str(self.indirect))