Skip to content

Commit

Permalink
Updated Unit tests for python3
Browse files Browse the repository at this point in the history
Added different expected results for python3 (with version check)
for some WebsocketHandler error cases
  • Loading branch information
Bryan Robert Tester committed Apr 27, 2018
1 parent f1591fa commit 6d1e7c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
3 changes: 1 addition & 2 deletions malcolm/core/serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,4 @@ def lookup_subclass(cls, d):
if not subclass:
raise FieldError("'%s' not a valid typeid" % typeid)
else:
return subclass

return subclass
43 changes: 32 additions & 11 deletions tests/test_modules/test_web/test_system_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from malcolm.modules.builtin.blocks import proxy_block
from malcolm.modules.demo.blocks import hello_block, counter_block
from malcolm.modules.web.blocks import web_server_block, websocket_client_block
from sys import version_info


class TestSystemWSCommsServerOnly(unittest.TestCase):
Expand Down Expand Up @@ -65,11 +66,20 @@ def test_error_server_and_simple_client_badJSON(self):

self.server._loop.add_callback(self.send_message, "I am not JSON", convert_json=False)
resp = self.result.get(timeout=2)
assert resp == dict(
typeid="malcolm:core/Error:1.0",
id=-1,
message="ValueError: Error decoding JSON object (No JSON object could be decoded)"
)
if version_info[0] == 2:
assert resp == dict(
typeid="malcolm:core/Error:1.0",
id=-1,
message="ValueError: Error decoding JSON object (No JSON object could be decoded)"
)
elif version_info[0] == 3:
assert resp == dict(
typeid="malcolm:core/Error:1.0",
id=-1,
message="'ValueError: Error decoding JSON object (Expecting value: line 1 column 1 (char 0))"
)
else:
raise Exception("Got bad python version info")

def test_error_server_and_simple_client_no_id(self):
self.server._loop.add_callback(self.send_message,
Expand Down Expand Up @@ -117,12 +127,23 @@ def test_error_server_and_simple_client_no_type(self):
)
)
resp = self.result.get(timeout=2)
assert resp == dict(
typeid="malcolm:core/Error:1.0",
id=0,
message="FieldError: typeid field not present in dictionary " +
"( d.keys() = [u'path', u'id', u'parameters'] )"
)

if version_info[0] == 2:
assert resp == dict(
typeid="malcolm:core/Error:1.0",
id=0,
message="FieldError: typeid field not present in dictionary " +
"( d.keys() = [u'path', u'id', u'parameters'] )"
)
elif version_info[0] == 3:
assert resp == dict(
typeid="malcolm:core/Error:1.0",
id=0,
message="FieldError: typeid field not present in dictionary " +
"( d.keys() = odict_keys(['parameters', 'path', 'id']) )"
)
else:
raise Exception("Got bad python version info")

def test_error_server_and_simple_client_bad_path_controller(self):
self.server._loop.add_callback(self.send_message,
Expand Down

0 comments on commit 6d1e7c1

Please sign in to comment.