Skip to content

Leka test#37

Closed
leka-k wants to merge 12 commits intoLeka_mainfrom
Leka_test
Closed

Leka test#37
leka-k wants to merge 12 commits intoLeka_mainfrom
Leka_test

Conversation

@leka-k
Copy link
Collaborator

@leka-k leka-k commented Jun 13, 2025

No description provided.

def _check_methods(C, *methods):
mro = C.__mro__
for method in methods:
for B in mro:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [CAMILA] reported by reviewdog 🐶
[pysnooper.utils.x__check_methods__mutmut_1] Survived mutant. Changed mro = C.__mro__ to mro = None
Why: The mutant changes the value of the variable 'mro' in the function '_check_methods' to 'None', which is not a valid type. This change makes the code behave differently, as the 'for B in mro' loop will not execute if 'mro' is set to None.
How to kill: The mutant can be killed by adding a test that specifically checks for the case where 'mro' is None. For example, a test function could be written as follows:
Test:

def test_check_methods():
    class MyClass:
        pass
    assert _check_methods(MyClass, '__str__') == []

for B in mro:
if method in B.__dict__:
if B.__dict__[method] is None:
return NotImplemented

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [CAMILA] reported by reviewdog 🐶
[pysnooper.utils.x__check_methods__mutmut_2] Survived mutant. Changed if method in B.__dict__: to if method not in B.__dict__:
Why: The mutant survived because the condition in the if statement was negated, causing the method to be called even when it should not have been. This was likely done as a way to fix a bug or make the code more readable, but it introduced a new issue: the method may not always be implemented properly, leading to incorrect behavior.
How to kill: To detect this mutant, you can write a test that specifically checks for the expected behavior of the method when it is called. For example, if the method should return 'NotImplemented' when the object does not have the method, you can write a test that calls the method on an object with the method and asserts that the result is 'NotImplemented'. Additionally, you can also add additional tests to ensure that the method is properly implemented and returns the expected results under different conditions.
Test:

def test_method_not_implemented():
    
    # Create an object without the method
    obj = MyObject()
    
    # Call the method on the object
    result = obj.my_method()
    
    # Assert that the result is 'NotImplemented'
    assert result is NotImplemented

if method in B.__dict__:
if B.__dict__[method] is None:
return NotImplemented
break

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [CAMILA] reported by reviewdog 🐶
[pysnooper.utils.x__check_methods__mutmut_3] Survived mutant. Changed if B.__dict__[method] is None: to if B.__dict__[method] is not None:
Why: The mutant survived because the if statement in line 17 is not checking for the correct condition. The original code checks if B.__dict__[method] is None, but the mutated code checks if it is not None.
How to kill: The mutant can be killed by adding a test that asserts that B.__dict__[method] is actually None. This can be done using pytest's built-in support for mocking and monkeypatching, or by creating a custom test fixture that overrides the __dict__ attribute of the class with a mock object.
Test:

def test_null_method():
    from pysnooper.utils import methods_that_need_wrapping
    B = MagicMock()
    B.__dict__['method'] = None
    assert methods_that_need_wrapping(B) == NotImplemented

return NotImplemented
break
else:
return NotImplemented

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [CAMILA] reported by reviewdog 🐶
[pysnooper.utils.x__check_methods__mutmut_4] Survived mutant. Changed break to return
Why: The mutant changes the behavior of the if statement by adding a return statement after the break keyword, which causes the method to return early and not execute the rest of the code block. This change in behavior can cause the method to return a different value than it would have without the mutation.
How to kill: The test function should check that the method returns the expected value regardless of whether the if statement is executed or not. One way to do this is by using a combination of assert_called_once_with() and assert_not_called(). The former asserts that the mocked method was called once with the expected arguments, while the latter asserts that it was not called.
Test:

def test_my_function():
    
    # Arrange
    from unittest.mock import patch
    from my_module import my_function
    
    @patch('my_module.B.__dict__', {'method': None})
    def test_my_function():
        # Act
        result = my_function()
        
        # Assert
        assert result == 'expected value'
        assert B.__dict__.called_once_with('method')
        assert not B.__dict__.called

@leka-k leka-k closed this Jun 13, 2025
@leka-k leka-k deleted the Leka_test branch June 13, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants