Skip to content

Commit

Permalink
Merge pull request #20 from norkator/more-tests
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
norkator authored Jul 3, 2021
2 parents 95a71fa + a72cc94 commit 43bccc4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/nx100_remote_control/module/MockResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
# noinspection SpellCheckingInspection
IOREAD = "b'0\\r\\n'"

# noinspection SpellCheckingInspection
RJDIR = ""

# noinspection SpellCheckingInspection
SETMJ = "b'0000\\r\\n'"


def get_mock_response(command):
if command.name == 'RALARM':
Expand Down Expand Up @@ -75,5 +81,9 @@ def get_mock_response(command):
return IOWRITE
elif command.name == 'IOREAD':
return IOREAD
elif command.name == 'RJDIR':
return RJDIR
elif command.name == 'SETMJ':
return SETMJ
else:
return '[E] no mock response for given command ' + command.name
66 changes: 65 additions & 1 deletion src/nx100_remote_control/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import nx100_remote_control
from nx100_remote_control.module import Commands
from nx100_remote_control.module import Commands, Utils
from nx100_remote_control.objects import MoveJ, MoveL, IO


class MyTestCase(unittest.TestCase):
Expand All @@ -14,6 +15,69 @@ def test_read_current_joint_coordinate_position(self):
position = Commands.read_current_joint_coordinate_position()
self.assertEqual(position, '45411,-59646,-55567,667,-1077,-1260,0,0,0,0,0,0')

def test_write_hold(self):
res = Commands.write_hold('1')
self.assertEqual(res.get_response(), '0000')

def test_write_reset(self):
res = Commands.write_reset()
self.assertEqual(res.get_response(), '0000')

def test_write_cancel(self):
res = Commands.write_cancel()
self.assertEqual(res.get_response(), '0000')

def test_write_servo_power(self):
res = Commands.write_servo_power('1')
self.assertEqual(res.get_response(), '0000')

def test_write_start_job(self):
res = Commands.write_start_job('test_job')
self.assertEqual(res.get_response(), '0000')

def test_read_io_signals(self):
io = IO.IO(4)
res = Commands.read_io_signals(io)
self.assertEqual(res.get_response(), '0')

def test_write_io_signals(self):
io = IO.IO(4)
res = Commands.write_io_signals(io)
self.assertEqual(res.get_response(), '0')

def test_read_all_job_names(self):
res = Commands.read_all_job_names()
self.assertEqual(res.get_response(), '')

def test_write_master_job(self):
res = Commands.write_master_job('test_job')
self.assertEqual(res.get_response(), '0000')

def test_linear_motion_move(self):
move_l = MoveL.MoveL(
MoveL.MoveL.motion_speed_selection_posture_speed,
5,
MoveL.MoveL.coordinate_specification_base_coordinate,
352.769, 202.779, 120.658,
-1.34, 35.78, 27.84,
Utils.binary_to_decimal(0x00000001),
0, 0, 0, 0, 0, 0, 0
)
res = Commands.write_linear_move(move_l=move_l)
self.assertEqual(res.get_response(), '0000')

def test_joint_motion_move(self):
move_j = MoveJ.MoveJ(
25, # speed %
MoveJ.MoveJ.coordinate_specification_base_coordinate,
352.769, 202.779, 120.658,
-1.34, 35.78, 27.84,
Utils.binary_to_decimal(0x00000001),
0, 0, 0, 0, 0, 0, 0
)
res = Commands.write_joint_motion_move(move_j=move_j)
self.assertEqual(res.get_response(), '0000')


if __name__ == '__main__':
unittest.main()

0 comments on commit 43bccc4

Please sign in to comment.