Skip to content

Commit

Permalink
Fix #53 and remove useless pathfinder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubik committed Mar 29, 2014
1 parent ba56144 commit f123506
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 70 deletions.
2 changes: 1 addition & 1 deletion radon/visitors.py
Expand Up @@ -186,7 +186,7 @@ def generic_visit(self, node):
self.complexity += 1
# The For and While blocks count as 1 plus the `else` block.
elif name in ('For', 'While'):
self.complexity += len(node.orelse) + 1
self.complexity += bool(node.orelse) + 1
# List, set, dict comprehensions and generator exps count as 1 plus
# the `if` statement.
elif name == 'comprehension':
Expand Down
69 changes: 0 additions & 69 deletions tests/pathfinder_tests/test.py
Expand Up @@ -283,81 +283,12 @@ def test_depth(self):
self.assertEqual(5, len(paths))
self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)


def test_size(self):
""" Find files based on size criteria. """
# all files except the image files are less than 10 bytes
p_filter = SizeFilter(max_bytes=0)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(11, len(paths))

# only the image files contain data
p_filter = SizeFilter(min_bytes=1)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(6, len(paths))

# three images between 450 bytes and 9000
p_filter = SizeFilter(min_bytes=450, max_bytes=9000)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(3, len(paths))

def test_find_filepath(self):
""" Test when the root path to a find is a file and not a directory. """
a_paths = pathfind(os.path.join(BASEPATH, 'python_logo.png'), just_files=True)
b_paths = pathfind(BASEPATH, just_files=True)
self.assertEqual(a_paths, b_paths)

try:
import PIL

def test_image_dimension(self):
""" Find images based on dimensions. """
p_filter = ImageDimensionFilter(max_width=1000, max_height=1000,
min_height=20, min_width=20)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(6, len(paths))

# ignore the 24x24
p_filter = ImageDimensionFilter(max_width=1000, max_height=1000,
min_height=25, min_width=25)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(5, len(paths))

# no 24x24, but only check it based on height
p_filter = ImageDimensionFilter(min_height=25)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(5, len(paths))

# only the 24x24
p_filter = ImageDimensionFilter(max_width=24, max_height=24)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(1, len(paths))

# only the 24x24, but only check it based on height
p_filter = ImageDimensionFilter(max_height=24)
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(1, len(paths))

# no parameters - all images
p_filter = ImageDimensionFilter()
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(6, len(paths))

def test_bw_image(self):
""" Find all grey scale images. """
p_filter = GreyscaleImageFilter()
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(4, len(paths))

def test_color_image(self):
""" Find all color images. """
p_filter = ColorImageFilter()
paths = walk_and_filter(BASEPATH, p_filter)
self.assertEqual(2, len(paths))

except ImportError:
pass

def test_generator(self):
""" Test with no parameters. """
# find all paths
Expand Down
19 changes: 19 additions & 0 deletions tests/test_complexity_visitor.py
Expand Up @@ -157,6 +157,25 @@
sum(i for i in range(10) if i >= 2 and val and val2 or val3)
''', 6),

('''
for i in range(10):
print(i)
else:
print('wah')
print('really not found')
print(3)
''', 3),

('''
while True:
print(1)
else:
print(2)
print(1)
print(0)
print(-1)
''', 3),

('''
assert i < 0
''', 2),
Expand Down

0 comments on commit f123506

Please sign in to comment.