Best Python code snippet using refurb_python
test_postprocess.py
Source: test_postprocess.py
1# This file is part of Pynguin.2#3# SPDX-FileCopyrightText: 2019â2022 Pynguin Contributors4#5# SPDX-License-Identifier: LGPL-3.0-or-later6#7from unittest import mock8from unittest.mock import MagicMock, call9import pytest10import pynguin.ga.postprocess as pp11import pynguin.ga.testcasechromosome as tcc12import pynguin.testcase.defaulttestcase as dtc13import pynguin.testcase.statement as stmt14from pynguin.analyses.module import ModuleTestCluster15from pynguin.assertion.assertion import ExceptionAssertion16from pynguin.utils.orderedset import OrderedSet17def test_not_failing():18 trunc = pp.ExceptionTruncation()19 test_case = MagicMock()20 chromosome = MagicMock(test_case=test_case)21 chromosome.is_failing.return_value = False22 trunc.visit_test_case_chromosome(chromosome)23 test_case.chop.assert_not_called()24def test_simple_chop():25 trunc = pp.ExceptionTruncation()26 test_case = MagicMock()27 chromosome = MagicMock(test_case=test_case)28 chromosome.is_failing.return_value = True29 chromosome.get_last_mutatable_statement.return_value = 4230 trunc.visit_test_case_chromosome(chromosome)31 test_case.chop.assert_called_once_with(42)32def test_suite_chop():33 trunc = pp.ExceptionTruncation()34 chromosome = MagicMock()35 suite = MagicMock(test_case_chromosomes=[chromosome, chromosome])36 trunc.visit_test_suite_chromosome(suite)37 chromosome.accept.assert_has_calls([call(trunc), call(trunc)])38def test_suite_assertion_minimization():39 ass_min = pp.AssertionMinimization()40 chromosome = MagicMock()41 suite = MagicMock(test_case_chromosomes=[chromosome, chromosome])42 ass_min.visit_test_suite_chromosome(suite)43 chromosome.accept.assert_has_calls([call(ass_min), call(ass_min)])44def test_test_case_assertion_minimization(default_test_case):45 ass_min = pp.AssertionMinimization()46 statement = stmt.IntPrimitiveStatement(default_test_case)47 assertion_1 = MagicMock(48 checked_instructions=[MagicMock(lineno=1), MagicMock(lineno=2)]49 )50 assertion_2 = MagicMock(checked_instructions=[MagicMock(lineno=1)])51 statement.add_assertion(assertion_1)52 statement.add_assertion(assertion_2)53 default_test_case.add_statement(statement)54 chromosome = tcc.TestCaseChromosome(test_case=default_test_case)55 ass_min.visit_test_case_chromosome(chromosome)56 assert ass_min.remaining_assertions == OrderedSet([assertion_1])57 assert ass_min.deleted_assertions == OrderedSet([assertion_2])58 assert default_test_case.get_assertions() == [assertion_1]59def test_test_case_assertion_minimization_does_not_remove_exception_assertion(60 default_test_case,61):62 ass_min = pp.AssertionMinimization()63 statement = stmt.IntPrimitiveStatement(default_test_case)64 assertion_1 = MagicMock(65 checked_instructions=[MagicMock(lineno=1), MagicMock(lineno=2)]66 )67 assertion_2 = MagicMock(68 spec=ExceptionAssertion, checked_instructions=[MagicMock(lineno=1)]69 )70 statement.add_assertion(assertion_1)71 statement.add_assertion(assertion_2)72 default_test_case.add_statement(statement)73 chromosome = tcc.TestCaseChromosome(test_case=default_test_case)74 ass_min.visit_test_case_chromosome(chromosome)75 assert ass_min.remaining_assertions == OrderedSet([assertion_1, assertion_2])76 assert ass_min.deleted_assertions == OrderedSet()77 assert default_test_case.get_assertions() == [assertion_1, assertion_2]78def test_test_case_assertion_minimization_does_not_remove_empty_assertion(79 default_test_case,80):81 ass_min = pp.AssertionMinimization()82 statement = stmt.IntPrimitiveStatement(default_test_case)83 assertion_1 = MagicMock(checked_instructions=[])84 statement.add_assertion(assertion_1)85 default_test_case.add_statement(statement)86 chromosome = tcc.TestCaseChromosome(test_case=default_test_case)87 ass_min.visit_test_case_chromosome(chromosome)88 assert ass_min.remaining_assertions == OrderedSet([assertion_1])89 assert ass_min.deleted_assertions == OrderedSet()90 assert default_test_case.get_assertions() == [assertion_1]91def test_test_case_postprocessor_suite():92 dummy_visitor = MagicMock()93 tcpp = pp.TestCasePostProcessor([dummy_visitor])94 chromosome = MagicMock()95 suite = MagicMock(test_case_chromosomes=[chromosome, chromosome])96 tcpp.visit_test_suite_chromosome(suite)97 chromosome.accept.assert_has_calls([call(tcpp), call(tcpp)])98def test_test_case_postprocessor_test():99 dummy_visitor = MagicMock()100 tcpp = pp.TestCasePostProcessor([dummy_visitor])101 test_case = MagicMock()102 test_chromosome = MagicMock(test_case=test_case)103 tcpp.visit_test_case_chromosome(test_chromosome)104 test_case.accept.assert_has_calls([call(dummy_visitor)])105def test_unused_primitives_visitor():106 visitor = pp.UnusedStatementsTestCaseVisitor()107 statement = MagicMock()108 test_case = MagicMock(statements=[statement])109 visitor.visit_default_test_case(test_case)110 assert statement.accept.call_count == 1111# TODO(fk) replace with ast_to_stmt112def test_remove_integration(constructor_mock):113 cluster = ModuleTestCluster(0)114 test_case = dtc.DefaultTestCase(cluster)115 test_case.add_statement(stmt.IntPrimitiveStatement(test_case))116 test_case.add_statement(stmt.FloatPrimitiveStatement(test_case))117 int0 = stmt.IntPrimitiveStatement(test_case)118 test_case.add_statement(int0)119 list0 = stmt.ListStatement(120 test_case, cluster.type_system.convert_type_hint(list[int]), [int0.ret_val]121 )122 test_case.add_statement(list0)123 float0 = stmt.FloatPrimitiveStatement(test_case)124 test_case.add_statement(float0)125 ctor0 = stmt.ConstructorStatement(126 test_case, constructor_mock, {"foo": float0.ret_val, "bar": list0.ret_val}127 )128 test_case.add_statement(ctor0)129 assert test_case.size() == 6130 visitor = pp.UnusedStatementsTestCaseVisitor()131 test_case.accept(visitor)132 assert test_case.statements == [int0, list0, float0, ctor0]133@pytest.mark.parametrize(134 "statement_type, func",135 [136 ("visit_int_primitive_statement", "_handle_collection_or_primitive"),137 ("visit_float_primitive_statement", "_handle_collection_or_primitive"),138 ("visit_string_primitive_statement", "_handle_collection_or_primitive"),139 ("visit_bytes_primitive_statement", "_handle_collection_or_primitive"),140 ("visit_boolean_primitive_statement", "_handle_collection_or_primitive"),141 ("visit_bytes_primitive_statement", "_handle_collection_or_primitive"),142 ("visit_enum_statement", "_handle_collection_or_primitive"),143 ("visit_none_statement", "_handle_collection_or_primitive"),144 ("visit_constructor_statement", "_handle_remaining"),145 ("visit_method_statement", "_handle_remaining"),146 ("visit_function_statement", "_handle_remaining"),147 ("visit_list_statement", "_handle_collection_or_primitive"),148 ("visit_set_statement", "_handle_collection_or_primitive"),149 ("visit_tuple_statement", "_handle_collection_or_primitive"),150 ("visit_dict_statement", "_handle_collection_or_primitive"),151 ],152)153def test_all_statements(statement_type, func):154 visitor = pp.UnusedPrimitiveOrCollectionStatementVisitor()155 with mock.patch.object(visitor, func) as func:156 visitor.__getattribute__(statement_type)(MagicMock())157 func.assert_called_once()158@pytest.mark.parametrize(159 "statement_type",160 [161 "visit_field_statement",162 "visit_assignment_statement",163 ],164)165def test_not_implemented_statements(statement_type):166 visitor = pp.UnusedPrimitiveOrCollectionStatementVisitor()167 with pytest.raises(NotImplementedError):...
test_visitor.py
Source: test_visitor.py
...8from refurb.visitor import METHOD_NODE_MAPPINGS, RefurbVisitor9from refurb.visitor.mapping import VisitorNodeTypeMap10from .mypy_visitor import get_mypy_visitor_mapping11@pytest.fixture12def dummy_visitor() -> RefurbVisitor:13 """14 This fixture provides a RefurbVisitor instance with a visit method for each15 possible node, but no checks to run.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)....
__init__.py
Source: __init__.py
1""" Tools for parsing and handling expressions """2from .constraint import ConstraintExpression3from .selection import SelectionExpression4from .update import UpdateExpression5from .visitor import DummyVisitor, Visitor, dummy_visitor6__all__ = [7 "ConstraintExpression",8 "SelectionExpression",9 "UpdateExpression",10 "DummyVisitor",11 "Visitor",12 "dummy_visitor",...
Check out the latest blogs from LambdaTest on this topic:
In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.
Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.
In my last blog, I investigated both the stateless and the stateful class of model-based testing. Both have some advantages and disadvantages. You can use them for different types of systems, depending on whether a stateful solution is required or a stateless one is enough. However, a better solution is to use an aggregate technique that is appropriate for each system. Currently, the only aggregate solution is action-state testing, introduced in the book Paradigm Shift in Software Testing. This method is implemented in Harmony.
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
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.
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!!