Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (47 sloc) 1.61 KB

Refactor if X is None

Reproducer

$ pip install nose
$ pip install https://github.com/sixty-north/cosmic-ray/zipball/master

$ cosmic-ray run --test-runner nose --baseline=10 example.json hello.py -- test_hello.py
$ cosmic-ray report example.json

job ID 4:Outcome.SURVIVED:hello
command: cosmic-ray worker hello replace_Is_with_Eq 0 nose -- -v test_hello.py
--- mutation diff ---
--- a/example_06/hello.py
+++ b/example_06/hello.py
@@ -1,7 +1,7 @@


 def sayHello(name, title=None):
-    if (title is None):
+    if (title == None):
         title = 'Mr.'
     return ('Hello %s %s' % (title, name))

total jobs: 9
complete: 9 (100.00%)
survival rate: 11.11%

Note

Since PR #162 Cosmic-Ray skips mutations of the kind == -> is but doesn't skip the opposite of is -> ==!

Now compare the results after refactoring

$ cosmic-ray run --test-runner nose --baseline=10 example.json hello2.py -- test_hello2.py
$ cosmic-ray report example.json --full-report
total jobs: 0
no jobs completed

Functionality is the same but we have reduced the number of possible mutations!

Source code

.. literalinclude:: hello.py
    :caption: hello.py
    :language: python

.. literalinclude:: test_hello.py
    :caption: test_hello.py
    :language: python

.. literalinclude:: hello2.py
    :caption: hello2.py
    :language: python

.. literalinclude:: test_hello2.py
    :caption: test_hello2.py
    :language: python
You can’t perform that action at this time.