{"id":17119242,"url":"https://github.com/xhacker/mutpy","last_synced_at":"2025-03-24T02:19:33.132Z","repository":{"id":143097965,"uuid":"56827947","full_name":"xhacker/mutpy","owner":"xhacker","description":"Forked from https://bitbucket.org/khalas/mutpy","archived":false,"fork":false,"pushed_at":"2016-04-26T00:04:28.000Z","size":1086,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-29T08:24:26.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xhacker.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-22T05:13:46.000Z","updated_at":"2016-04-22T05:14:12.000Z","dependencies_parsed_at":"2023-04-02T13:19:16.741Z","dependency_job_id":null,"html_url":"https://github.com/xhacker/mutpy","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xhacker%2Fmutpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xhacker%2Fmutpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xhacker%2Fmutpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xhacker%2Fmutpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xhacker","download_url":"https://codeload.github.com/xhacker/mutpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245195961,"owners_count":20575938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T17:56:35.862Z","updated_at":"2025-03-24T02:19:33.114Z","avatar_url":"https://github.com/xhacker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=====\nMutPy\n=====\n\n.. image:: https://drone.io/bitbucket.org/khalas/mutpy/status.png\n    :target: https://drone.io/bitbucket.org/khalas/mutpy/latest\n\nMutPy is a mutation testing tool for Python 3.x source code. MutPy supports\nstandard unittest module, generates YAML/HTML reports and has colorful output. It's\napply mutation on AST level. You could boost your mutation testing process with\nhigh order mutations (HOM) and code coverage analysis.\n\nMutation testing\n~~~~~~~~~~~~~~~~\n\nFrom article at Wikipedia:\n\n    **Mutation testing** (or Mutation analysis or Program mutation) evaluates\n    the quality of software tests. Mutation testing involves modifying a program's\n    source code or byte code in small ways. A test suite that does not detect and\n    reject the mutated code is considered defective. These so-called mutations, are\n    based on well-defined mutation operators that either mimic typical programming\n    errors (such as using the wrong operator or variable name) or force the\n    creation of valuable tests (such as driving each expression to zero). The\n    purpose is to help the tester develop effective tests or locate weaknesses in\n    the test data used for the program or in sections of the code that are seldom\n    or never accessed during execution.\n\nInstallation\n~~~~~~~~~~~~\n\nYou can easily install MutPy from PyPi:\n\n::\n\n    $ pip install mutpy\n\n... or if you want to have latest changes you can clone this repository and\ninstall MutPy from sources:\n\n::\n\n    $ hg clone https://bitbucket.org/khalas/mutpy\n    $ cd mutpy/\n    $ python3 setup.py install\n\nExample\n~~~~~~~\n\nMain code (``calculator.py``) - we will mutate it:\n\n::\n\n    def mul(x, y):\n        return x * y\n\nTest (``test_calculator.py``) - we will check its quality:\n\n::\n\n    from unittest import TestCase\n    from calculator import mul\n\n    class CalculatorTest(TestCase):\n\n        def test_mul(self):\n            self.assertEqual(mul(2, 2), 4)\n\nNow we can run MutPy in the same directory where we have our sources files:\n\n::\n\n    $ mut.py --target calculator --unit-test test_calculator -m\n\nThis command will produce the following output:\n\n::\n\n    [*] Start mutation process:\n       - targets: calculator\n       - tests: test_calculator\n    [*] All tests passed:\n       - test_calculator [0.00031 s]\n    [*] Start mutants generation and execution:\n       - [#   1] AOR calculator.py:2  :\n    --------------------------------------------------------------------------------\n     1: def mul(x, y):\n    ~2:     return x / y\n    --------------------------------------------------------------------------------\n    [0.02944 s] killed by test_mul (test_calculator.CalculatorTest)\n       - [#   2] AOR calculator.py:2  :\n    --------------------------------------------------------------------------------\n     1: def mul(x, y):\n    ~2:     return x // y\n    --------------------------------------------------------------------------------\n    [0.02073 s] killed by test_mul (test_calculator.CalculatorTest)\n       - [#   3] AOR calculator.py:2  :\n    --------------------------------------------------------------------------------\n     1: def mul(x, y):\n    ~2:     return x ** y\n    --------------------------------------------------------------------------------\n    [0.01152 s] survived\n       - [#   4] SDL calculator.py:2  :\n    --------------------------------------------------------------------------------\n     1: def mul(x, y):\n    ~2:     pass\n    --------------------------------------------------------------------------------\n    [0.01437 s] killed by test_mul (test_calculator.CalculatorTest)\n    [*] Mutation score [0.21818 s]: 75.0%\n       - all: 4\n       - killed: 3 (75.0%)\n       - survived: 1 (25.0%)\n       - incompetent: 0 (0.0%)\n       - timeout: 0 (0.0%)\n\nFirst of all we run MutPy with few parameters. The most important are:\n\n- ``--target`` - after this flag we should pass module which we want to mutate.\n- ``--unit-test`` - this flag point to our unit tests module.\n\nThere are few phases in mutation process which we can see on printed by MutPy\noutput (marked by star ``[*]``):\n\n- main code and tests modules loading,\n- run tests with original (not mutated) code base,\n- code mutation (main mutation phase),\n- results summary.\n\nThere are 4 mutants generated in main mutation phase - 3 of them are killed and\nonly 1 mutant survived. We can see all stats at the end of MutPy output. In\nthis case MutPy didn't generate any incompetent (raised ``TypeError``) and\ntimeout (generated infinite loop) mutants. Our mutation score (killed to all\nmutants ratio) is 75%.\n\nTo increase mutation score (100% is our target) we need to improve our tests.\nThis is a mutant which survived:\n\n::\n\n    def mul(x, y):\n        return x ** y\n\nThis mutant survived because our test check if ``2 * 2 == 4``. Also ``2 ** 2 ==\n4``, so this data aren't good to specify multiplication operation. We should\nchange it, eg:\n\n::\n\n    from unittest import TestCase\n    from calculator import mul\n\n    class CalculatorTest(TestCase):\n\n        def test_mul(self):\n            self.assertEqual(mul(2, 3), 6)\n\nWe can run MutPy again and now mutation score is equal 100%.\n\n\nCommand-line arguments\n~~~~~~~~~~~~~~~~~~~~~~\n\nList of all arguments with which you can run MutPy:\n\n- ``-t TARGET [TARGET ...]``, ``--target TARGET [TARGET ...]`` - target module or package to mutate,\n- ``-u UNIT_TEST [UNIT_TEST ...]``, ``--unit-test UNIT_TEST [UNIT_TEST ...]`` - test class, test method, module or package with unit tests,\n- ``-m``, ``--show-mutants`` - show mutants source code,\n- ``-r REPORT_FILE``, ``--report REPORT_FILE`` - generate YAML report,\n- ``--report-html DIR_NAME`` - generate HTML report,\n- ``-f TIMEOUT_FACTOR``. ``--timeout-factor TIMEOUT_FACTOR`` - max timeout factor (default 5),\n- ``-d``, ``--disable-stdout`` - try disable stdout during mutation (this option can damage your tests if you interact with ``sys.stdout``),\n- ``-e``. ``--experimental-operators`` - use experimental operators,\n- ``-o OPERATOR [OPERATOR ...]``, ``--operator OPERATOR [OPERATOR ...]`` - use only selected operators,\n- ``--disable-operator OPERATOR [OPERATOR ...]`` - disable selected operators,\n- ``-l``. ``--list-operators`` - list available operators,\n- ``-p DIR``. ``--path DIR`` - extend Python path,\n- ``--percentage PERCENTAGE`` - percentage of the generated mutants (mutation sampling),\n- ``--coverage`` - mutate only covered code,\n- ``-h``, ``--help`` - show this help message and exit,\n- ``-v``, ``--version`` - show program's version number and exit,\n- ``-q``, ``--quiet`` - quiet mode,\n- ``--debug`` - debug mode,\n- ``-c``. ``--colored-output`` - try print colored output,\n- ``--coverage`` - mutate only covered code,\n- ``--order ORDER`` - mutation order,\n- ``--hom-strategy HOM_STRATEGY`` - HOM strategy,\n- ``--list-hom-strategies`` - list available HOM strategies,\n- ``--mutation-number MUTATION_NUMBER`` - run only one mutation (debug purpose).\n\nMutation operators\n~~~~~~~~~~~~~~~~~~\n\nList of MutPy mutation operators sorted by alphabetical order:\n\n- AOD - arithmetic operator deletion\n- AOR - arithmetic operator replacement\n- ASR - assignment operator replacement\n- BCR - break continue replacement\n- COD - conditional operator deletion\n- COI - conditional operator insertion\n- CRP - constant replacement\n- DDL - decorator deletion\n- EHD - exception handler deletion\n- EXS - exception swallowing\n- IHD - hiding variable deletion\n- IOD - overriding method deletion\n- IOP - overridden method calling position change\n- LCR - logical connector replacement\n- LOD - logical operator deletion\n- LOR - logical operator replacement\n- ROR - relational operator replacement\n- SCD - super calling deletion\n- SCI - super calling insert\n- SIR - slice index remove\n\nExperimental mutation operators:\n\n- CDI - classmethod decorator insertion\n- OIL - one iteration loop\n- RIL - reverse iteration loop\n- SDI - staticmethod decorator insertion\n- SDL - statement deletion\n- SVD - self variable deletion\n- ZIL - zero iteration loop\n\nLicense\n~~~~~~~\n\nLicensed under the Apache License, Version 2.0. See LICENSE file.\n\nMutPy was developed as part of engineer's and master’s thesis at Institute of\nComputer Science, Faculty of Electronics and Information Technology, Warsaw\nUniversity of Technology.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxhacker%2Fmutpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxhacker%2Fmutpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxhacker%2Fmutpy/lists"}