How to use _simple_merge_dict method in prospector

Best Python code snippet using prospector_python

profile.py

Source:profile.py Github

copy

Full Screen

...116def _ensure_list(value):117 if isinstance(value, list):118 return value119 return [value]120def _simple_merge_dict(priority, base):121 out = dict(base.items())122 out.update(dict(priority.items()))123 return out124def _merge_tool_config(priority, base):125 out = dict(base.items())126 # add options that are missing, but keep existing options from the priority dictionary127 # TODO: write a unit test for this :-|128 out["options"] = _simple_merge_dict(priority.get("options", {}), base.get("options", {}))129 # copy in some basic pieces130 for key in ("run", "load-plugins"):131 value = priority.get(key, base.get(key))132 if value is not None:133 out[key] = value134 # anything enabled in the 'priority' dict is removed135 # from 'disabled' in the base dict and vice versa136 base_disabled = base.get("disable") or []137 base_enabled = base.get("enable") or []138 pri_disabled = priority.get("disable") or []139 pri_enabled = priority.get("enable") or []140 out["disable"] = list(set(pri_disabled) | (set(base_disabled) - set(pri_enabled)))141 out["enable"] = list(set(pri_enabled) | (set(base_enabled) - set(pri_disabled)))142 return out143def _merge_profile_dict(priority, base):144 # copy the base dict into our output145 out = dict(base.items())146 for key, value in priority.items():147 if key in (148 "strictness",149 "doc-warnings",150 "test-warnings",151 "member-warnings",152 "output-format",153 "autodetect",154 "max-line-length",155 "pep8",156 ):157 # some keys are simple values which are overwritten158 out[key] = value159 elif key in (160 "ignore",161 "ignore-patterns",162 "ignore-paths",163 "uses",164 "requirements",165 "python-targets",166 "output-target",167 ):168 # some keys should be appended169 out[key] = _ensure_list(value) + _ensure_list(base.get(key, []))170 elif key in TOOLS:171 # this is tool config!172 out[key] = _merge_tool_config(value, base.get(key, {}))173 return out174def _determine_strictness(profile_dict, inherits):175 for profile in inherits:176 if profile.startswith("strictness_"):177 return None, False178 strictness = profile_dict.get("strictness")179 if strictness is None:180 return None, False181 return ("strictness_%s" % strictness), True182def _determine_pep8(profile_dict):183 pep8 = profile_dict.get("pep8")184 if pep8 == "full":185 return "full_pep8", True186 elif pep8 == "none":187 return "no_pep8", True188 elif isinstance(pep8, dict) and pep8.get("full", False):189 return "full_pep8", False190 return None, False191def _determine_doc_warnings(profile_dict):192 doc_warnings = profile_dict.get("doc-warnings")193 if doc_warnings is None:194 return None, False195 return ("doc_warnings" if doc_warnings else "no_doc_warnings"), True196def _determine_test_warnings(profile_dict):197 test_warnings = profile_dict.get("test-warnings")198 if test_warnings is None:199 return None, False200 return (None if test_warnings else "no_test_warnings"), True201def _determine_member_warnings(profile_dict):202 member_warnings = profile_dict.get("member-warnings")203 if member_warnings is None:204 return None, False205 return ("member_warnings" if member_warnings else "no_member_warnings"), True206def _determine_implicit_inherits(profile_dict, already_inherits, shorthands_found):207 # Note: the ordering is very important here - the earlier items208 # in the list have precedence over the later items. The point of209 # the doc/test/pep8 profiles is usually to restore items which were210 # turned off in the strictness profile, so they must appear first.211 implicit = [212 ("pep8", _determine_pep8(profile_dict)),213 ("docs", _determine_doc_warnings(profile_dict)),214 ("tests", _determine_test_warnings(profile_dict)),215 ("strictness", _determine_strictness(profile_dict, already_inherits)),216 ("members", _determine_member_warnings(profile_dict)),217 ]218 inherits = []219 for shorthand_name, determined in implicit:220 if shorthand_name in shorthands_found:221 continue222 extra_inherits, shorthand_found = determined223 if not shorthand_found:224 continue225 shorthands_found.add(shorthand_name)226 if extra_inherits is not None:227 inherits.append(extra_inherits)228 return inherits, shorthands_found229def _append_profiles(name, profile_path, data, inherit_list, allow_shorthand=False):230 new_data, new_il, _ = _load_profile(name, profile_path, allow_shorthand=allow_shorthand)231 data.update(new_data)232 inherit_list += new_il233 return data, inherit_list234def _load_and_merge(235 name_or_path, profile_path, allow_shorthand: bool = True, forced_inherits: List[str] = None236) -> Tuple[Dict[str, Any], List[str]]:237 # First simply load all of the profiles and those that it explicitly inherits from238 data, inherit_list, shorthands_found = _load_profile(239 name_or_path,240 profile_path,241 allow_shorthand=allow_shorthand,242 forced_inherits=forced_inherits or [],243 )244 if allow_shorthand:245 if "docs" not in shorthands_found:246 data, inherit_list = _append_profiles("no_doc_warnings", profile_path, data, inherit_list)247 if "members" not in shorthands_found:248 data, inherit_list = _append_profiles("no_member_warnings", profile_path, data, inherit_list)249 if "tests" not in shorthands_found:250 data, inherit_list = _append_profiles("no_test_warnings", profile_path, data, inherit_list)251 if "strictness" not in shorthands_found:252 # if no strictness was specified, then we should manually insert the medium strictness253 for inherit in inherit_list:254 if inherit.startswith("strictness_"):255 break256 else:257 data, inherit_list = _append_profiles("strictness_medium", profile_path, data, inherit_list)258 # Now we merge all of the values together, from 'right to left' (ie, from the259 # top of the inheritance tree to the bottom). This means that the lower down260 # values overwrite those from above, meaning that the initially provided profile261 # has precedence.262 merged = {}263 for name in inherit_list[::-1]:264 priority = data[name]265 merged = _merge_profile_dict(priority, merged)266 return merged, inherit_list267def _transform_legacy(profile_dict):268 """269 After pep8 was renamed to pycodestyle, this pre-filter just moves profile270 config blocks using the old name to use the new name, merging if both are271 specified.272 Same for pep257->pydocstyle273 """274 out = {}275 # copy in existing pep8/pep257 using new names to start276 if "pycodestyle" in profile_dict:277 out["pycodestyle"] = profile_dict["pycodestyle"]278 if "pydocstyle" in profile_dict:279 out["pydocstyle"] = profile_dict["pydocstyle"]280 # pep8 is tricky as it's overloaded as a tool configuration and a shorthand281 # first, is this the short "pep8: full" version or a configuration of the282 # pycodestyle tool using the old name?283 if "pep8" in profile_dict:284 pep8conf = profile_dict["pep8"]285 if isinstance(pep8conf, dict):286 # merge in with existing config if there is any287 out["pycodestyle"] = _simple_merge_dict(out.get("pycodestyle", {}), pep8conf)288 else:289 # otherwise it's shortform, just copy it in directly290 out["pep8"] = pep8conf291 del profile_dict["pep8"]292 if "pep257" in profile_dict:293 out["pydocstyle"] = _simple_merge_dict(out.get("pydocstyle", {}), profile_dict["pep257"])294 del profile_dict["pep257"]295 # now just copy the rest in296 for key, value in profile_dict.items():297 if key in ("pycodestyle", "pydocstyle"):298 # already handled these299 continue300 out[key] = value301 return out302def _load_profile(303 name_or_path,304 profile_path,305 shorthands_found=None,306 already_loaded=None,307 allow_shorthand=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 prospector 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