How to use get_visit_methods method in refurb

Best Python code snippet using refurb_python

test_visitor.py

Source:test_visitor.py Github

copy

Full Screen

...16 This forces method generation but calling the methods does nothing.17 """18 checks = Checks(list, {ty: [] for ty in METHOD_NODE_MAPPINGS.values()})19 return RefurbVisitor(checks, Settings())20def get_visit_methods(21 visitor: RefurbVisitor,22) -> Iterable[tuple[str, type[Node]]]:23 """24 Find visitor methods in the instance's __dict__ (those that have been25 generated in __init__) and in the class' __dict__ (the ones that are26 overridden directly in the class).27 Not using inspect.getmembers because that goes too deep into the parents28 and that would deafeat the purpose of this, which is testing that the29 methods are defined in the RefurbVisitor.30 """31 method_sources = itertools.chain(32 visitor.__dict__.items(), visitor.__class__.__dict__.items()33 )34 for method_name, method in method_sources:35 if callable(method) and method_name.startswith("visit_"):36 yield method_name, method37def test_visitor_generation(dummy_visitor: RefurbVisitor) -> None:38 """39 Ensure the visitor creates all expected methods with the right types (The40 ones listed in refurb.visitor.METHOD_NODE_MAPPINGS).41 """42 visitor_mappings: VisitorNodeTypeMap = {}43 for method_name, method in get_visit_methods(dummy_visitor):44 method_types = typing.get_type_hints(method)45 assert "o" in method_types, f"No 'o' parameter in method {method_name}"46 node_type = method_types["o"]47 visitor_mappings[method_name] = node_type48 assert visitor_mappings == METHOD_NODE_MAPPINGS49def test_mypy_consistence() -> None:50 """51 Ensure the visitor method name to node type mappings used in refurb are52 in sync with the ones of mypy.53 This is meant as a failsafe, especially when the mypy dependency is54 upgraded.55 If this fails, review the mappings in refurb.visitor.METHOD_NODE_MAPPINGS.56 """57 mypy_visitor_mapping = get_mypy_visitor_mapping()...

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