How to use update_all method in autotest

Best Python code snippet using autotest_python

custom_updater.py

Source:custom_updater.py Github

copy

Full Screen

...86 await python_scripts_controller.cache_versions()87 async def update_all_service(call):88 """Set up service for manual trigger."""89 if 'cards' in conf_track:90 await card_controller.update_all()91 if 'components' in conf_track:92 await components_controller.update_all()93 if 'python_scripts' in conf_track:94 await python_scripts_controller.update_all()95 async def install_service(call):96 """Install single component/card."""97 element = call.data.get(ATTR_ELEMENT)98 _LOGGER.debug('Installing %s', element)99 if 'cards' in conf_track:100 await card_controller.install(element)101 if 'components' in conf_track:102 await components_controller.install(element)103 if 'python_scripts' in conf_track:104 await python_scripts_controller.install(element)105 hass.services.async_register(DOMAIN, 'check_all', check_all_service)106 hass.services.async_register(DOMAIN, 'update_all', update_all_service)107 hass.services.async_register(DOMAIN, 'install', install_service)108 return True109class CustomCards():110 """Custom cards controller."""111 # pylint: disable=too-many-instance-attributes112 def __init__(self, hass, conf_hide_sensor, conf_card_urls,113 conf_mode):114 """Initialize."""115 _LOGGER.debug('CustomCards - __init__')116 from pyupdate.ha_custom.custom_cards import CustomCards as Cards117 self.hass = hass118 self.ha_conf_dir = str(hass.config.path())119 self.hidden = conf_hide_sensor120 self.pyupdate = Cards(self.ha_conf_dir, conf_mode, '', conf_card_urls)121 async def extra_init(self):122 """Additional init."""123 _LOGGER.debug('CustomCards - extra_init')124 await self.pyupdate.init_local_data()125 await self.cache_versions()126 await self.serve_dynamic_files()127 async def force_reload(self, now=None):128 """Force data refresh"""129 _LOGGER.debug('CustomCards - force_reload')130 await self.pyupdate.force_reload()131 await self.cache_versions()132 async def cache_versions(self, now=None):133 """Cache."""134 _LOGGER.debug('CustomCards - cache_versions')135 information = await self.pyupdate.get_sensor_data()136 state = int(information[1])137 attributes = information[0]138 attributes['hidden'] = self.hidden139 self.hass.states.async_set(140 'sensor.custom_card_tracker', state, attributes)141 async def update_all(self):142 """Update all cards."""143 _LOGGER.debug('CustomCards - update_all')144 await self.pyupdate.update_all()145 information = await self.pyupdate.get_sensor_data()146 state = int(information[1])147 attributes = information[0]148 attributes['hidden'] = self.hidden149 self.hass.states.async_set(150 'sensor.custom_card_tracker', state, attributes)151 async def install(self, element):152 """Install single card."""153 _LOGGER.debug('CustomCards - update_all')154 await self.pyupdate.install(element)155 async def serve_dynamic_files(self):156 """Serve dynamic cardfiles."""157 self.hass.http.register_view(CustomCardsView(self.ha_conf_dir))158class CustomComponents():159 """Custom components controller."""160 # pylint: disable=too-many-instance-attributes161 def __init__(self, hass, conf_hide_sensor, conf_component_urls):162 """Initialize."""163 _LOGGER.debug('CustomComponents - __init__')164 from pyupdate.ha_custom.custom_components import (165 CustomComponents as Components)166 self.hass = hass167 self.ha_conf_dir = str(hass.config.path())168 self.hidden = conf_hide_sensor169 self.pyupdate = Components(self.ha_conf_dir, conf_component_urls)170 async def extra_init(self):171 """Additional init."""172 _LOGGER.debug('CustomComponents - extra_init')173 await self.cache_versions()174 async def cache_versions(self, now=None):175 """Cache."""176 _LOGGER.debug('CustomComponents - cache_versions')177 information = await self.pyupdate.get_sensor_data(True)178 state = int(information[1])179 attributes = information[0]180 attributes['hidden'] = self.hidden181 self.hass.states.async_set(182 'sensor.custom_component_tracker', state, attributes)183 async def update_all(self):184 """Update all components."""185 _LOGGER.debug('CustomComponents - update_all')186 await self.pyupdate.update_all()187 information = await self.pyupdate.get_sensor_data()188 state = int(information[1])189 attributes = information[0]190 attributes['hidden'] = self.hidden191 self.hass.states.async_set(192 'sensor.custom_component_tracker', state, attributes)193 async def install(self, element):194 """Install single component."""195 _LOGGER.debug('CustomComponents - install')196 await self.pyupdate.install(element)197class CustomPythonScripts():198 """Custom python_scripts controller."""199 # pylint: disable=too-many-instance-attributes200 def __init__(self, hass, conf_hide_sensor, conf_python_script_urls):201 """Initialize."""202 _LOGGER.debug('CustomPythonScripts - __init__')203 from pyupdate.ha_custom.python_scripts import PythonScripts204 self.hass = hass205 self.ha_conf_dir = str(hass.config.path())206 self.hidden = conf_hide_sensor207 self.pyupdate = PythonScripts(208 self.ha_conf_dir, conf_python_script_urls)209 async def extra_init(self):210 """Additional init."""211 _LOGGER.debug('CustomPythonScripts - extra_init')212 await self.cache_versions()213 async def cache_versions(self, now=None):214 """Cache."""215 _LOGGER.debug('CustomPythonScripts - cache_versions')216 information = await self.pyupdate.get_sensor_data(True)217 state = int(information[1])218 attributes = information[0]219 attributes['hidden'] = self.hidden220 self.hass.states.async_set(221 'sensor.custom_python_script_tracker', state, attributes)222 async def update_all(self):223 """Update all python_scripts."""224 _LOGGER.debug('CustomPythonScripts - update_all')225 await self.pyupdate.update_all()226 information = await self.pyupdate.get_sensor_data()227 state = int(information[1])228 attributes = information[0]229 attributes['hidden'] = self.hidden230 self.hass.states.async_set(231 'sensor.custom_python_script_tracker', state, attributes)232 async def install(self, element):233 """Install single python_script."""234 _LOGGER.debug('CustomPythonScripts - install')235 await self.pyupdate.install(element)236class CustomCardsView(HomeAssistantView):237 """View to return a custom_card file."""238 requires_auth = False239 url = r"/customcards/{path:.+}"...

