Skip to content

Commit

Permalink
Some more tests/comments written.
Browse files Browse the repository at this point in the history
Tests for various broken file operations.
Comments added for __init__.
  • Loading branch information
lyda committed Apr 8, 2012
1 parent 4ecd3a4 commit 22dc40a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
18 changes: 16 additions & 2 deletions misspellings/misspellings_lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#!/usr/bin/python

class Misspellings(object):
"""Detects misspelled words in files."""
def __init__(self, files=None, misspelling_list=None):
"""Initialises an Misspellings instance.
Args:
files: List of files to check. More can be added with add().
misspelling_list: Filename with a list of misspelled words
and their alternatives.
Raises:
IOError: Raised if misspelling_list can't be found.
ValueError: Raised if misspelling_list isn't correctly formatted.
"""
if misspelling_list:
self._misspelling_dict = {}
with open(misspelling_list, 'r') as f:
Expand All @@ -14,8 +26,10 @@ def __init__(self, files=None, misspelling_list=None):
self.add(files)

def add(self, files):
for fn in files:
self._files.append(fn)
if files.__class__.__name__ == 'str':
self._files.append(files)
else:
self._files.extend(files)

def check(self):
errors = []
Expand Down
3 changes: 3 additions & 0 deletions tests/broken_msl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo fouled up
bar beyond all repair
kitten
27 changes: 21 additions & 6 deletions tests/test_file_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@
import unittest

# Set the path to load the module being tested.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
BASE_PATH = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(BASE_PATH, '..'))
import misspellings.misspellings_lib as misspellings


class IntegerArithmenticTestCase(unittest.TestCase):
def testMissingList(self):
def testMissingMSList(self):
self.assertRaises(IOError, misspellings.Misspellings,
None, 'missing_msl.txt')
def testMultiply(self):
self.assertEqual((0 * 10), 0)
self.assertEqual((5 * 8), 40)
None, os.path.join(BASE_PATH, 'missing_msl.txt'))

def testBrokenMSList(self):
self.assertRaises(ValueError, misspellings.Misspellings, None,
os.path.join(BASE_PATH, 'broken_msl.txt'))

def testMissingFile(self):
ms = misspellings.Misspellings(
files=os.path.join(BASE_PATH, 'missing_source.c'))
errors, results = ms.check()
self.assertEquals(len(errors), 1)

def testMissingFiles(self):
ms = misspellings.Misspellings(files=[
os.path.join(BASE_PATH, 'missing_source_%d.c' % i)
for i in xrange(10)])
errors, results = ms.check()
self.assertEquals(len(errors), 10)

if __name__ == '__main__':
unittest.main()

0 comments on commit 22dc40a

Please sign in to comment.