How to use assert_has_calls method in autotest

Best Python code snippet using autotest_python

test_xiaomi_miio.py

Source:test_xiaomi_miio.py Github

copy

Full Screen

...145 assert state.attributes.get(ATTR_CLEANING_TOTAL_TIME) == 695146 # Call services147 yield from hass.services.async_call(148 DOMAIN, SERVICE_TURN_ON, blocking=True)149 mock_mirobo_is_off.assert_has_calls(150 [mock.call.Vacuum.start()], any_order=True)151 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)152 mock_mirobo_is_off.reset_mock()153 yield from hass.services.async_call(154 DOMAIN, SERVICE_TURN_OFF, blocking=True)155 mock_mirobo_is_off.assert_has_calls(156 [mock.call.Vacuum().home()], any_order=True)157 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)158 mock_mirobo_is_off.reset_mock()159 yield from hass.services.async_call(160 DOMAIN, SERVICE_TOGGLE, blocking=True)161 mock_mirobo_is_off.assert_has_calls(162 [mock.call.Vacuum().start()], any_order=True)163 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)164 mock_mirobo_is_off.reset_mock()165 yield from hass.services.async_call(166 DOMAIN, SERVICE_STOP, blocking=True)167 mock_mirobo_is_off.assert_has_calls(168 [mock.call.Vacuum().stop()], any_order=True)169 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)170 mock_mirobo_is_off.reset_mock()171 yield from hass.services.async_call(172 DOMAIN, SERVICE_START_PAUSE, blocking=True)173 mock_mirobo_is_off.assert_has_calls(174 [mock.call.Vacuum().pause()], any_order=True)175 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)176 mock_mirobo_is_off.reset_mock()177 yield from hass.services.async_call(178 DOMAIN, SERVICE_RETURN_TO_BASE, blocking=True)179 mock_mirobo_is_off.assert_has_calls(180 [mock.call.Vacuum().home()], any_order=True)181 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)182 mock_mirobo_is_off.reset_mock()183 yield from hass.services.async_call(184 DOMAIN, SERVICE_LOCATE, blocking=True)185 mock_mirobo_is_off.assert_has_calls(186 [mock.call.Vacuum().find()], any_order=True)187 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)188 mock_mirobo_is_off.reset_mock()189 yield from hass.services.async_call(190 DOMAIN, SERVICE_CLEAN_SPOT, {}, blocking=True)191 mock_mirobo_is_off.assert_has_calls(192 [mock.call.Vacuum().spot()], any_order=True)193 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)194 mock_mirobo_is_off.reset_mock()195 # Set speed service:196 yield from hass.services.async_call(197 DOMAIN, SERVICE_SET_FAN_SPEED, {"fan_speed": 60}, blocking=True)198 mock_mirobo_is_off.assert_has_calls(199 [mock.call.Vacuum().set_fan_speed(60)], any_order=True)200 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)201 mock_mirobo_is_off.reset_mock()202 yield from hass.services.async_call(203 DOMAIN, SERVICE_SET_FAN_SPEED, {"fan_speed": "turbo"}, blocking=True)204 mock_mirobo_is_off.assert_has_calls(205 [mock.call.Vacuum().set_fan_speed(77)], any_order=True)206 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)207 mock_mirobo_is_off.reset_mock()208 assert 'ERROR' not in caplog.text209 yield from hass.services.async_call(210 DOMAIN, SERVICE_SET_FAN_SPEED, {"fan_speed": "invent"}, blocking=True)211 assert 'ERROR' in caplog.text212 yield from hass.services.async_call(213 DOMAIN, SERVICE_SEND_COMMAND,214 {"command": "raw"}, blocking=True)215 mock_mirobo_is_off.assert_has_calls(216 [mock.call.Vacuum().raw_command('raw', None)], any_order=True)217 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)218 mock_mirobo_is_off.reset_mock()219 yield from hass.services.async_call(220 DOMAIN, SERVICE_SEND_COMMAND,221 {"command": "raw", "params": {"k1": 2}}, blocking=True)222 mock_mirobo_is_off.assert_has_calls(223 [mock.call.Vacuum().raw_command('raw', {'k1': 2})], any_order=True)224 mock_mirobo_is_off.assert_has_calls(status_calls, any_order=True)225 mock_mirobo_is_off.reset_mock()226@asyncio.coroutine227@pytest.mark.skip(reason="Fails")228def test_xiaomi_specific_services(hass, caplog, mock_mirobo_is_on):229 """Test vacuum supported features."""230 entity_name = 'test_vacuum_cleaner_2'231 entity_id = '{}.{}'.format(DOMAIN, entity_name)232 yield from async_setup_component(233 hass, DOMAIN,234 {DOMAIN: {CONF_PLATFORM: PLATFORM,235 CONF_HOST: '192.168.1.100',236 CONF_NAME: entity_name,237 CONF_TOKEN: '12345678901234567890123456789012'}})238 assert 'Initializing with host 192.168.1.100 (token 12345' in caplog.text239 # Check state attributes240 state = hass.states.get(entity_id)241 assert state.state == STATE_ON242 assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 2047243 assert state.attributes.get(ATTR_DO_NOT_DISTURB) == STATE_OFF244 assert state.attributes.get(ATTR_ERROR) is None245 assert (state.attributes.get(ATTR_BATTERY_ICON)246 == 'mdi:battery-30')247 assert state.attributes.get(ATTR_CLEANING_TIME) == 175248 assert state.attributes.get(ATTR_CLEANED_AREA) == 133249 assert state.attributes.get(ATTR_FAN_SPEED) == 99250 assert (state.attributes.get(ATTR_FAN_SPEED_LIST)251 == ['Quiet', 'Balanced', 'Turbo', 'Max'])252 assert state.attributes.get(ATTR_MAIN_BRUSH_LEFT) == 11253 assert state.attributes.get(ATTR_SIDE_BRUSH_LEFT) == 11254 assert state.attributes.get(ATTR_FILTER_LEFT) == 11255 assert state.attributes.get(ATTR_CLEANING_COUNT) == 41256 assert state.attributes.get(ATTR_CLEANED_TOTAL_AREA) == 323257 assert state.attributes.get(ATTR_CLEANING_TOTAL_TIME) == 675258 # Xiaomi vacuum specific services:259 yield from hass.services.async_call(260 DOMAIN, SERVICE_START_REMOTE_CONTROL,261 {ATTR_ENTITY_ID: entity_id}, blocking=True)262 mock_mirobo_is_on.assert_has_calls(263 [mock.call.Vacuum().manual_start()], any_order=True)264 mock_mirobo_is_on.assert_has_calls(status_calls, any_order=True)265 mock_mirobo_is_on.reset_mock()266 control = {"duration": 1000, "rotation": -40, "velocity": -0.1}267 yield from hass.services.async_call(268 DOMAIN, SERVICE_MOVE_REMOTE_CONTROL,269 control, blocking=True)270 mock_mirobo_is_on.assert_has_calls(271 [mock.call.Vacuum().manual_control(control)], any_order=True)272 mock_mirobo_is_on.assert_has_calls(status_calls, any_order=True)273 mock_mirobo_is_on.reset_mock()274 yield from hass.services.async_call(275 DOMAIN, SERVICE_STOP_REMOTE_CONTROL, {}, blocking=True)276 mock_mirobo_is_on.assert_has_calls(277 [mock.call.Vacuum().manual_stop()], any_order=True)278 mock_mirobo_is_on.assert_has_calls(status_calls, any_order=True)279 mock_mirobo_is_on.reset_mock()280 control_once = {"duration": 2000, "rotation": 120, "velocity": 0.1}281 yield from hass.services.async_call(282 DOMAIN, SERVICE_MOVE_REMOTE_CONTROL_STEP,283 control_once, blocking=True)284 mock_mirobo_is_on.assert_has_calls(285 [mock.call.Vacuum().manual_control_once(control_once)], any_order=True)286 mock_mirobo_is_on.assert_has_calls(status_calls, any_order=True)...