Full Screen

Full Screen

test_cmus.py

Source:test_cmus.py Github

copy

Full Screen

...22 def tearDown(self):23 mocks.teardown_test(self)24 def test_read_song(self):25 self.popen.mock.communicate.return_value = ("song", None)26 self.module.update_all()27 self.popen.assert_call("cmus-remote -Q")28 def test_handle_runtimeerror(self):29 self.popen.mock.communicate.side_effect = RuntimeError("error loading song")30 self.module.update_all()31 self.assertEquals(self.module.description(self.anyWidget), " - /")32 def test_format(self):33 self.popen.mock.communicate.return_value = (self.songTemplate.format(34 artist="an artist", title="a title", duration="100", position="20",35 album="an album", status="irrelevant"36 ), None)37 self.module.update_all()38 self.anyWidget.set("theme.width", 1000)39 self.assertEquals(self.module.description(self.anyWidget),40 "an artist - a title 00:20/01:40"41 )42 def test_scrollable_format(self):43 self.popen.mock.communicate.return_value = (self.songTemplate.format(44 artist="an artist", title="a title", duration="100", position="20",45 album="an album", status="irrelevant"46 ), None)47 self.module.update_all()48 self.anyWidget.set("theme.width", 10)49 self.assertEquals(self.module.description(self.anyWidget),50 "an artist - a title 00:20/01:40"[:10]51 )52 def test_repeat(self):53 self.popen.mock.communicate.return_value = ("set repeat false", None)54 self.module.update_all()55 self.assertTrue("repeat-off" in self.module.state(self.module.widget("cmus.repeat")))56 self.popen.mock.communicate.return_value = ("set repeat true", None)57 self.module.update_all()58 self.assertTrue("repeat-on" in self.module.state(self.module.widget("cmus.repeat")))59 def test_shuffle(self):60 self.popen.mock.communicate.return_value = ("set shuffle false", None)61 self.module.update_all()62 self.assertTrue("shuffle-off" in self.module.state(self.module.widget("cmus.shuffle")))63 self.popen.mock.communicate.return_value = ("set shuffle true", None)64 self.module.update_all()65 self.assertTrue("shuffle-on" in self.module.state(self.module.widget("cmus.shuffle")))66 def test_prevnext(self):67 self.assertTrue("prev" in self.module.state(self.module.widget("cmus.prev")))68 self.assertTrue("next" in self.module.state(self.module.widget("cmus.next")))69 def test_main(self):70 self.popen.mock.communicate.return_value = ("status paused", None)71 self.module.update_all()72 self.assertTrue("paused" in self.module.state(self.module.widget("cmus.main")))73 self.popen.mock.communicate.return_value = ("status playing", None)74 self.module.update_all()75 self.assertTrue("playing" in self.module.state(self.module.widget("cmus.main")))76 self.popen.mock.communicate.return_value = ("status stopped", None)77 self.module.update_all()78 self.assertTrue("stopped" in self.module.state(self.module.widget("cmus.main")))79 def test_widget(self):80 self.assertEquals(len(self.module.widgets()), 5)81 for idx, val in enumerate(["prev", "main", "next", "shuffle", "repeat"]):82 self.assertEquals(self.module.widgets()[idx].name, "cmus.{}".format(val))83 def test_interaction(self):84 events = [85 {"widget": "cmus.shuffle", "action": "cmus-remote -S"},86 {"widget": "cmus.repeat", "action": "cmus-remote -R"},87 {"widget": "cmus.next", "action": "cmus-remote -n"},88 {"widget": "cmus.prev", "action": "cmus-remote -r"},89 {"widget": "cmus.main", "action": "cmus-remote -u"},90 ]91 for event in events:...

