Skip to content

Mutant Info

pyllmut.mutant_lib.mutant_info.MutantInfo

Bases: ResponseInfo

Represents a mutation.

Source code in pyllmut/mutant_lib/mutant_info.py
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class MutantInfo(ResponseInfo):
    """
    Represents a mutation.
    """

    def __init__(
        self,
        prompt_content: str,
        original_module_content: str,
        line_number: int,
        sent_token_count: int,
        response_content: str,
        received_token_count: int,
        mutated_module_content: str,
        diff_content: str,
        pre_code_model: str,
        after_code_model: str,
        pre_code_refined: str,
        after_code_refined: str,
    ):
        """
        Initializes a Mutant instance.

        Args:
            prompt_content (str): The content of the prompt.
            original_module_content (str): The original content of the module before mutation.
            line_number (int): The line number where the mutation was applied.
            sent_token_count (int): The number of sent tokens when using the LLM.
            response_content (str): The response returned from the model.
            received_token_count (int): The number of tokens in the response.
            mutated_module_content (str): The content of the module after applying the mutation.
            diff_content (str): A diff representation of the changes between the original and mutated code.
            pre_code_model (str): The content of the line before mutation, as returned by the model.
            after_code_model (str): The content of the line after mutation, as returned by the model.
            pre_code_refined (str): The actual content of the line before mutation, extracted from the original code.
            after_code_refined (str): The content of the line after mutation, with fixed indentation.
        """
        super().__init__(
            prompt_content,
            original_module_content,
            line_number,
            sent_token_count,
            response_content,
            received_token_count
        )
        self._mutated_module_content = mutated_module_content
        self._diff_content = diff_content
        self._pre_code_model = pre_code_model
        self._after_code_model = after_code_model
        self._pre_code_refined = pre_code_refined
        self._after_code_refined = after_code_refined
        self._mutant_type = MutantType.UNKNOWN

    def __str__(self):
        return self._after_code_model

    def __repr__(self):
        return self._after_code_model

    def get_mutated_module_content(self) -> str:
        """
        Returns the content of the module after applying the mutation.

        Returns:
            str: The mutated module content.
        """
        return self._mutated_module_content

    def get_diff_content(self) -> str:
        """
        Returns a diff representation of the changes between the original and mutated code.

        Returns:
            str: The diff content.
        """
        return self._diff_content

    def get_pre_code_model(self) -> str:
        """
        Returns the content of the line before mutation, as returned by the model.

        Returns:
            str: The pre-mutation code content from the model.
        """
        return self._pre_code_model

    def get_after_code_model(self) -> str:
        """
        Returns the content of the line after mutation, as returned by the model.

        Returns:
            str: The post-mutation code content from the model.
        """
        return self._after_code_model

    def get_pre_code_refined(self) -> str:
        """
        Returns the actual content of the line before mutation, extracted from the original code.

        Returns:
            str: The refined pre-mutation code content.
        """
        return self._pre_code_refined

    def get_after_code_refined(self) -> str:
        """
        Returns the content of the line after mutation, with fixed indentation.

        Returns:
            str: The refined post-mutation code content.
        """
        return self._after_code_refined

    def get_mutant_type(self) -> MutantType:
        """
        Returns the type of the mutant.

        Returns:
            MutantType: The type of the mutant.
        """
        return self._mutant_type

    def set_mutant_type(self, mutant_type: MutantType):
        """
        Sets the type of the mutant (used during mutant classification).

        Args:
            mutant_type (MutantType): The mutant type to set.
        """
        self._mutant_type = mutant_type

get_after_code_model()

Returns the content of the line after mutation, as returned by the model.

Returns:

Name Type Description
str str

The post-mutation code content from the model.

Source code in pyllmut/mutant_lib/mutant_info.py
91
92
93
94
95
96
97
98
def get_after_code_model(self) -> str:
    """
    Returns the content of the line after mutation, as returned by the model.

    Returns:
        str: The post-mutation code content from the model.
    """
    return self._after_code_model

get_after_code_refined()

Returns the content of the line after mutation, with fixed indentation.

Returns:

Name Type Description
str str

The refined post-mutation code content.

Source code in pyllmut/mutant_lib/mutant_info.py
109
110
111
112
113
114
115
116
def get_after_code_refined(self) -> str:
    """
    Returns the content of the line after mutation, with fixed indentation.

    Returns:
        str: The refined post-mutation code content.
    """
    return self._after_code_refined

