Skip to content

Commit

Permalink
Increase test coverage (jendrikseipp#126)
Browse files Browse the repository at this point in the history
* Ensure sort_by_size is actually tested.

* Test Item.__repr__
  • Loading branch information
RJ722 authored and jendrikseipp committed Jun 5, 2018
1 parent e0e384e commit 01a5031
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from . import v
assert v # Silence pyflakes.

Expand All @@ -10,3 +12,12 @@ def test_syntax_error(v):
def test_null_byte(v):
v.scan("\x00")
assert int(v.report()) == 1


def test_confidence_range(v):
v.scan("""\
def foo():
pass
""")
with pytest.raises(ValueError):
v.get_unused_code(min_confidence=150)
16 changes: 16 additions & 0 deletions tests/test_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from . import v
assert v # Silence pyflakes


def test_item_repr(v):
v.scan("""\
import os
message = "foobar"
class Foo:
def bar():
pass
""")
for item in v.get_unused_code():
assert repr(item) == "'{}'".format(item.name)
2 changes: 1 addition & 1 deletion tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_pyc():


def test_sort_by_size():
assert call_vulture(['vulture/', '--sort-by-size']) == 0
assert call_vulture(['vulture/utils.py', '--sort-by-size']) == 1


def test_min_confidence():
Expand Down
17 changes: 17 additions & 0 deletions tests/test_sorting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from . import v
assert v # Silence pyflakes


def test_sorting(v):
v.scan("""\
def foo():
print("Hello, I am a long function.")
return "World"
def bar():
pass
""")
assert [item.name for item in
v.get_unused_code(sort_by_size=True)] == ['bar', 'foo']
assert [item.name for item in
v.get_unused_code(sort_by_size=False)] == ['foo', 'bar']

0 comments on commit 01a5031

Please sign in to comment.