Full Screen

Full Screen

test_report.py

Source:test_report.py Github

copy

Full Screen

...77 self._report_contracts(report_class, [broken_contract])78 self.assert_headings_printed(report_class, printer, is_successful=False)79 if report_class is VerboseReport:80 self.assert_dependencies_printed(printer)81 printer.print_error.assert_has_calls([call('Contracts: 0 kept, 1 broken.')])82 printer.print_heading.assert_has_calls([83 call('Broken contracts', printer.HEADING_LEVEL_TWO,84 style=printer.ERROR),85 call('Foo', printer.HEADING_LEVEL_THREE,86 style=printer.ERROR),87 ])88 printer.print_error.assert_has_calls([89 call('1. foo.two imports foo.one:'),90 call('foo.two <-', bold=False),91 call('foo.one', bold=False),92 ])93 assert self.report.has_broken_contracts is True94 def test_multiple_kept_and_broken_contracts(self, printer, report_class, make_kept_contract,95 make_broken_contract):96 broken_contract_1 = make_broken_contract(97 name='Contract 1',98 illegal_dependencies=[99 ('foo.two', 'foo.one'),100 ]101 )102 broken_contract_2 = make_broken_contract(103 name='Contract 2',104 illegal_dependencies=[105 ('bar.two', 'bar.one'),106 ]107 )108 kept_contract_1 = make_kept_contract()109 kept_contract_2 = make_kept_contract()110 kept_contract_3 = make_kept_contract()111 self._report_contracts(112 report_class,113 [114 broken_contract_1,115 kept_contract_1,116 broken_contract_2,117 kept_contract_2,118 kept_contract_3,119 ]120 )121 self.assert_headings_printed(report_class, printer, is_successful=False)122 if report_class is VerboseReport:123 self.assert_dependencies_printed(printer)124 printer.print_contract_one_liner.assert_has_calls([125 call(kept_contract_1),126 call(kept_contract_2),127 call(kept_contract_3),128 call(broken_contract_1),129 call(broken_contract_2),130 ])131 printer.print_error.assert_has_calls([call('Contracts: 3 kept, 2 broken.')])132 printer.print_heading.assert_has_calls([133 call('Broken contracts', printer.HEADING_LEVEL_TWO,134 style=printer.ERROR),135 call('Contract 1', printer.HEADING_LEVEL_THREE,136 style=printer.ERROR),137 ])138 printer.print_error.assert_has_calls([139 call('1. foo.two imports foo.one:'),140 call('foo.two <-', bold=False),141 call('foo.one', bold=False),142 ])143 printer.print_heading.assert_has_calls([144 call('Contract 2', printer.HEADING_LEVEL_THREE,145 style=printer.ERROR),146 ])147 printer.print_error.assert_has_calls([148 call('1. bar.two imports bar.one:'),149 call('bar.two <-', bold=False),150 call('bar.one', bold=False),151 ])152 assert self.report.has_broken_contracts is True153 def test_single_broken_contract_indirect(self, printer, report_class, make_broken_contract):154 contract = make_broken_contract(155 name='Foo',156 illegal_dependencies=[157 ('foo.four', 'foo.three', 'foo.two', 'foo.one'),158 ]159 )160 self._report_contracts(report_class, [contract])161 self.assert_headings_printed(report_class, printer, is_successful=False)162 if report_class is VerboseReport:163 self.assert_dependencies_printed(printer)164 printer.print_contract_one_liner.assert_has_calls([165 call(contract),166 ])167 printer.print_error.assert_has_calls([call('Contracts: 0 kept, 1 broken.')])168 printer.print_heading.assert_has_calls([169 call('Broken contracts', printer.HEADING_LEVEL_TWO,170 style=printer.ERROR),171 call('Foo', printer.HEADING_LEVEL_THREE,172 style=printer.ERROR),173 ])174 printer.print_error.assert_has_calls([175 call('1. foo.four imports foo.one:'),176 call('foo.four <-', bold=False),177 call('foo.three <-', bold=False),178 call('foo.two <-', bold=False),179 call('foo.one', bold=False),180 ])181 assert self.report.has_broken_contracts is True182 def test_single_broken_contract_multiple_illegal_dependencies(self, printer, report_class,183 make_broken_contract):184 contract = make_broken_contract(185 name='Foo',186 illegal_dependencies=[187 ('foo.four', 'foo.three', 'foo.two', 'foo.one'),188 ('bar.two', 'bar.one'),189 ]190 )191 self._report_contracts(report_class, [contract])192 self.assert_headings_printed(report_class, printer, is_successful=False)193 if report_class is VerboseReport:194 self.assert_dependencies_printed(printer)195 printer.print_contract_one_liner.assert_has_calls([196 call(contract),197 ])198 printer.print_error.assert_has_calls([call('Contracts: 0 kept, 1 broken.')])199 printer.print_heading.assert_has_calls([200 call('Broken contracts', printer.HEADING_LEVEL_TWO,201 style=printer.ERROR),202 call('Foo', printer.HEADING_LEVEL_THREE,203 style=printer.ERROR),204 ])205 printer.print_error.assert_has_calls([206 call('1. foo.four imports foo.one:'),207 call('foo.four <-', bold=False),208 call('foo.three <-', bold=False),209 call('foo.two <-', bold=False),210 call('foo.one', bold=False),211 call('2. bar.two imports bar.one:'),212 call('bar.two <-', bold=False),213 call('bar.one', bold=False),214 ])215 assert self.report.has_broken_contracts is True216 def assert_headings_printed(self, report_class, printer, is_successful):217 if (report_class is QuietReport) and is_successful:218 printer.print_heading.assert_not_called()219 printer.print_contract_one_liner.assert_not_called()220 printer.print_success.assert_not_called()221 elif report_class is VerboseReport:222 printer.print_heading.assert_has_calls([223 call('Layer Linter', printer.HEADING_LEVEL_ONE),224 call('Dependencies', printer.HEADING_LEVEL_TWO),225 call('Contracts', printer.HEADING_LEVEL_TWO),226 ])227 else:228 printer.print_heading.assert_has_calls([229 call('Layer Linter', printer.HEADING_LEVEL_ONE),230 call('Contracts', printer.HEADING_LEVEL_TWO),231 ])232 def assert_dependencies_printed(self, printer):233 printer.print.assert_has_calls([234 call('foo.one imports:', bold=True),235 call('- foo.four.one'),236 call('- foo.four.two'),237 call('foo.two imports:', bold=True),238 call('- (nothing)'),239 call('foo.three imports:', bold=True),240 call('- foo.five'),241 ])242@patch.object(report, 'click')243class TestConsolePrinter:244 @pytest.mark.parametrize('style,expected_color', [245 (None, None),246 (ConsolePrinter.SUCCESS, 'green',),247 (ConsolePrinter.ERROR, 'red'),248 ])249 def test_print_heading_1(self, click, style, expected_color):250 ConsolePrinter.print_heading(251 'Lorem ipsum', ConsolePrinter.HEADING_LEVEL_ONE, style)252 assert click.secho.call_count == 3253 click.secho.assert_has_calls([254 call('===========', bold=True, fg=expected_color),255 call('Lorem ipsum', bold=True, fg=expected_color),256 call('===========', bold=True, fg=expected_color),257 ])258 click.echo.assert_called_once_with()259 def test_print_heading_2(self, click):260 ConsolePrinter.print_heading(261 'Dolor sic', ConsolePrinter.HEADING_LEVEL_TWO)262 assert click.secho.call_count == 3263 click.secho.assert_has_calls([264 call('---------', bold=True, fg=None),265 call('Dolor sic', bold=True, fg=None),266 call('---------', bold=True, fg=None),267 ])268 click.echo.assert_called_once_with()269 def test_print_heading_3(self, click):270 ConsolePrinter.print_heading(271 'Amet consectetur', ConsolePrinter.HEADING_LEVEL_THREE)272 assert click.secho.call_count == 2273 click.secho.assert_has_calls([274 call('Amet consectetur', bold=True, fg=None),275 call('----------------', bold=True, fg=None),276 ])277 click.echo.assert_called_once_with()278 @pytest.mark.parametrize('bold', (True, False))279 def test_print(self, click, bold):280 ConsolePrinter.print(sentinel.text, bold)281 click.secho.assert_called_once_with(282 sentinel.text, bold=bold)283 @pytest.mark.parametrize('bold', (True, False))284 def test_print_success(self, click, bold):285 ConsolePrinter.print_success(sentinel.text, bold)286 click.secho.assert_called_once_with(287 sentinel.text, fg='green', bold=bold)288 @pytest.mark.parametrize('bold', (True, False))289 def test_print_error(self, click, bold):290 ConsolePrinter.print_error(sentinel.text, bold)291 click.secho.assert_called_once_with(292 sentinel.text, fg='red', bold=bold)293 def test_indent_cursor(self, click):294 ConsolePrinter.indent_cursor()295 click.echo.assert_called_once_with(' ', nl=False)296 def test_new_line(self, click):297 ConsolePrinter.new_line()298 click.echo.assert_called_once_with()299 @pytest.mark.parametrize(300 'is_kept,whitelisted_path_length,expected_label,expected_color', [301 (True, 4, 'KEPT', 'green'),302 (False, 0, 'BROKEN', 'red'),303 ])304 def test_print_contract_one_liner(self, click, is_kept, whitelisted_path_length,305 expected_label, expected_color):306 contract = MagicMock(307 whitelisted_paths=[MagicMock()] * whitelisted_path_length,308 is_kept=is_kept,309 )310 contract.__str__.return_value = 'Foo'311 ConsolePrinter.print_contract_one_liner(contract)312 if whitelisted_path_length:313 click.secho.assert_has_calls([314 call('Foo ', nl=False),315 call('({} whitelisted paths) '.format(whitelisted_path_length), nl=False),316 call(expected_label, fg=expected_color, bold=True)317 ])318 else:319 click.secho.assert_has_calls([320 call('Foo ', nl=False),321 call(expected_label, fg=expected_color, bold=True)...

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