Skip to content

Commit

Permalink
Add tests for see.tools.compact
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Cooke committed May 17, 2017
1 parent c6201d3 commit 0c6b165
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_mod_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@

class TestToolsModule(unittest.TestCase):

def test_compact_list(self):
# Arrange
items = [0, 1, '', 'foo', True, False, [], ['a'], {}, {1: 2}]
expected = [1, 'foo', True, ['a'], {1: 2}]

# Act
compact_list = tools.compact(list, items)
compact_tuple = tools.compact(tuple, items)

# Assert
self.assertEqual(compact_list, list(expected))
self.assertEqual(compact_tuple, tuple(expected))

def test_compact_set(self):
# Arrange
hashable = [0, 1, '', 'foo', True, False, (), ('a',)]
unhashable = [0, 1, '', 'foo', True, False, [], ['a']]
expected = [1, 'foo', True, ('a',)]

# Act
compact_set = tools.compact(set, hashable)

def compact_unhashable():
return tools.compact(set, unhashable)

# Assert
self.assertEqual(compact_set, set(expected))
self.assertRaises(TypeError, compact_unhashable)

def test_filter_by_regex(self):
# Arrange
names = ["george", "helen"]
Expand Down

0 comments on commit 0c6b165

Please sign in to comment.