def append_statement( self, test_case: tc.TestCase, statement: stmt.Statement, allow_none: bool = True, ) -> None: """Appends a statement to a test case. Args: test_case: The test case statement: The statement to append allow_none: Whether or not parameter variables can hold None values Raises: ConstructionFailedException: if construction of an object failed """ if isinstance(statement, par_stmt.ConstructorStatement): self.add_constructor( test_case, statement.accessible_object(), position=test_case.size(), allow_none=allow_none, ) elif isinstance(statement, par_stmt.MethodStatement): self.add_method( test_case, statement.accessible_object(), position=test_case.size(), allow_none=allow_none, ) elif isinstance(statement, par_stmt.FunctionStatement): self.add_function( test_case, statement.accessible_object(), position=test_case.size(), allow_none=allow_none, ) elif isinstance(statement, f_stmt.FieldStatement): self.add_field( test_case, statement.field, position=test_case.size(), ) elif isinstance(statement, prim.PrimitiveStatement): self.add_primitive(test_case, statement, position=test_case.size()) else: raise ConstructionFailedException( f"Unknown statement type: {statement}")
def change_random_call(self, test_case: tc.TestCase, statement: stmt.Statement) -> bool: """Change the call represented by this statement to another one. Args: test_case: The test case statement: The new statement Returns: Whether or not the operation was successful """ if statement.return_value.is_type_unknown(): return False objects = test_case.get_all_objects(statement.get_position()) type_ = statement.return_value.variable_type assert type_, "Cannot change change call, when type is unknown" calls = self._get_possible_calls(type_, objects) acc_object = statement.accessible_object() if acc_object in calls: calls.remove(acc_object) if len(calls) == 0: return False call = randomness.choice(calls) try: self.change_call(test_case, statement, call) return True except ConstructionFailedException: self._logger.info("Failed to change call for statement.") return False