Best Python code snippet using refurb_python
test_graphs_models.py
Source: test_graphs_models.py
1from django.test import TestCase2from mdta.apps.graphs.models import EdgeType, Edge, NodeType, Node3from mdta.apps.projects.models import Project, Module4class NodeTypeTest(TestCase):5 def setUp(self):6 self.type_db = NodeType.objects.create(7 name='DataQueries Database',8 keys=['InputData'],9 subkeys=['Inputs, Outputs']10 )11 self.type_prompt = NodeType.objects.create(12 name='Menu Prompt',13 keys=['Verbiage', 'TranslateVerbiage', 'NonStandardFail', 'TextToSpeech'],14 subkeys=['OnFailGoTo', 'NM1', 'NI1']15 )16 self.type_transfer = NodeType.objects.create(17 name='dtmp',18 keys=['TransferNumber'],19 subkeys=['']20 )21 def test_keys_data_name_with_data_node(self):22 self.assertEqual(self.type_db.keys_data_name, self.type_db.keys[0])23 def test_keys_data_name_without_data_node(self):24 self.assertEqual(self.type_prompt.keys_data_name, None)25 def test_subkeys_data_name_with_data_node(self):26 self.assertEqual(self.type_db.subkeys_data_name, self.type_db.subkeys)27 def test_subkeys_data_name_without_data_node_with_subkeys(self):28 self.assertEqual(self.type_prompt.subkeys_data_name, 'OnFailGoTo')29 def test_subkeys_data_name_without_data_node_without_subkeys(self):30 self.assertEqual(self.type_transfer.subkeys_data_name, None)31class EdgeTypeTest(TestCase):32 def setUp(self):33 self.type_data = EdgeType.objects.create(34 name='data edge',35 keys=['OutputData', 'Invisible'],36 subkeys=['Outputs']37 )38 self.type_precondition = EdgeType.objects.create(39 name='pre condition',40 keys=['OutputData', 'Invisible'],41 subkeys=['Condition']42 )43 self.type_dtmf = EdgeType.objects.create(44 name='dtmf',45 keys=['Press', 'Invisible'],46 subkeys=['']47 )48 def test_keys_data_name_data(self):49 self.assertEqual(self.type_data.keys_data_name, 'OutputData')50 def test_keys_data_name_precondition(self):51 self.assertEqual(self.type_precondition.keys_data_name, 'OutputData')52 def test_keys_data_name_else(self):53 self.assertEqual(self.type_dtmf.keys_data_name, None)54 def test_subkeys_data_name_with_subkeys(self):55 self.assertEqual(self.type_data.subkeys_data_name, 'Outputs')56 self.assertEqual(self.type_precondition.subkeys_data_name, 'Condition')57 def test_subkeys_data_name_without_subkeys(self):58 self.assertEqual(self.type_dtmf.subkeys_data_name, None)59class NodeTest(TestCase):60 def setUp(self):61 self.test_header = Module.objects.create(62 name='test header'63 )64 self.project = Project.objects.create(65 name='Test Project',66 test_header=self.test_header67 )68 self.module = Module.objects.create(69 name='module1',70 project=self.project71 )72 self.node_type_prompt = NodeType.objects.create(73 name='Menu Prompt',74 keys=['Verbiage', 'TranslateVerbiage', 'NonStandardFail', 'TextToSpeech'],75 subkeys=['OnFailGoTo', 'NM1', 'NI1']76 )77 def test_new_node_to_test_header(self):78 th = Node.objects.create(79 name='th start',80 module=self.test_header,81 type=self.node_type_prompt82 )83 self.assertEqual(th.module.name, self.test_header.name)84 def test_new_node_to_module(self):85 node = Node.objects.create(86 name='th start',87 module=self.module,88 type=self.node_type_prompt89 )90 self.assertEqual(node.module.name, self.module.name)...
gen.py
Source: gen.py
...62 if error_code.prefix == prefix:63 highest = max(highest, error_code.id + 1)64 return highest65NODES: dict[str, type] = {x.__name__: x for x in METHOD_NODE_MAPPINGS.values()}66def node_type_prompt() -> list[str]:67 return sorted(68 fzf(69 list(NODES.keys()), args=["--prompt", "type> ", "--multi"]70 ).splitlines()71 )72def filename_prompt() -> Path:73 return Path(74 fzf(75 None,76 args=[77 "--prompt",78 "filename> ",79 "--print-query",80 "--query",81 "refurb/checks/",82 ],83 ).splitlines()[0]84 )85def prefix_prompt() -> str:86 return fzf(87 [""], args=["--prompt", "prefix> ", "--print-query", "--query", "FURB"]88 )89def build_imports(names: list[str]) -> str:90 modules: defaultdict[str, list[str]] = defaultdict(list)91 for name in names:92 modules[NODES[name].__module__].append(name)93 return "\n".join(94 f"from {module} import {', '.join(names)}"95 for module, names in sorted(modules.items(), key=lambda x: x[0])96 )97def main() -> None:98 selected = node_type_prompt()99 file = filename_prompt()100 if file.suffix != ".py":101 print('refurb: File must end in ".py"')102 sys.exit(1)103 prefix = prefix_prompt()104 template = FILE_TEMPLATE.format(105 accept_type=" | ".join(selected),106 imports=build_imports(selected),107 prefix=prefix,108 id=get_next_error_id(prefix) or 100,109 pattern=" | ".join(f"{x}()" for x in selected),110 )111 with suppress(FileExistsError):112 file.parent.mkdir(parents=True, exist_ok=True)...
Check out the latest blogs from LambdaTest on this topic:
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
Entering the world of testers, one question started to formulate in my mind: “what is the reason that bugs happen?”.
Are members of agile teams different from members of other teams? Both yes and no. Yes, because some of the behaviors we observe in agile teams are more distinct than in non-agile teams. And no, because we are talking about individuals!
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!!