-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from albertas/feature/add-only-option
Add only option which now works only with dry option
- Loading branch information
Showing
10 changed files
with
200 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
try: | ||
import importlib.metadata | ||
__version__ = importlib.metadata.version(__package__ or __name__) | ||
except ImportError: | ||
import importlib_metadata | ||
__version__ = importlib_metadata.version(__package__ or __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from deadcode.cli import main | ||
from deadcode.utils.base_test_case import BaseTestCase | ||
from deadcode.utils.fix_indent import fix_indent | ||
|
||
|
||
class TestOnlyCliOption(BaseTestCase): | ||
def test_output_is_provided_only_for_files_in_only_option(self): | ||
self.files = { | ||
'foo.py': b""" | ||
class UnusedClass: | ||
pass | ||
print("Dont change this file")""", | ||
'bar.py': b""" | ||
def unused_function(): | ||
pass | ||
print("Dont change this file")""", | ||
} | ||
|
||
unused_names = main('. --only foo.py --no-color'.split()) | ||
|
||
self.assertEqual( | ||
unused_names, | ||
fix_indent( | ||
"""\ | ||
foo.py:1:0: DC03 Class `UnusedClass` is never used""" | ||
), | ||
) | ||
|
||
self.assertFiles( | ||
{ | ||
'foo.py': b""" | ||
class UnusedClass: | ||
pass | ||
print("Dont change this file")""", | ||
'bar.py': b""" | ||
def unused_function(): | ||
pass | ||
print("Dont change this file")""", | ||
} | ||
) | ||
|
||
def test_files_are_modified_only_for_files_in_only_option(self): | ||
self.files = { | ||
'foo.py': b""" | ||
class UnusedClass: | ||
pass | ||
print("Dont change this line")""", | ||
'bar.py': b""" | ||
def unused_function(): | ||
pass | ||
print("Dont change this file")""", | ||
} | ||
|
||
unused_names = main('. --only foo.py --no-color --fix'.split()) | ||
|
||
self.assertEqual( | ||
unused_names, | ||
fix_indent( | ||
"""\ | ||
foo.py:1:0: DC03 Class `UnusedClass` is never used\n | ||
Removed 1 unused code item!""" | ||
), | ||
) | ||
|
||
# self.assertFiles( | ||
# { | ||
# 'bar.py': b""" | ||
# def unused_function(): | ||
# pass | ||
|
||
# print("Dont change this file")""", | ||
# 'foo.py': b""" | ||
# print("Dont change this line")""", | ||
# } | ||
# ) | ||
|
||
def test_diffs_are_provided_only_for_files_in_only_option(self): | ||
self.files = { | ||
'foo.py': b""" | ||
class UnusedClass: | ||
pass | ||
print("Dont change this file")""", | ||
'bar.py': b""" | ||
def unused_function(): | ||
pass | ||
print("Dont change this file")""", | ||
} | ||
|
||
unused_names = main(['ignore_names_by_pattern.py', '--no-color', '--dry', '--only', 'foo.py']) | ||
self.assertEqual( | ||
unused_names, | ||
fix_indent( | ||
"""\ | ||
foo.py:1:0: DC03 Class `UnusedClass` is never used | ||
--- foo.py | ||
+++ foo.py | ||
@@ -1,4 +1 @@ | ||
-class UnusedClass: | ||
- pass | ||
- | ||
print("Dont change this file") | ||
""" | ||
), | ||
) | ||
|
||
self.assertFiles( | ||
{ | ||
'foo.py': b""" | ||
class UnusedClass: | ||
pass | ||
print("Dont change this file")""", | ||
'bar.py': b""" | ||
def unused_function(): | ||
pass | ||
print("Dont change this file")""", | ||
} | ||
) |
Oops, something went wrong.