How to use assert_called_with method in autotest

Best Python code snippet using autotest_python

test_position_hl_commander.py

Source:test_position_hl_commander.py Github

copy

Full Screen

...97 # Test98 self.sut.take_off(height=0.4, velocity=0.6)99 # Assert100 duration = 0.4 / 0.6101 self.commander_mock.takeoff.assert_called_with(0.4, duration)102 sleep_mock.assert_called_with(duration)103 def test_that_it_goes_up_to_default_height(104 self, sleep_mock):105 # Fixture106 sut = PositionHlCommander(self.cf_mock, default_height=0.4)107 # Test108 sut.take_off(velocity=0.6)109 # Assert110 duration = 0.4 / 0.6111 self.commander_mock.takeoff.assert_called_with(0.4, duration)112 sleep_mock.assert_called_with(duration)113 def test_that_it_goes_down_on_landing(114 self, sleep_mock):115 # Fixture116 self.sut.take_off(height=0.4)117 # Test118 self.sut.land(velocity=0.6)119 # Assert120 duration = 0.4 / 0.6121 self.commander_mock.land.assert_called_with(0.0, duration)122 sleep_mock.assert_called_with(duration)123 def test_that_it_takes_off_and_lands_as_context_manager(124 self, sleep_mock):125 # Fixture126 # Test127 with self.sut:128 pass129 # Assert130 duration1 = 0.5 / 0.5131 duration2 = 0.5 / 0.5132 self.commander_mock.takeoff.assert_called_with(0.5, duration1)133 self.commander_mock.land.assert_called_with(0.0, duration2)134 sleep_mock.assert_called_with(duration1)135 sleep_mock.assert_called_with(duration2)136 def test_that_it_returns_current_position(137 self, sleep_mock):138 # Fixture139 self.sut.take_off(height=0.4, velocity=0.6)140 # Test141 actual = self.sut.get_position()142 # Assert143 self.assertEqual(actual, (0.0, 0.0, 0.4))144 def test_that_it_goes_to_position(145 self, sleep_mock):146 # Fixture147 self.sut.take_off()148 inital_pos = self.sut.get_position()149 # Test150 self.sut.go_to(1.0, 2.0, 3.0, 4.0)151 # Assert152 distance = self._distance(inital_pos, (1.0, 2.0, 3.0))153 duration = distance / 4.0154 self.commander_mock.go_to.assert_called_with(155 1.0, 2.0, 3.0, 0.0, duration)156 sleep_mock.assert_called_with(duration)157 def test_that_it_does_not_send_goto_to_same_position(158 self, sleep_mock):159 # Fixture160 self.sut.take_off()161 inital_pos = self.sut.get_position()162 # Test163 self.sut.go_to(inital_pos[0], inital_pos[1], inital_pos[2])164 # Assert165 self.commander_mock.go_to.assert_not_called()166 def test_that_it_moves_distance(167 self, sleep_mock):168 # Fixture169 self.sut.take_off()170 inital_pos = self.sut.get_position()171 # Test172 self.sut.move_distance(1.0, 2.0, 3.0, 4.0)173 # Assert174 distance = self._distance((0.0, 0.0, 0.0), (1.0, 2.0, 3.0))175 duration = distance / 4.0176 final_pos = (177 inital_pos[0] + 1.0,178 inital_pos[1] + 2.0,179 inital_pos[2] + 3.0)180 self.commander_mock.go_to.assert_called_with(181 final_pos[0], final_pos[1], final_pos[2], 0.0, duration)182 sleep_mock.assert_called_with(duration)183 def test_that_it_goes_forward(184 self, sleep_mock):185 # Fixture186 self.sut.take_off()187 inital_pos = self.sut.get_position()188 # Test189 self.sut.forward(1.0, 2.0)190 # Assert191 duration = 1.0 / 2.0192 final_pos = (193 inital_pos[0] + 1.0,194 inital_pos[1],195 inital_pos[2])196 self.commander_mock.go_to.assert_called_with(197 final_pos[0], final_pos[1], final_pos[2], 0.0, duration)198 sleep_mock.assert_called_with(duration)199 def test_that_it_goes_back(200 self, sleep_mock):201 # Fixture202 self.sut.take_off()203 inital_pos = self.sut.get_position()204 # Test205 self.sut.back(1.0, 2.0)206 # Assert207 duration = 1.0 / 2.0208 final_pos = (209 inital_pos[0] - 1.0,210 inital_pos[1],211 inital_pos[2])212 self.commander_mock.go_to.assert_called_with(213 final_pos[0], final_pos[1], final_pos[2], 0.0, duration)214 sleep_mock.assert_called_with(duration)215 def test_that_it_goes_left(216 self, sleep_mock):217 # Fixture218 self.sut.take_off()219 inital_pos = self.sut.get_position()220 # Test221 self.sut.left(1.0, 2.0)222 # Assert223 duration = 1.0 / 2.0224 final_pos = (225 inital_pos[0],226 inital_pos[1] + 1.0,227 inital_pos[2])228 self.commander_mock.go_to.assert_called_with(229 final_pos[0], final_pos[1], final_pos[2], 0.0, duration)230 sleep_mock.assert_called_with(duration)231 def test_that_it_goes_right(232 self, sleep_mock):233 # Fixture234 self.sut.take_off()235 inital_pos = self.sut.get_position()236 # Test237 self.sut.right(1.0, 2.0)238 # Assert239 duration = 1.0 / 2.0240 final_pos = (241 inital_pos[0],242 inital_pos[1] - 1,243 inital_pos[2])244 self.commander_mock.go_to.assert_called_with(245 final_pos[0], final_pos[1], final_pos[2], 0, duration)246 sleep_mock.assert_called_with(duration)247 def test_that_it_goes_up(248 self, sleep_mock):249 # Fixture250 self.sut.take_off()251 inital_pos = self.sut.get_position()252 # Test253 self.sut.up(1.0, 2.0)254 # Assert255 duration = 1.0 / 2.0256 final_pos = (257 inital_pos[0],258 inital_pos[1],259 inital_pos[2] + 1)260 self.commander_mock.go_to.assert_called_with(261 final_pos[0], final_pos[1], final_pos[2], 0, duration)262 sleep_mock.assert_called_with(duration)263 def test_that_it_goes_down(264 self, sleep_mock):265 # Fixture266 self.sut.take_off()267 inital_pos = self.sut.get_position()268 # Test269 self.sut.down(1.0, 2.0)270 # Assert271 duration = 1.0 / 2.0272 final_pos = (273 inital_pos[0],274 inital_pos[1],275 inital_pos[2] - 1)276 self.commander_mock.go_to.assert_called_with(277 final_pos[0], final_pos[1], final_pos[2], 0, duration)278 sleep_mock.assert_called_with(duration)279 def test_that_default_velocity_is_used(280 self, sleep_mock):281 # Fixture282 self.sut.take_off()283 inital_pos = self.sut.get_position()284 self.sut.set_default_velocity(7)285 # Test286 self.sut.go_to(1.0, 2.0, 3.0)287 # Assert288 distance = self._distance(inital_pos, (1.0, 2.0, 3.0))289 duration = distance / 7.0290 self.commander_mock.go_to.assert_called_with(291 1.0, 2.0, 3.0, 0.0, duration)292 sleep_mock.assert_called_with(duration)293 def test_that_default_height_is_used(294 self, sleep_mock):295 # Fixture296 self.sut.take_off()297 inital_pos = self.sut.get_position()298 self.sut.set_default_velocity(7.0)299 self.sut.set_default_height(5.0)300 # Test301 self.sut.go_to(1.0, 2.0)302 # Assert303 distance = self._distance(inital_pos, (1.0, 2.0, 5.0))304 duration = distance / 7.0305 self.commander_mock.go_to.assert_called_with(306 1.0, 2.0, 5.0, 0.0, duration)307 sleep_mock.assert_called_with(duration)308 ######################################################################309 def _distance(self, p1, p2):310 dx = p1[0] - p2[0]311 dy = p1[1] - p2[1]312 dz = p1[2] - p2[2]313 return math.sqrt(dx * dx + dy * dy + dz * dz)314if __name__ == '__main__':...

