How to use get_device_info method in Airtest

Best Python code snippet using Airtest

test_parted.py

Source:test_parted.py Github

copy

Full Screen

1# (c) 2017 Red Hat Inc.2# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)3from __future__ import (absolute_import, division, print_function)4__metaclass__ = type5from ansible_collections.community.general.tests.unit.compat.mock import patch, call6from ansible_collections.community.general.plugins.modules.system import parted as parted_module7from ansible_collections.community.general.plugins.modules.system.parted import parse_parted_version8from ansible_collections.community.general.plugins.modules.system.parted import parse_partition_info9from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args10# Example of output : parted -s -m /dev/sdb -- unit 'MB' print11parted_output1 = """12BYT;13/dev/sdb:286061MB:scsi:512:512:msdos:ATA TOSHIBA THNSFJ25:;141:1.05MB:106MB:105MB:fat32::esp;152:106MB:368MB:262MB:ext2::;163:368MB:256061MB:255692MB:::;"""17parted_version_info = {"""18 parted (GNU parted) 3.319 Copyright (C) 2019 Free Software Foundation, Inc.20 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.21 This is free software: you are free to change and redistribute it.22 There is NO WARRANTY, to the extent permitted by law.23 Written by <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.24 """: (3, 3, 0), """25 parted (GNU parted) 3.4.526 Copyright (C) 2019 Free Software Foundation, Inc.27 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.28 This is free software: you are free to change and redistribute it.29 There is NO WARRANTY, to the extent permitted by law.30 Written by <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.31 """: (3, 4, 5), """32 parted (GNU parted) 3.3.14-dfc6133 Copyright (C) 2019 Free Software Foundation, Inc.34 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.35 This is free software: you are free to change and redistribute it.36 There is NO WARRANTY, to the extent permitted by law.37 Written by <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.38 """: (3, 3, 14)}39# corresponding dictionary after parsing by parse_partition_info40parted_dict1 = {41 "generic": {42 "dev": "/dev/sdb",43 "size": 286061.0,44 "unit": "mb",45 "table": "msdos",46 "model": "ATA TOSHIBA THNSFJ25",47 "logical_block": 512,48 "physical_block": 51249 },50 "partitions": [{51 "num": 1,52 "begin": 1.05,53 "end": 106.0,54 "size": 105.0,55 "fstype": "fat32",56 "name": '',57 "flags": ["esp"],58 "unit": "mb"59 }, {60 "num": 2,61 "begin": 106.0,62 "end": 368.0,63 "size": 262.0,64 "fstype": "ext2",65 "name": '',66 "flags": [],67 "unit": "mb"68 }, {69 "num": 3,70 "begin": 368.0,71 "end": 256061.0,72 "size": 255692.0,73 "fstype": "",74 "name": '',75 "flags": [],76 "unit": "mb"77 }]78}79parted_output2 = """80BYT;81/dev/sdb:286061MB:scsi:512:512:msdos:ATA TOSHIBA THNSFJ25:;"""82# corresponding dictionary after parsing by parse_partition_info83parted_dict2 = {84 "generic": {85 "dev": "/dev/sdb",86 "size": 286061.0,87 "unit": "mb",88 "table": "msdos",89 "model": "ATA TOSHIBA THNSFJ25",90 "logical_block": 512,91 "physical_block": 51292 },93 "partitions": []94}95# fake some_flag exists96parted_dict3 = {97 "generic": {98 "dev": "/dev/sdb",99 "size": 286061.0,100 "unit": "mb",101 "table": "msdos",102 "model": "ATA TOSHIBA THNSFJ25",103 "logical_block": 512,104 "physical_block": 512105 },106 "partitions": [{107 "num": 1,108 "begin": 1.05,109 "end": 106.0,110 "size": 105.0,111 "fstype": "fat32",112 "name": '',113 "flags": ["some_flag"],114 "unit": "mb"115 }]116}117class TestParted(ModuleTestCase):118 def setUp(self):119 super(TestParted, self).setUp()120 self.module = parted_module121 self.mock_check_parted_label = (patch('ansible_collections.community.general.plugins.modules.system.parted.check_parted_label', return_value=False))122 self.check_parted_label = self.mock_check_parted_label.start()123 self.mock_parted = (patch('ansible_collections.community.general.plugins.modules.system.parted.parted'))124 self.parted = self.mock_parted.start()125 self.mock_run_command = (patch('ansible.module_utils.basic.AnsibleModule.run_command'))126 self.run_command = self.mock_run_command.start()127 self.mock_get_bin_path = (patch('ansible.module_utils.basic.AnsibleModule.get_bin_path'))128 self.get_bin_path = self.mock_get_bin_path.start()129 def tearDown(self):130 super(TestParted, self).tearDown()131 self.mock_run_command.stop()132 self.mock_get_bin_path.stop()133 self.mock_parted.stop()134 self.mock_check_parted_label.stop()135 def execute_module(self, failed=False, changed=False, script=None):136 if failed:137 result = self.failed()138 self.assertTrue(result['failed'], result)139 else:140 result = self.changed(changed)141 self.assertEqual(result['changed'], changed, result)142 if script:143 self.assertEqual(script, result['script'], result['script'])144 return result145 def failed(self):146 with self.assertRaises(AnsibleFailJson) as exc:147 self.module.main()148 result = exc.exception.args[0]149 self.assertTrue(result['failed'], result)150 return result151 def changed(self, changed=False):152 with self.assertRaises(AnsibleExitJson) as exc:153 self.module.main()154 result = exc.exception.args[0]155 self.assertEqual(result['changed'], changed, result)156 return result157 def test_parse_partition_info(self):158 """Test that the parse_partition_info returns the expected dictionary"""159 self.assertEqual(parse_partition_info(parted_output1, 'MB'), parted_dict1)160 self.assertEqual(parse_partition_info(parted_output2, 'MB'), parted_dict2)161 def test_partition_already_exists(self):162 set_module_args({163 'device': '/dev/sdb',164 'number': 1,165 'state': 'present',166 })167 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):168 self.execute_module(changed=False)169 def test_create_new_partition(self):170 set_module_args({171 'device': '/dev/sdb',172 'number': 4,173 'state': 'present',174 })175 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):176 self.execute_module(changed=True, script='unit KiB mkpart primary 0% 100%')177 def test_create_new_partition_1G(self):178 set_module_args({179 'device': '/dev/sdb',180 'number': 4,181 'state': 'present',182 'part_end': '1GiB',183 })184 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):185 self.execute_module(changed=True, script='unit KiB mkpart primary 0% 1GiB')186 def test_create_new_partition_minus_1G(self):187 set_module_args({188 'device': '/dev/sdb',189 'number': 4,190 'state': 'present',191 'fs_type': 'ext2',192 'part_start': '-1GiB',193 })194 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):195 self.execute_module(changed=True, script='unit KiB mkpart primary ext2 -1GiB 100%')196 def test_remove_partition_number_1(self):197 set_module_args({198 'device': '/dev/sdb',199 'number': 1,200 'state': 'absent',201 })202 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):203 self.execute_module(changed=True, script='rm 1')204 def test_resize_partition(self):205 set_module_args({206 'device': '/dev/sdb',207 'number': 3,208 'state': 'present',209 'part_end': '100%',210 'resize': True211 })212 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):213 self.execute_module(changed=True, script='resizepart 3 100%')214 def test_change_flag(self):215 # Flags are set in a second run of parted().216 # Between the two runs, the partition dict is updated.217 # use checkmode here allow us to continue even if the dictionary is218 # not updated.219 set_module_args({220 'device': '/dev/sdb',221 'number': 3,222 'state': 'present',223 'flags': ['lvm', 'boot'],224 '_ansible_check_mode': True,225 })226 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):227 self.parted.reset_mock()228 self.execute_module(changed=True)229 # When using multiple flags:230 # order of execution is non deterministic, because set() operations are used in231 # the current implementation.232 expected_calls_order1 = [call('unit KiB set 3 lvm on set 3 boot on ',233 '/dev/sdb', 'optimal')]234 expected_calls_order2 = [call('unit KiB set 3 boot on set 3 lvm on ',235 '/dev/sdb', 'optimal')]236 self.assertTrue(self.parted.mock_calls == expected_calls_order1 or237 self.parted.mock_calls == expected_calls_order2)238 def test_create_new_primary_lvm_partition(self):239 # use check_mode, see previous test comment240 set_module_args({241 'device': '/dev/sdb',242 'number': 4,243 'flags': ["boot"],244 'state': 'present',245 'part_start': '257GiB',246 'fs_type': 'ext3',247 '_ansible_check_mode': True,248 })249 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):250 self.execute_module(changed=True, script='unit KiB mkpart primary ext3 257GiB 100% unit KiB set 4 boot on')251 def test_create_label_gpt(self):252 # Like previous test, current implementation use parted to create the partition and253 # then retrieve and update the dictionary. Use check_mode to force to continue even if254 # dictionary is not updated.255 set_module_args({256 'device': '/dev/sdb',257 'number': 1,258 'flags': ["lvm"],259 'label': 'gpt',260 'name': 'lvmpartition',261 'state': 'present',262 '_ansible_check_mode': True,263 })264 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict2):265 self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100% unit KiB name 1 \'"lvmpartition"\' set 1 lvm on')266 def test_change_label_gpt(self):267 # When partitions already exists and label is changed, mkpart should be called even when partition already exists,268 # because new empty label will be created anyway269 set_module_args({270 'device': '/dev/sdb',271 'number': 1,272 'state': 'present',273 'label': 'gpt',274 '_ansible_check_mode': True,275 })276 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):277 self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100%')278 def test_check_mode_unchanged(self):279 # Test that get_device_info result is checked in check mode too280 # No change on partition 1281 set_module_args({282 'device': '/dev/sdb',283 'number': 1,284 'state': 'present',285 'flags': ['some_flag'],286 '_ansible_check_mode': True,287 })288 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict3):289 self.execute_module(changed=False)290 def test_check_mode_changed(self):291 # Test that get_device_info result is checked in check mode too292 # Flag change on partition 1293 set_module_args({294 'device': '/dev/sdb',295 'number': 1,296 'state': 'present',297 'flags': ['other_flag'],298 '_ansible_check_mode': True,299 })300 with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict3):301 self.execute_module(changed=True)302 def test_version_info(self):303 """Test that the parse_parted_version returns the expected tuple"""304 for key, value in parted_version_info.items():...

Full Screen

Full Screen

device_info.py

Source:device_info.py Github

copy

Full Screen

...43 return get_adb_handler().get_version()44 @staticmethod45 def get_screen():46 return get_adb_handler().get_screen()47def get_device_info():48 if not get_device_info.instance:49 platform_name = os.getenv(Environment.PLATFORM)50 if platform_name == Platform.Windows:51 get_device_info.instance = PCInfo52 elif platform_name == Platform.Android:53 get_device_info.instance = MobileInfo54 else:55 get_device_info.instance = PCInfo56 return get_device_info.instance...

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 Airtest 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