Best Python code snippet using robotframework-appiumlibrary_python
test_backend.py
Source:test_backend.py
...38 self.assertFalse(capabilities[Capability.WEATHER])39 self.assertFalse(capabilities[Capability.POWER_CURRENT])40 self.assertFalse(capabilities[Capability.COSTS])41 self.assertFalse(capabilities[Capability.ANY])42 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.ELECTRICITY))43 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.ELECTRICITY_RETURNED))44 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.GAS))45 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.MULTI_PHASES))46 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.WEATHER))47 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.POWER_CURRENT))48 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.COSTS))49 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.ANY))50 def test_electricity_capabilities(self):51 """ Capability check for electricity consumption. """52 capabilities = dsmr_backend.services.backend.get_capabilities()53 self.assertFalse(capabilities[Capability.ELECTRICITY])54 self.assertFalse(capabilities[Capability.ANY])55 ElectricityConsumption.objects.create(56 read_at=timezone.now(),57 delivered_1=0,58 returned_1=0,59 delivered_2=0,60 returned_2=0,61 currently_delivered=0,62 currently_returned=0,63 )64 capabilities = dsmr_backend.services.backend.get_capabilities()65 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.ELECTRICITY))66 self.assertTrue(capabilities[Capability.ELECTRICITY])67 self.assertTrue(capabilities[Capability.ANY])68 def test_multi_phases_capabilities(self):69 """ Capability check for multiple phases. """70 capabilities = dsmr_backend.services.backend.get_capabilities()71 self.assertFalse(capabilities[Capability.MULTI_PHASES])72 self.assertFalse(capabilities[Capability.ANY])73 ElectricityConsumption.objects.create(74 read_at=timezone.now(),75 delivered_1=0,76 returned_1=0,77 delivered_2=0,78 returned_2=0,79 currently_delivered=0,80 currently_returned=0,81 phase_currently_delivered_l1=1,82 phase_currently_returned_l1=2,83 )84 # Should fail.85 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.MULTI_PHASES))86 ElectricityConsumption.objects.create(87 read_at=timezone.now() + timezone.timedelta(minutes=1),88 delivered_1=0,89 returned_1=0,90 delivered_2=0,91 returned_2=0,92 currently_delivered=0,93 currently_returned=0,94 phase_currently_delivered_l2=1,95 phase_currently_delivered_l3=1,96 phase_currently_returned_l2=2,97 phase_currently_returned_l3=2,98 )99 capabilities = dsmr_backend.services.backend.get_capabilities()100 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.MULTI_PHASES))101 self.assertTrue(capabilities[Capability.MULTI_PHASES])102 self.assertTrue(capabilities[Capability.ANY])103 def test_multi_phases_capabilities_belgium(self):104 """ Capability check for multiple phases, Belgium version which lack some fields. """105 capabilities = dsmr_backend.services.backend.get_capabilities()106 self.assertFalse(capabilities[Capability.MULTI_PHASES])107 self.assertFalse(capabilities[Capability.ANY])108 ElectricityConsumption.objects.create(109 read_at=timezone.now(),110 delivered_1=0,111 returned_1=0,112 delivered_2=0,113 returned_2=0,114 currently_delivered=0,115 currently_returned=0,116 phase_voltage_l2=None,117 phase_voltage_l3=None,118 )119 # Should fail.120 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.MULTI_PHASES))121 ElectricityConsumption.objects.create(122 read_at=timezone.now() + timezone.timedelta(minutes=1),123 delivered_1=0,124 returned_1=0,125 delivered_2=0,126 returned_2=0,127 currently_delivered=0,128 currently_returned=0,129 phase_voltage_l2=1,130 phase_voltage_l3=2,131 )132 capabilities = dsmr_backend.services.backend.get_capabilities()133 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.MULTI_PHASES))134 self.assertTrue(capabilities[Capability.MULTI_PHASES])135 self.assertTrue(capabilities[Capability.ANY])136 def test_electricity_returned_capabilities(self):137 """ Capability check for electricity returned. """138 capabilities = dsmr_backend.services.backend.get_capabilities()139 self.assertFalse(capabilities[Capability.ELECTRICITY_RETURNED])140 self.assertFalse(capabilities[Capability.ANY])141 # Should not have any affect.142 consumption = ElectricityConsumption.objects.create(143 read_at=timezone.now(),144 delivered_1=0,145 returned_1=0,146 delivered_2=0,147 returned_2=0,148 currently_delivered=0,149 currently_returned=0,150 )151 capabilities = dsmr_backend.services.backend.get_capabilities()152 self.assertFalse(capabilities[Capability.ELECTRICITY_RETURNED])153 consumption.currently_returned = 0.001154 consumption.save(update_fields=['currently_returned'])155 capabilities = dsmr_backend.services.backend.get_capabilities()156 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.ELECTRICITY_RETURNED))157 self.assertTrue(capabilities[Capability.ELECTRICITY_RETURNED])158 self.assertTrue(capabilities[Capability.ANY])159 def test_gas_capabilities(self):160 """ Capability check for gas consumption. """161 capabilities = dsmr_backend.services.backend.get_capabilities()162 self.assertFalse(capabilities[Capability.GAS])163 self.assertFalse(capabilities[Capability.ANY])164 GasConsumption.objects.create(165 read_at=timezone.now(),166 delivered=0,167 currently_delivered=0,168 )169 capabilities = dsmr_backend.services.backend.get_capabilities()170 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.GAS))171 self.assertTrue(capabilities[Capability.GAS])172 self.assertTrue(capabilities[Capability.ANY])173 def test_weather_capabilities(self):174 """ Capability check for gas consumption. """175 weather_settings = WeatherSettings.get_solo()176 self.assertFalse(weather_settings.track)177 self.assertFalse(TemperatureReading.objects.exists())178 capabilities = dsmr_backend.services.backend.get_capabilities()179 self.assertFalse(capabilities[Capability.WEATHER])180 self.assertFalse(capabilities[Capability.ANY])181 # Should not have any affect.182 weather_settings.track = True183 weather_settings.save(update_fields=['track'])184 self.assertTrue(WeatherSettings.get_solo().track)185 capabilities = dsmr_backend.services.backend.get_capabilities()186 self.assertFalse(capabilities[Capability.WEATHER])187 TemperatureReading.objects.create(read_at=timezone.now(), degrees_celcius=0.0)188 capabilities = dsmr_backend.services.backend.get_capabilities()189 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.WEATHER))190 self.assertTrue(capabilities[Capability.WEATHER])191 self.assertTrue(capabilities[Capability.ANY])192 def test_costs_capabilities(self):193 capabilities = dsmr_backend.services.backend.get_capabilities()194 self.assertFalse(capabilities[Capability.COSTS])195 self.assertFalse(capabilities[Capability.ANY])196 EnergySupplierPrice.objects.create(197 start=timezone.now().date(),198 end=(timezone.now() + timezone.timedelta(hours=24)).date(),199 electricity_delivered_1_price=0.010,200 electricity_delivered_2_price=0.020,201 )202 capabilities = dsmr_backend.services.backend.get_capabilities()203 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.COSTS))204 self.assertTrue(capabilities[Capability.COSTS])205 self.assertTrue(capabilities[Capability.ANY])206 def test_disabled_capabilities(self):207 """ Whether disable capabilities affects the outcome. """208 BackendSettings.get_solo()209 ElectricityConsumption.objects.create(210 read_at=timezone.now(),211 delivered_1=1,212 returned_1=2,213 delivered_2=3,214 returned_2=4,215 currently_delivered=5,216 currently_returned=6,217 )218 GasConsumption.objects.create(219 read_at=timezone.now(),220 delivered=1,221 currently_delivered=1,222 )223 capabilities = dsmr_backend.services.backend.get_capabilities()224 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.GAS))225 self.assertTrue(capabilities[Capability.GAS])226 self.assertTrue(dsmr_backend.services.backend.get_capability(Capability.ELECTRICITY_RETURNED))227 self.assertTrue(capabilities[Capability.ELECTRICITY_RETURNED])228 # Disable gas.229 BackendSettings.objects.all().update(disable_gas_capability=True)230 capabilities = dsmr_backend.services.backend.get_capabilities()231 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.GAS))232 self.assertFalse(capabilities[Capability.GAS])233 # Disable return.234 BackendSettings.objects.all().update(disable_electricity_returned_capability=True)235 capabilities = dsmr_backend.services.backend.get_capabilities()236 self.assertFalse(dsmr_backend.services.backend.get_capability(Capability.ELECTRICITY_RETURNED))237 self.assertFalse(capabilities[Capability.ELECTRICITY_RETURNED])238 @mock.patch('django.core.cache.cache.set')239 @mock.patch('django.core.cache.cache.get')240 def test_capability_caching(self, get_cache_mock, set_cache_mock):241 """ Whether capabilities are cached. """242 get_cache_mock.return_value = None243 self.assertFalse(get_cache_mock.called)244 self.assertFalse(set_cache_mock.called)245 first_capabilities = dsmr_backend.services.backend.get_capabilities()246 self.assertTrue(get_cache_mock.called)247 self.assertTrue(set_cache_mock.called)248 # Now we should retreive from cache.249 set_cache_mock.reset_mock()250 get_cache_mock.return_value = first_capabilities # Fake caching....
test_get_capability.py
Source:test_get_capability.py
1########2# Copyright (c) 2018 Cloudify Platform Ltd. All rights reserved3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# * See the License for the specific language governing permissions and14# * limitations under the License.15from dsl_parser import functions16from dsl_parser.tasks import prepare_deployment_plan17from dsl_parser.constants import INTER_DEPLOYMENT_FUNCTIONS, OUTPUTS18from dsl_parser.tests.abstract_test_parser import AbstractTestParser19class TestGetCapability(AbstractTestParser):20 def setUp(self):21 super(TestGetCapability, self).setUp()22 self.mock_storage = self.mock_evaluation_storage(23 capabilities={24 'dep_1': {25 'cap_a': 'value_a_1',26 'cap_b': 'value_b_1'27 },28 'dep_2': {29 'cap_a': 'value_a_2',30 'cap_b': 'value_b_2'31 }32 }33 )34 def test_has_intrinsic_functions_property(self):35 yaml = """36relationships:37 cloudify.relationships.contained_in: {}38plugins:39 p:40 executor: central_deployment_agent41 install: false42node_types:43 webserver_type: {}44node_templates:45 node:46 type: webserver_type47 webserver:48 type: webserver_type49 interfaces:50 test:51 op_with_no_get_capability:52 implementation: p.p53 inputs:54 a: 155 op_with_get_capability:56 implementation: p.p57 inputs:58 a:59 get_capability:60 - deployment_id61 - node_template_capability_id62 relationships:63 - type: cloudify.relationships.contained_in64 target: node65 source_interfaces:66 test:67 op_with_no_get_capability:68 implementation: p.p69 inputs:70 a: 171 op_with_get_capability:72 implementation: p.p73 inputs:74 a:75 get_capability:76 - deployment_id77 - source_op_capability_id78 target_interfaces:79 test:80 op_with_no_get_capability:81 implementation: p.p82 inputs:83 a: 184 op_with_get_capability:85 implementation: p.p86 inputs:87 a:88 get_capability:89 - deployment_id90 - target_op_capability_id91"""92 parsed = prepare_deployment_plan(self.parse(yaml))93 webserver_node = None94 for node in parsed.node_templates:95 if node['id'] == 'webserver':96 webserver_node = node97 break98 self.assertIsNotNone(webserver_node)99 def assertion(operations):100 op = operations['test.op_with_no_get_capability']101 self.assertIs(False, op.get('has_intrinsic_functions'))102 op = operations['test.op_with_get_capability']103 self.assertIs(True, op.get('has_intrinsic_functions'))104 assertion(webserver_node['operations'])105 assertion(webserver_node['relationships'][0]['source_operations'])106 assertion(webserver_node['relationships'][0]['target_operations'])107 def test_evaluate_functions(self):108 payload = {109 'a': {'get_capability': ['dep_1', 'cap_a']},110 'b': {'get_capability': ['dep_2', 'cap_a']},111 'c': {'concat': [112 {'get_capability': ['dep_1', 'cap_b']},113 {'get_capability': ['dep_2', 'cap_b']}114 ]}115 }116 functions.evaluate_functions(payload, {}, self.mock_storage)117 self.assertEqual(payload['a'], 'value_a_1')118 self.assertEqual(payload['b'], 'value_a_2')119 self.assertEqual(payload['c'], 'value_b_1value_b_2')120 def test_node_template_properties_simple(self):121 yaml = """122node_types:123 type:124 properties:125 property: {}126node_templates:127 node:128 type: type129 properties:130 property: { get_capability: [ dep_1, cap_a ]}131"""132 parsed = prepare_deployment_plan(self.parse_1_3(yaml))133 node = self.get_node_by_name(parsed, 'node')134 self.assertEqual({'get_capability': ['dep_1', 'cap_a']},135 node['properties']['property'])136 functions.evaluate_functions(parsed, {}, self.mock_storage)137 self.assertEqual(node['properties']['property'], 'value_a_1')138 def test_capabilities_in_outputs(self):139 yaml = """140node_types:141 type: {}142node_templates:143 node:144 type: type145outputs:146 output:147 value: { get_capability: [ dep_1, cap_a ]}148"""149 parsed = prepare_deployment_plan(self.parse_1_3(yaml))150 outputs = parsed.outputs151 self.assertEqual({'get_capability': ['dep_1', 'cap_a']},152 outputs['output']['value'])153 functions.evaluate_functions(parsed, {}, self.mock_storage)154 self.assertEqual(outputs['output']['value'], 'value_a_1')155 def test_capabilities_in_inputs(self):156 yaml = """157inputs:158 input:159 default: { get_capability: [ dep_1, cap_a ]}160node_types:161 type: {}162node_templates:163 node:164 type: type165outputs:166 output:167 value: { get_input: input }168"""169 parsed = prepare_deployment_plan(self.parse_1_3(yaml))170 outputs = parsed.outputs171 # `get_input` is evaluated at parse time, so we expect to see it172 # replaced here with the `get_capability` function173 self.assertEqual({'get_capability': ['dep_1', 'cap_a']},174 outputs['output']['value'])175 functions.evaluate_functions(parsed, {}, self.mock_storage)176 self.assertEqual(outputs['output']['value'], 'value_a_1')177 def test_get_capability_not_list(self):178 yaml = """179node_types:180 type:181 properties:182 property: {}183node_templates:184 node:185 type: type186 properties:187 property: { get_capability: i_should_be_a_list }188"""189 self.assertRaisesRegex(190 ValueError,191 "`get_capability` function argument should be a list. ",192 self.parse_1_3,193 yaml)194 def test_get_capability_short_list(self):195 yaml = """196node_types:197 type:198 properties:199 property: {}200node_templates:201 node:202 type: type203 properties:204 property: { get_capability: [ only_one_item ] }205"""206 self.assertRaisesRegex(207 ValueError,208 "`get_capability` function argument should be a list "209 "with 2 elements at least",210 self.parse_1_3,211 yaml)212 def test_get_capability_first_complex(self):213 yaml = """214node_types:215 type:216 properties:217 property: {}218node_templates:219 node:220 type: type221 properties:222 property: { get_capability: [ [list] , value ] }223"""224 self.assertRaisesRegex(225 ValueError,226 "`get_capability` function arguments can't be complex "227 "values; only strings/ints/functions are accepted. ",228 self.parse_1_3,229 yaml)230 def test_get_capability_registers_to_plan(self):231 yaml = """232node_types:233 type: {}234node_templates:235 node:236 type: type237outputs:238 output1:239 value: { get_capability: [ { get_capability: [ dep_1, cap_a ]}, cap_b ]}240 output2:241 value: { get_capability:242 [ { get_attribute: [node, doesnt_matter] }, cap_a ]}243"""244 def _assert_capability_is_registered(capability_path, expected_value):245 self.assertIn(capability_path, parsed[INTER_DEPLOYMENT_FUNCTIONS])246 self.assertEqual(247 parsed[INTER_DEPLOYMENT_FUNCTIONS][capability_path],248 expected_value)249 parsed = prepare_deployment_plan(self.parse(yaml))250 get_cap_path1 = '{0}.output1.value.get_capability'.format(OUTPUTS)251 cap_path1_func = {'get_capability': ['dep_1', 'cap_a']}252 get_cap_path2 = '{0}.output1.value.get_capability[0].get_capability' \253 ''.format(OUTPUTS)254 cap_path2_func = 'dep_1'255 get_cap_path3 = '{0}.output2.value.get_capability'.format(OUTPUTS)256 cap_path3_func = {'get_attribute': ['node', 'doesnt_matter']}257 self.assertIn(INTER_DEPLOYMENT_FUNCTIONS, parsed)258 _assert_capability_is_registered(get_cap_path1, (None, cap_path1_func))259 _assert_capability_is_registered(get_cap_path2, ('dep_1',260 cap_path2_func))...
drm.py
Source:drm.py
...9 print('name:', v.name)10 print('date:', v.date)11 print('description:', v.desc)12 print('capabilities:')13 print(' dumb buffers:', device.get_capability(drm.CAP_DUMB_BUFFER))14 print(' VBLANK high CRTC:', device.get_capability(drm.CAP_VBLANK_HIGH_CRTC))15 print(' preferred depth:', device.get_capability(drm.CAP_DUMB_PREFERRED_DEPTH))16 print(' prefer shadow:', device.get_capability(drm.CAP_DUMB_PREFER_SHADOW))17 prime = device.get_capability(drm.CAP_PRIME)18 flags = []19 if prime & drm.CAP_PRIME_IMPORT:20 flags.append('import')21 if prime & drm.CAP_PRIME_EXPORT:22 flags.append('export')23 print(' PRIME:', ', '.join(flags))24 print(' timestamp monotonic:', device.get_capability(drm.CAP_TIMESTAMP_MONOTONIC))25 print(' async page flip:', device.get_capability(drm.CAP_ASYNC_PAGE_FLIP))26 width = device.get_capability(drm.CAP_CURSOR_WIDTH)27 height = device.get_capability(drm.CAP_CURSOR_HEIGHT)28 print(' cursor: %ux%u' % (width, height))29 print(' framebuffer modifiers:', device.get_capability(drm.CAP_ADDFB2_MODIFIERS))30 print(' page flip target:', device.get_capability(drm.CAP_PAGE_FLIP_TARGET))31 print(' CRTC in VBLANK event:', device.get_capability(drm.CAP_CRTC_IN_VBLANK_EVENT))32 print(' Sync objects:', device.get_capability(drm.CAP_SYNCOBJ))33 device.set_capability(drm.CLIENT_CAP_UNIVERSAL_PLANES, True)34 device.get_resources()35 if device.connectors:36 print('connectors:')37 for connector in device.connectors:38 print(' %s' % connector)39 if connector.modes:40 print(' modes:')41 for mode in connector.modes:42 flags = ', '.join(mode.get_flags())43 types = ', '.join(mode.get_types())44 if flags:45 flags = ' flags: %s' % flags46 if types:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!