Best Python code snippet using autotest_python
mapConf.py
Source:mapConf.py
...88 configfile = open(self.config_path, 'wb')89 config.write(configfile)90 ## Reads the configuration from a given file91 def read(self):92 def read_config(keyOption, defaultValue, castFunction, section=SECTION_INIT):93 try:94 strValue = config.get(section, keyOption)95 return castFunction(strValue)96 except Exception:97 return defaultValue98 config = ConfigParser.RawConfigParser()99 config.read(self.config_path)100 ## Initial window width, default is 550101 self.init_width = read_config('width', 780, int)102 ## Initial window height, default is 450103 self.init_height = read_config('height', 600, int)104 ## Directory path to the map images, default is "userProfile" folder105 self.init_path = DEFAULT_PATH106 strPath = read_config('path', self.init_path, str)107 if not strPath.strip().lower() in ['none', '']:108 strPath = fileUtils.check_dir(strPath)109 if os.path.isdir(strPath):110 self.init_path = strPath111 ## Repository type - filebased / sqlite3112 self.repository_type = read_config('repository_type', 0, int)113 ## URL with the latest version used for the notification updates.114 self.version_url = read_config('version_url',115 'http://gmapcatcher.googlecode.com/svn/wiki/version.wiki', str)116 ## Whether or not to check for updates, default is True (1)117 self.check_for_updates = read_config('check_for_updates', 1, int)118 ## oneDirPerMap setting, default is False119 self.oneDirPerMap = read_config('oneDirPerMap', 0, int)120 ## Statusbar type, default is STATUS_NONE121 self.statusbar_type = read_config('statusbar_type', STATUS_NONE, int)122 ## save width/height/layer/location at close, default is SAVE_AT_CLOSE123 self.save_at_close = read_config('save_at_close', 1, int)124 ## layer when saved at close125 self.save_layer = read_config('save_layer', LAYER_MAP, int)126 ## location when saved at close127 self.save_hlocation = read_config('save_hlocation', 0, int)128 self.save_vlocation = read_config('save_vlocation', 0, int)129 ## width when saved at close130 self.save_width = read_config('save_width', 780, int)131 ## height when saved at close132 self.save_height = read_config('save_height', 600, int)133 ## The match function to be used in the auto-completion of the entry134 self.match_func = read_config('match_func', ENTRY_SUB_MENU[0], str)135 ## List of map servers to hide136 self.hide_map_servers = read_config('hide_map_servers', '0,3,16,18,19,20', str)137 ## Speed and distance units (default km / km/h)138 self.units = read_config('units', 0, int)139 ## Start offline (default = Yes)140 self.start_offline = read_config('start_offline', 1, int)141 ## limited capabilities (default = No)142 self.limited = read_config('limited', 0, int)143 ## Initial map zoom, default is MAP_MAX_ZOOM_LEVEL-2144 self.init_zoom = read_config('zoom', MAP_MAX_ZOOM_LEVEL - 2, int, SECTION_MAP)145 ## language setting, default is 'en'146 self.language = read_config('language', 'en', str, SECTION_MAP)147 ## Initial map center, default is ((1, 1), (210, 170))148 self.init_center = read_config('center', ((1, 1), (210, 170)), str_to_tuple, SECTION_MAP)149 ## Show a small cross in the center of the map, default is False (0)150 self.show_cross = read_config('show_cross', 0, int, SECTION_MAP)151 ## Map service to get images, default is Nokia152 self.map_service = read_config('map_service', MAP_SERVERS[NOKIA], str, SECTION_MAP)153 ## cloudMade API key154 self.cloudMade_API = read_config('cloudmade_api', '333d990d389d5e65a7714dd738b2fc77', str, SECTION_MAP)155 ## Initial style ID for the CloudMade maps156 self.cloudMade_styleID = read_config('cloudmade_styleid', 1, int, SECTION_MAP)157 ## Visibility of the scale158 self.scale_visible = read_config('scale_visible', 1, int, SECTION_MAP)159 ## Amount of days used when user selects the Force Update160 self.force_update_days = read_config('force_update_days', 1, int, SECTION_MAP)161 ## auto-refresh frequency in miliseconds162 self.auto_refresh = read_config('auto_refresh', 0, int, SECTION_MAP)163 ## Part of the URL that is used to get the google tiles164 self.google_src = read_config('google_src', '', str, SECTION_MAP)165 ## Show the name/description of the marker in the map166 self.show_marker_name = read_config('show_marker_name', 0, int, SECTION_MAP)167 ## The font color for the name of the marker168 self.marker_font_color = read_config('marker_font_color', '#00CCCC', str, SECTION_MAP)169 ## The font Description for the marker "sans bold 12"170 ## http://www.pygtk.org/docs/pygtk/class-pangofontdescription.html171 self.marker_font_desc = read_config('marker_font_desc', 'normal', str, SECTION_MAP)172 ## Maximum number of threads to download maps173 self.maxthreads = read_config('maxthreads', 4, int, SECTION_MAP)174 ## Time delay before drawing the map overlay175 self.overlay_delay = read_config('overlay_delay', 0.1, float, SECTION_MAP)176 ## Initial map opacity177 self.opacity = read_config('opacity', 0.0, float, SECTION_MAP)178 ## Initial map opacity179 self.draw_track_start_end = read_config('draw_track_start_end', 0, int, SECTION_MAP)180 ## Ruler-track width, default is 3px181 self.ruler_track_width = read_config('ruler_track_width', 3, int, SECTION_MAP)182 ## How often is the GPS updated, default is 1 second183 self.gps_update_rate = read_config('gps_update_rate', 1.0, float, SECTION_GPS)184 ## default increment for gps track saving185 self.gps_increment = read_config('gps_increment', GPS_INCREMENT, int, SECTION_GPS)186 ## GPS-type, GPSd (0) or serial (1), default is GPSd187 self.gps_type = read_config('gps_type', 0, int, SECTION_GPS)188 ## Draw GPS-track, default is 1 (True)189 self.gps_track = read_config('gps_track', 1, int, SECTION_GPS)190 ## GPS-track "interval" in meters, default is 50m191 self.gps_track_interval = read_config('gps_track_interval', 50, int, SECTION_GPS)192 ## GPS-track width, default is 2px193 self.gps_track_width = read_config('gps_track_width', 2, int, SECTION_GPS)194 ## GPS serial port, default is 'none'195 self.gps_serial_port = read_config('gps_serial_port', 'none', str, SECTION_GPS)196 ## GPS serial baudrate, default is 9600197 self.gps_serial_baudrate = read_config('gps_serial_baudrate', 9600, int, SECTION_GPS)198 ## Initial GPS mode, default is GPS_DISABLED199 self.gps_mode = read_config('gps_mode', GPS_DISABLED, int, SECTION_GPS)200 ## Maximum zoom to show the GPS, default is 16201 self.max_gps_zoom = read_config('max_gps_zoom', 16, int, SECTION_GPS)202 ## User agent name203 self.name = read_config('name', NAME, str, SECTION_AGENT)204 ## User agent version205 self.version = read_config('version', VERSION, str, SECTION_AGENT)206 ## User agent webaddress207 self.web_address = read_config('web_address', WEB_ADDRESS, str, SECTION_AGENT)208 ## Write the configuration to the default file209 def save(self):210 self.write()211 ## Write the configuration to the default file212 def get_layer_dir(self, layer):213 if self.oneDirPerMap:214 return os.path.join(self.map_service, LAYER_DIRS[layer])215 else:...
test_config_stub.py
Source:test_config_stub.py
1"""Test LETP config stub.2Use read_config fixture to validate it's expected.3The stub will be used by LETP unit tests.4"""5import pytest6from pytest_letp.lib import swilog7from pytest_letp.lib.modules import SlinkInfo8__copyright__ = "Copyright (C) Sierra Wireless Inc."9COUNT = 010def validate_config(expected_iter, read_config):11 """Validate configured values are set correctly in read_config."""12 for cur_path, cur_val in expected_iter:13 swilog.info("path %s expected value %s" % (cur_path, cur_val))14 if "(" in cur_path:15 # It is an attribute16 attr_path = cur_path.split("(")[0]17 attr = cur_path.split("(")[1].replace(")", "")18 res = read_config.find(attr_path).get(attr)19 else:20 # It is a text21 res = read_config.findtext(cur_path)22 swilog.info("Found %s: %s" % (cur_path, res))23 assert str(res) == str(cur_val), (24 "Expected value not found for %s: expected %s found %s"25 % (cur_path, cur_val, res)26 )27def check_config(request, read_config):28 """Check request's path and expected values."""29 path = request.config.getoption("--path")30 expected_value = request.config.getoption("--expected_value")31 if path and expected_value:32 expected_iter = zip(path, expected_value)33 validate_config(expected_iter, read_config)34def test_cmd_config_set(request, read_config):35 """Test config set from command line."""36 check_config(request, read_config)37@pytest.mark.timeout(5)38def test_config_value(request, test_config):39 """Check a parameter or an attribute value.40 The value can be feed by --path and --expected_value in the command41 line.42 """43 test_config_xml = test_config.get()44 check_config(request, test_config_xml)45 main_config_list = test_config.get_main_config()46 valid_configs = [47 tuple(config.split("="))48 for config in main_config_list49 if "=" in config and not config.endswith("=")50 ]51 validate_config(iter(valid_configs), test_config_xml)52def test_config_same_test_with_2_cfg(read_config):53 """Test should be called twice.54 The same test has different xml configuration in the json file.55 """56 global COUNT57 # First time,58 expected_value = "test" if COUNT == 0 else "test2"59 val = read_config.findtext("foo/bar")60 swilog.info("Found value: %s" % val)61 assert val == expected_value62def test_config_two_xml_with_json_file(read_config):63 """Two tests with different xml configuration in the json file."""64 expected_value = "test"65 val = read_config.findtext("foo/bar")66 swilog.info("Found value: %s" % val)67 assert val == expected_value68def test_config_two_xml_with_json_file_2(read_config):69 """Test should be called twice."""70 expected_value = "test2"71 val = read_config.findtext("foo2/bar")72 swilog.info("Found value: %s" % val)73 assert val == expected_value74@pytest.mark.config("$LETP_TESTS/scenario/config/target_wp750x.xml")75def test_config_value_xml(request, read_config):76 """Test with xml file associated within test."""77 check_config(request, read_config)78@pytest.mark.config(79 "$LETP_TESTS/scenario/config/target_wp750x.xml,$LETP_TESTS/scenario/config/foo.xml"80)81def test_config_value_multi_xml(request, read_config):82 """Test with multiple xml file associated within test."""83 check_config(request, read_config)84def test_config_value_with_json_env_vari(request, read_config):85 """Test environment variable in json file.86 If this function gets called that means,87 the system was able to get $LETP_TESTS path and call88 this function from json file,89 $LETP_TESTS is the env variable used in json file.90 """91 assert request92 assert read_config93 swilog.info("env variable was found")94def test_custom_config_tag_with_attri(read_config):95 """Test custom config arguments tag with attribute."""96 assert read_config.findtext("module/slink3/name") == "/dev/ttyUSB6"97 assert read_config.findtext("module/slink1/name/new_tag") == "new_val"98 assert read_config.find("module/slink3").get("used") == "1"99 assert read_config.findtext("module/slink3/desc") == "mcu"100 assert read_config.findtext("custom/new/tag") == "foo"101 assert (102 read_config.find("module/slink1/name/new_tag").get("new_attri")103 == "new_attri_val"104 )105def test_custom_config_attri_only(read_config):106 """Test custom config arguments attribute only."""107 assert read_config.find("module/slink3").get("used") == "1"108 assert read_config.find("capability/avc").get("used") == "1"109 assert read_config.find("custom/new/tag").get("attri") == "1"110def test_custom_config_tag_only(read_config):111 """Test custom config arguments tag only."""112 assert read_config.findtext("module/slink3/name") == "/dev/ttyUSB6"113 assert read_config.findtext("module/slink1/name/new_tag") == "new_val"114 assert read_config.findtext("module/slink3/desc") == "mcu"115 assert read_config.findtext("custom/new/tag") == "foo"116def test_slink_default_val(read_config):117 """Test default slink config val."""118 assert SlinkInfo.get_num_links(read_config) == 3119 link = SlinkInfo(read_config, "module/slink3")120 assert link.desc().lower() == "cli"121 assert link.speed() == 115200122 assert not link.rtscts()...
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!!