get_diff_content()

Returns a diff representation of the changes between the original and mutated code.

Returns:

Name Type Description
str str

The diff content.

Source code in pyllmut/mutant_lib/mutant_info.py
73
74
75
76
77
78
79
80
def get_diff_content(self) -> str:
    """
    Returns a diff representation of the changes between the original and mutated code.

    Returns:
        str: The diff content.
    """
    return self._diff_content

get_line_number()

Returns the line number in the module where we want to generate mutants.

Source code in pyllmut/mutant_lib/prompt_info.py
30
31
32
def get_line_number(self) -> int:
    """Returns the line number in the module where we want to generate mutants."""
    return self._line_number

get_mutant_type()

Returns the type of the mutant.

Returns:

Name Type Description
MutantType MutantType

The type of the mutant.

Source code in pyllmut/mutant_lib/mutant_info.py
118
119
120
121
122
123
124
125
def get_mutant_type(self) -> MutantType:
    """
    Returns the type of the mutant.

    Returns:
        MutantType: The type of the mutant.
    """
    return self._mutant_type

get_mutated_module_content()

Returns the content of the module after applying the mutation.

Returns:

Name Type Description
str str

The mutated module content.

Source code in pyllmut/mutant_lib/mutant_info.py
64
65
66
67
68
69
70
71
def get_mutated_module_content(self) -> str:
    """
    Returns the content of the module after applying the mutation.

    Returns:
        str: The mutated module content.
    """
    return self._mutated_module_content

get_original_module_content()

Returns the content of the module we plan to generate mutants for.

Source code in pyllmut/mutant_lib/prompt_info.py
26
27
28
def get_original_module_content(self) -> str:
    """Returns the content of the module we plan to generate mutants for."""
    return self._original_module_content

get_pre_code_model()

Returns the content of the line before mutation, as returned by the model.

Returns:

Name Type Description
str str

The pre-mutation code content from the model.

Source code in pyllmut/mutant_lib/mutant_info.py
82
83
84
85
86
87
88
89
def get_pre_code_model(self) -> str:
    """
    Returns the content of the line before mutation, as returned by the model.

    Returns:
        str: The pre-mutation code content from the model.
    """
    return self._pre_code_model

get_pre_code_refined()

Returns the actual content of the line before mutation, extracted from the original code.

Returns:

Name Type Description
str str

The refined pre-mutation code content.

Source code in pyllmut/mutant_lib/mutant_info.py
100
101
102
103
104
105
106
107
def get_pre_code_refined(self) -> str:
    """
    Returns the actual content of the line before mutation, extracted from the original code.

    Returns:
        str: The refined pre-mutation code content.
    """
    return self._pre_code_refined

get_prompt_content()

Returns the content of the prompt.

Source code in pyllmut/mutant_lib/prompt_info.py
22
23
24
def get_prompt_content(self) -> str:
    """Returns the content of the prompt."""
    return self._prompt_content

get_received_token_count()

Returns the number of tokens in the response.

Source code in pyllmut/mutant_lib/response_info.py
44
45
46
def get_received_token_count(self) -> int:
    """Returns the number of tokens in the response."""
    return self._received_token_count

get_response_content()

Returns the response returned from the model.

Source code in pyllmut/mutant_lib/response_info.py
40
41
42
def get_response_content(self) -> str:
    """Returns the response returned from the model."""
    return self._response_content

get_sent_token_count()

Returns the number of sent tokens when using the LLM.

Source code in pyllmut/mutant_lib/response_info.py
36
37
38
def get_sent_token_count(self) -> int:
    """Returns the number of sent tokens when using the LLM."""
    return self._sent_token_count

set_mutant_type(mutant_type)

Sets the type of the mutant (used during mutant classification).

Parameters:

Name Type Description Default
mutant_type MutantType

The mutant type to set.

required
Source code in pyllmut/mutant_lib/mutant_info.py
127
128
129
130
131
132
133
134
def set_mutant_type(self, mutant_type: MutantType):
    """
    Sets the type of the mutant (used during mutant classification).

    Args:
        mutant_type (MutantType): The mutant type to set.
    """
    self._mutant_type = mutant_type