|
8 | 8 |
|
9 | 9 | from pymycobot import MyCobotCommandGenerator |
10 | 10 |
|
11 | | -mg: MyCobotCommandGenerator |
12 | | - |
13 | 11 |
|
14 | 12 | @pytest.fixture(scope="module") |
15 | | -def setup(): |
16 | | - global mg |
| 13 | +def mcg(): |
17 | 14 | print("") |
18 | 15 | DEBUG = False |
19 | 16 | mg = MyCobotCommandGenerator(debug=DEBUG) |
20 | 17 | print("") |
| 18 | + return mg |
21 | 19 |
|
| 20 | +def test_flatten1(mcg): |
| 21 | + assert mcg._flatten([1,2,3,4,5,6]) == [1,2,3,4,5,6] |
22 | 22 |
|
23 | | -def test_generator(setup): |
24 | | - print("") |
25 | | - pprint(mg.send_coords([-160, 160, 160, 0, 0, 0], 7, 2)) |
26 | | - print("") |
27 | | - pprint(mg.version()) |
28 | | - print("") |
29 | | - pprint(mg.power_on()) |
30 | | - print("") |
31 | | - pprint(mg.power_off()) |
32 | | - print("") |
33 | | - pprint(mg.release_all_servos()) |
34 | | - print("") |
35 | | - pprint(mg.is_controller_connected()) |
36 | | - print("") |
37 | | - pprint(mg.get_angles()) |
38 | | - print("") |
39 | | - pprint(mg.send_angle(1, 0, 10)) |
40 | | - print("") |
41 | | - pprint(mg.send_angles([0, 0, 0, 0, 0, 0], 5)) |
42 | | - print("") |
43 | | - pprint(mg.get_coords()) |
44 | | - print("") |
45 | | - pprint(mg.send_coord(1, 110.5, 8)) |
46 | | - print("pause") |
47 | | - pprint(mg.pause()) |
48 | | - print("is_paused") |
49 | | - pprint(mg.is_paused()) |
50 | | - print("resume") |
51 | | - pprint(mg.resume()) |
52 | | - print("stop") |
53 | | - pprint(mg.stop()) |
54 | | - print("is_in_position") |
55 | | - pprint(mg.is_in_position([0, 0, 0, 0, 0, 0], 0)) |
56 | | - print("") |
57 | | - pprint(mg.is_moving()) |
58 | | - print("") |
59 | | - pprint(mg.jog_angle(1, 0, 1)) |
60 | | - print("") |
61 | | - pprint(mg.jog_coord(2, 1, 3)) |
62 | | - print("") |
63 | | - pprint(mg.jog_stop()) |
64 | | - print("set_encoder") |
65 | | - pprint(mg.set_encoder(1, 1024)) |
66 | | - print("get_encoder") |
67 | | - pprint(mg.get_encoder(2)) |
68 | | - print("get_speed") |
69 | | - pprint(mg.get_speed()) |
70 | | - print("set_speed") |
71 | | - pprint(mg.set_speed(100)) |
72 | | - print("get_joint_min_angle") |
73 | | - pprint(mg.get_joint_min_angle(1)) |
74 | | - print("get_joint_max_angle") |
75 | | - pprint(mg.get_joint_max_angle(2)) |
76 | | - print("is_servo_enable") |
77 | | - pprint(mg.is_servo_enable(6)) |
78 | | - print("is_all_servo_enable") |
79 | | - pprint(mg.is_all_servo_enable()) |
80 | | - print("set_servo_data") |
81 | | - pprint(mg.set_servo_data(0, 1, 2)) |
82 | | - print("get_servo_data") |
83 | | - pprint(mg.get_servo_data(1, 2)) |
84 | | - print("set_servo_calibration") |
85 | | - pprint(mg.set_servo_calibration(1)) |
86 | | - print("release_servo") |
87 | | - pprint(mg.release_servo(1)) |
88 | | - print("focus_servo") |
89 | | - pprint(mg.focus_servo(1)) |
90 | | - print("set_color") |
91 | | - pprint(mg.set_color(255, 255, 0)) |
92 | | - print("set_pin_mode") |
93 | | - pprint(mg.set_pin_mode(1, 0)) |
94 | | - print("set_digital_output") |
95 | | - pprint(mg.set_digital_output(0, 1)) |
96 | | - pprint(mg) |
| 23 | +def test_flatten2(mcg): |
| 24 | + assert mcg._flatten([1,2,3,4,[],5]) == [1,2,3,4,5] |
| 25 | + |
| 26 | +def test_flatten3(mcg): |
| 27 | + assert mcg._flatten([1,2,3,4,[5,6],7]) == [1,2,3,4,5,6,7] |
| 28 | + |
| 29 | +def test_encode_int16(mcg): |
| 30 | + assert mcg._encode_int16([0, 1]) == sum([mcg._encode_int16(0), mcg._encode_int16(1)], []) |
| 31 | + |
| 32 | +def test_process_data_command1(mcg): |
| 33 | + assert mcg._process_data_command(()) == [] |
| 34 | + |
| 35 | +def test_process_data_command2(mcg): |
| 36 | + assert mcg._process_data_command((1, 2, 3)) == [1, 2, 3] |
| 37 | + |
| 38 | +def test_process_data_command3(mcg): |
| 39 | + assert mcg._process_data_command((1, 2, [1, 2])) == mcg._flatten([1, 2, mcg._encode_int16([1, 2])]) |
| 40 | + |
| 41 | +def test_version(mcg): |
| 42 | + assert mcg.version() == ([0xFE, 0xFE, 2, 0x00, 0xFA], True) |
| 43 | + |
| 44 | +def test_power_on(mcg): |
| 45 | + assert mcg.power_on() == ([0xFE, 0xFE, 2, 0x10, 0xFA], False) |
| 46 | + |
| 47 | +def test_power_off(mcg): |
| 48 | + assert mcg.power_off() == ([0xFE, 0xFE, 2, 0x11, 0xFA], False) |
| 49 | + |
| 50 | +def test_release_all_servos(mcg): |
| 51 | + assert mcg.release_all_servos() == ([0xFE, 0xFE, 2, 0x13, 0xFA], False) |
| 52 | + |
| 53 | +def test_is_controller_connected(mcg): |
| 54 | + assert mcg.is_controller_connected() == ([0xFE, 0xFE, 2, 0x14, 0xFA], True) |
| 55 | + |
| 56 | +def test_get_angles(mcg): |
| 57 | + assert mcg.get_angles() == ([0xFE, 0xFE, 2, 0x20, 0xFA], True) |
| 58 | + |
| 59 | +def test_get_coords(mcg): |
| 60 | + assert mcg.get_coords() == ([0xFE, 0xFE, 2, 0x23, 0xFA], True) |
| 61 | + |
| 62 | +def test_is_in_position(mcg): |
| 63 | + assert mcg.is_in_position([0, 0, 0, 0, 0, 0], 0) == (mcg._flatten([0xFE, 0xFE, 15, 0x2A, mcg._flatten([mcg._encode_int16([0, 0, 0, 0, 0, 0]), 0]), 0xFA]), True) |
| 64 | + |
| 65 | +def test_pause(mcg): |
| 66 | + assert mcg.pause() == ([0xFE, 0xFE, 2, 0x26, 0xFA], False) |
| 67 | + |
| 68 | +def test_resume(mcg): |
| 69 | + assert mcg.resume() == ([0xFE, 0xFE, 2, 0x28, 0xFA], False) |
| 70 | + |
| 71 | +def test_stop(mcg): |
| 72 | + assert mcg.stop() == ([0xFE, 0xFE, 2, 0x29, 0xFA], False) |
| 73 | + |
| 74 | +def test_set_pin_mode(mcg): |
| 75 | + assert mcg.set_pin_mode(1, 0) == ([0xFE, 0xFE, 4, 0x60, 1, 0, 0xFA], False) |
| 76 | + |
| 77 | +def test_set_digital_output(mcg): |
| 78 | + assert mcg.set_digital_output(0, 1) == ([0xFE, 0xFE, 4, 0x61, 0, 1, 0xFA], False) |
0 commit comments