Full Screen

Full Screen

test_battery.py

Source:test_battery.py Github

copy

Full Screen

...42 for widget in self.module.widgets():43 self.assertEquals(len(widget.full_text()), len("100%"))44 def test_critical(self):45 self.file.read.return_value = self.criticalValue46 self.module.update_all()47 self.assertTrue("critical" in self.module.state(self.anyWidget))48 def test_warning(self):49 self.file.read.return_value = self.warningValue50 self.module.update_all()51 self.assertTrue("warning" in self.module.state(self.anyWidget))52 def test_normal(self):53 self.file.read.return_value = self.normalValue54 self.module.update_all()55 self.assertTrue(not "warning" in self.module.state(self.anyWidget))56 self.assertTrue(not "critical" in self.module.state(self.anyWidget))57 def test_overload(self):58 self.file.read.return_value = "120"59 self.module.update_all()60 self.assertTrue(not "warning" in self.module.state(self.anyWidget))61 self.assertTrue(not "critical" in self.module.state(self.anyWidget))62 self.assertEquals(self.module.capacity(self.anyWidget), "100%")63 def test_ac(self):64 self.exists.return_value = False65 self.module.update_all()66 self.assertEquals(self.module.capacity(self.anyWidget), "ac")67 self.assertTrue("AC" in self.module.state(self.anyWidget))68 def test_error(self):69 self.file.read.side_effect = IOError("failed to read")70 self.module.update_all()71 self.assertEquals(self.module.capacity(self.anyWidget), "n/a")72 self.assertTrue("critical" in self.module.state(self.anyWidget))73 self.assertTrue("unknown" in self.module.state(self.anyWidget))74 def test_charging(self):75 self.file.read.return_value = self.chargedValue76 self.module.update_all()77 self.assertTrue("charged" in self.module.state(self.anyWidget))78 self.file.read.return_value = self.normalValue79 self.module.update_all()80 self.assertTrue("charging" in self.module.state(self.anyWidget))81 82 def test_discharging(self):83 for limit in [ 10, 25, 50, 80, 100 ]:84 value = limit - 185 self.file.read.return_value = str(value)86 self.module.update_all()87 self.file.read.return_value = "Discharging"88 self.assertTrue("discharging-{}".format(limit) in self.module.state(self.anyWidget))...

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