se2p / pynguin

The PYthoN General UnIt Test geNerator is a test-generation tool for Python
https://www.pynguin.eu
MIT License
1.22k stars 74 forks source link

Integrate Mutpy functionalities into the project instead of relying on the library #64

Closed BergLucas closed 4 weeks ago

BergLucas commented 3 months ago

Introduction

Hello,

I'm currently doing a master's thesis on improving automatic test generation for Python code that uses C libraries. To do this, I'm using Pynguin as a base and I've tried a few things to improve it.

Problem

While writing some code, I encountered some problems with memory leaks and slowness in the generation of assertions by mutation analysis. While trying to fix this, I noticed that the current integration of MutPy with Pynguin made it quite complicated to fix the problems I have.

Proposed solution

Given that MutPy hasn't been updated for a long time, that the version currently used is a fork and that Pynguin only uses a subset of what's available in MutPy, I thought it might be interesting to integrate the used part of MutPy into Pynguin. Given that this could potentially be interesting even without what I tried for my thesis, I thought that making a pull request to propose the change would be a good idea.

Change summary

To summarise what was done, I first added the original MutPy files that were used in the project and then I gradually modified them to integrate them into the project. I added type hints, specifications and I refactored certain parts of complicated code into more understandable code with better comments. I've tried to make the commits as small as possible each time to make the process that led from the original code to the final code more explicit.

In addition, MutPy tests have been converted from unittest to pytest to ensure that the refactoring didn't create any bugs. During this conversion, some bugs were discovered in MutPy such as the modification of the original AST in the HidingVariableDeletion operator and the generation of several identical mutants in certain cases when several visitor functions are present for the same node. There was also a potential "bug" in Pynguin, as RandomHOMStrategy didn't use Pynguin's random generator, so results could potentially be different even with the same seed.

Conclusion

It's a pretty big pull request, sorry, but there's only a very little Pynguin code that's been modified to better integrate the code from MutPy and to make it easier to extend it (because that's why I did it in the first place) so it shouldn't be too hard to review.

Feel free to ask questions about my implementation choices or to say that you think it's a bad idea.

Have a nice day and thanks for having created Pynguin!

stephanlukasczyk commented 3 months ago

Hi @BergLucas ,

Thank you for this PR. I'll walk over it next week. One question upfront: did you copy the code from MutPy or did you actually reimplement it? I am asking because of license texts; Pynguin uses MIT but the original code of MutPy uses Apache license, and I am from the top of my head not sure whether this allows a relicensing.

BergLucas commented 3 months ago

Hi @stephanlukasczyk,

Damn, I forgot to check the licenses. But yes, I copied the original Mutpy code because I wanted to make sure that the changes I made didn't break Pynguin. I've made a lot of changes to the code but I suppose it's still under the original licence. I could reimplement Mutpy's functionalities from scratch if you think it's interesting, but it'll still look a bit like Mutpy at the end because some mutations are basic and there's not really a way to do them differently from Mutpy.

stephanlukasczyk commented 3 months ago

No worries @BergLucas . Do you mind to contact me through email? I'd like to setup a call, because I'm highly interested in what your work and plans on Pynguin are about. My work email address can be found from our chair's web page https://www.fim.uni-passau.de/en/chair-for-software-engineering-ii/team