Full Screen

Full Screen

test_GPIO.py

Source:test_GPIO.py Github

copy

Full Screen

...45 def test_setup(self):46 rpi_gpio = Mock()47 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)48 adapter.setup(1, GPIO.OUT)49 rpi_gpio.setup.assert_called_with(1, rpi_gpio.OUT, pull_up_down=rpi_gpio.PUD_OFF)50 adapter.setup(1, GPIO.IN)51 rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_OFF)52 adapter.setup(1, GPIO.IN, GPIO.PUD_DOWN)53 rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_DOWN)54 adapter.setup(1, GPIO.IN, GPIO.PUD_UP)55 rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_UP)56 def test_output(self):57 rpi_gpio = Mock()58 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)59 adapter.output(1, True)60 rpi_gpio.output.assert_called_with(1, True)61 adapter.output(1, False)62 rpi_gpio.output.assert_called_with(1, False)63 def test_input(self):64 rpi_gpio = Mock()65 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)66 rpi_gpio.input = Mock(return_value=True)67 val = adapter.input(1)68 self.assertTrue(val)69 rpi_gpio.input.assert_called_with(1)70 def test_setmode(self):71 rpi_gpio = Mock()72 adapter = GPIO.RPiGPIOAdapter(rpi_gpio, mode=rpi_gpio.BCM)73 rpi_gpio.setmode.assert_called_with(rpi_gpio.BCM)74 adapter = GPIO.RPiGPIOAdapter(rpi_gpio, mode=rpi_gpio.BOARD)75 rpi_gpio.setmode.assert_called_with(rpi_gpio.BOARD)76 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)77 rpi_gpio.setmode.assert_called_with(rpi_gpio.BCM)78 def test_add_event_detect(self):79 rpi_gpio = Mock()80 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)81 adapter.add_event_detect(1, GPIO.RISING)82 rpi_gpio.add_event_detect.assert_called_with(1, rpi_gpio.RISING)83 def test_remove_event_detect(self):84 rpi_gpio = Mock()85 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)86 adapter.remove_event_detect(1)87 rpi_gpio.remove_event_detect.assert_called_with(1)88 def test_add_event_callback(self):89 rpi_gpio = Mock()90 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)91 adapter.add_event_callback(1, callback=self.test_add_event_callback)92 rpi_gpio.add_event_callback.assert_called_with(1, self.test_add_event_callback)93 def test_event_detected(self):94 rpi_gpio = Mock()95 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)96 adapter.event_detected(1)97 rpi_gpio.event_detected.assert_called_with(1)98 def test_wait_for_edge(self):99 rpi_gpio = Mock()100 adapter = GPIO.RPiGPIOAdapter(rpi_gpio)101 adapter.wait_for_edge(1, GPIO.FALLING)102 rpi_gpio.wait_for_edge.assert_called_with(1, rpi_gpio.FALLING)103 def test_cleanup(self):104 rpi_gpio = Mock()105 adapter = GPIO.AdafruitBBIOAdapter(rpi_gpio)106 adapter.cleanup()107 rpi_gpio.cleanup.assert_called()108 def test_cleanup_pin(self):109 rpi_gpio = Mock()110 adapter = GPIO.AdafruitBBIOAdapter(rpi_gpio)111 adapter.cleanup(1)112 rpi_gpio.cleanup.assert_called_with(1)113class TestAdafruitBBIOAdapter(unittest.TestCase):114 def test_setup(self):115 bbio_gpio = Mock()116 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)117 adapter.setup(1, GPIO.OUT)118 bbio_gpio.setup.assert_called_with(1, bbio_gpio.OUT, pull_up_down=bbio_gpio.PUD_OFF)119 adapter.setup(1, GPIO.IN)120 bbio_gpio.setup.assert_called_with(1, bbio_gpio.IN, pull_up_down=bbio_gpio.PUD_OFF)121 adapter.setup(1, GPIO.IN, GPIO.PUD_DOWN)122 bbio_gpio.setup.assert_called_with(1, bbio_gpio.IN, pull_up_down=bbio_gpio.PUD_DOWN)123 adapter.setup(1, GPIO.IN, GPIO.PUD_UP)124 bbio_gpio.setup.assert_called_with(1, bbio_gpio.IN, pull_up_down=bbio_gpio.PUD_UP)125 def test_output(self):126 bbio_gpio = Mock()127 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)128 adapter.output(1, True)129 bbio_gpio.output.assert_called_with(1, True)130 adapter.output(1, False)131 bbio_gpio.output.assert_called_with(1, False)132 def test_input(self):133 bbio_gpio = Mock()134 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)135 bbio_gpio.input = Mock(return_value=True)136 val = adapter.input(1)137 self.assertTrue(val)138 bbio_gpio.input.assert_called_with(1)139 def test_add_event_detect(self):140 bbio_gpio = Mock()141 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)142 adapter.add_event_detect(1, GPIO.RISING)143 bbio_gpio.add_event_detect.assert_called_with(1, bbio_gpio.RISING)144 def test_add_event_detect(self):145 bbio_gpio = Mock()146 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)147 adapter.add_event_detect(1, GPIO.RISING)148 bbio_gpio.add_event_detect.assert_called_with(1, bbio_gpio.RISING)149 def test_remove_event_detect(self):150 bbio_gpio = Mock()151 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)152 adapter.remove_event_detect(1)153 bbio_gpio.remove_event_detect.assert_called_with(1)154 def test_add_event_callback(self):155 bbio_gpio = Mock()156 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)157 adapter.add_event_callback(1, callback=self.test_add_event_callback)158 bbio_gpio.add_event_callback.assert_called_with(1, self.test_add_event_callback)159 def test_event_detected(self):160 bbio_gpio = Mock()161 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)162 adapter.event_detected(1)163 bbio_gpio.event_detected.assert_called_with(1)164 def test_wait_for_edge(self):165 bbio_gpio = Mock()166 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)167 adapter.wait_for_edge(1, GPIO.FALLING)168 bbio_gpio.wait_for_edge.assert_called_with(1, bbio_gpio.FALLING)169 def test_cleanup(self):170 bbio_gpio = Mock()171 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)172 adapter.cleanup()173 bbio_gpio.cleanup.assert_called()174 def test_cleanup_pin(self):175 bbio_gpio = Mock()176 adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)177 adapter.cleanup(1)178 bbio_gpio.cleanup.assert_called_with(1)179class TestGetPlatformGPIO(unittest.TestCase):180 @patch.dict('sys.modules', {'RPi': Mock(), 'RPi.GPIO': Mock()})181 @patch('Adafruit_GPIO.Platform.platform_detect', Mock(return_value=Platform.RASPBERRY_PI))182 def test_raspberrypi(self):183 gpio = GPIO.get_platform_gpio()184 self.assertIsInstance(gpio, GPIO.RPiGPIOAdapter)185 @patch.dict('sys.modules', {'Adafruit_BBIO': Mock(), 'Adafruit_BBIO.GPIO': Mock()})186 @patch('Adafruit_GPIO.Platform.platform_detect', Mock(return_value=Platform.BEAGLEBONE_BLACK))187 def test_beagleboneblack(self):188 gpio = GPIO.get_platform_gpio()189 self.assertIsInstance(gpio, GPIO.AdafruitBBIOAdapter)190 @patch('Adafruit_GPIO.Platform.platform_detect', Mock(return_value=Platform.UNKNOWN))191 def test_unknown(self):192 self.assertRaises(RuntimeError, GPIO.get_platform_gpio)

Full Screen

Full Screen

test_llcp_socket.py

Source:test_llcp_socket.py Github

copy

Full Screen

...24 return sock25def test_resolve(sock):26 sock.llc.resolve.return_value = 'result'27 assert sock.resolve('urn:nfc:sn:svc') == 'result'28 sock.llc.resolve.assert_called_with('urn:nfc:sn:svc')29 assert sock.resolve(name='urn:nfc:sn:svc') == 'result'30 sock.llc.resolve.assert_called_with('urn:nfc:sn:svc')31def test_setsockopt(sock):32 sock.llc.getsockopt.return_value = 'result'33 sock.setsockopt('option', 'value')34 sock.llc.setsockopt.assert_called_with(sock._tco, 'option', 'value')35 sock.setsockopt(option='option', value='value')36 sock.llc.setsockopt.assert_called_with(sock._tco, 'option', 'value')37def test_getsockopt(sock):38 sock.llc.getsockopt.return_value = 'result'39 assert sock.getsockopt('option') == 'result'40 sock.llc.getsockopt.assert_called_with(sock._tco, 'option')41 assert sock.getsockopt(option='option') == 'result'42 sock.llc.getsockopt.assert_called_with(sock._tco, 'option')43def test_bind(sock):44 sock.llc.bind.return_value = 'result'45 assert sock.bind('address') == 'result'46 sock.llc.bind.assert_called_with(sock._tco, 'address')47 assert sock.bind(address='address') == 'result'48 sock.llc.bind.assert_called_with(sock._tco, 'address')49def test_connect(sock):50 sock.llc.connect.return_value = 'result'51 assert sock.connect('address') == 'result'52 sock.llc.connect.assert_called_with(sock._tco, 'address')53 assert sock.connect(address='address') == 'result'54 sock.llc.connect.assert_called_with(sock._tco, 'address')55def test_listen(sock):56 sock.llc.listen.return_value = 'result'57 assert sock.listen('backlog') == 'result'58 sock.llc.listen.assert_called_with(sock._tco, 'backlog')59 assert sock.listen(backlog='backlog') == 'result'60 sock.llc.listen.assert_called_with(sock._tco, 'backlog')61def test_accept(sock):62 sock.llc.accept.return_value = 'tco'63 assert isinstance(sock.accept(), nfc.llcp.socket.Socket)64 sock.llc.accept.assert_called_with(sock._tco)65def test_send(sock):66 sock.llc.send.return_value = 'result'67 assert sock.send('data') == 'result'68 sock.llc.send.assert_called_with(sock._tco, 'data', 0)69 assert sock.send('data', 'flags') == 'result'70 sock.llc.send.assert_called_with(sock._tco, 'data', 'flags')71 assert sock.send(data='data', flags='flags') == 'result'72 sock.llc.send.assert_called_with(sock._tco, 'data', 'flags')73def test_sendto(sock):74 sock.llc.sendto.return_value = 'result'75 assert sock.sendto('data', 'addr') == 'result'76 sock.llc.sendto.assert_called_with(sock._tco, 'data', 'addr', 0)77 assert sock.sendto('data', 'addr', 'flags') == 'result'78 sock.llc.sendto.assert_called_with(sock._tco, 'data', 'addr', 'flags')79 assert sock.sendto(data='data', addr='addr', flags='flags') == 'result'80 sock.llc.sendto.assert_called_with(sock._tco, 'data', 'addr', 'flags')81def test_recv(sock):82 sock.llc.recv.return_value = 'data'83 assert sock.recv() == 'data'84 sock.llc.recv.assert_called_with(sock._tco)85def test_recvfrom(sock):86 sock.llc.recvfrom.return_value = ('data', 'addr')87 assert sock.recvfrom() == ('data', 'addr')88 sock.llc.recvfrom.assert_called_with(sock._tco)89def test_poll(sock):90 sock.llc.poll.return_value = 'result'91 assert sock.poll('event') == 'result'92 sock.llc.poll.assert_called_with(sock._tco, 'event', None)93 assert sock.poll('event', 'timeout') == 'result'94 sock.llc.poll.assert_called_with(sock._tco, 'event', 'timeout')95 assert sock.poll(event='event', timeout='timeout') == 'result'96 sock.llc.poll.assert_called_with(sock._tco, 'event', 'timeout')97def test_getsockname(sock):98 sock.llc.getsockname.return_value = 'sockname'99 assert sock.getsockname() == 'sockname'100 sock.llc.getsockname.assert_called_with(sock._tco)101def test_getpeername(sock):102 sock.llc.getpeername.return_value = 'peername'103 assert sock.getpeername() == 'peername'104 sock.llc.getpeername.assert_called_with(sock._tco)105def test_close(sock):106 sock.llc.close.return_value = 'closed'107 assert sock.close() == 'closed'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful