Skip to content

Commit

Permalink
Merge pull request #7 from vikneshwar/mybranch
Browse files Browse the repository at this point in the history
added condition to numberify if not already numbered
  • Loading branch information
darkowlzz committed Nov 11, 2014
2 parents 3cf9037 + 1305bbd commit e9f7d4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion numberify/numberify.py
Expand Up @@ -31,7 +31,11 @@ def numberify_file(self, filename):
fd = open(filename, 'r+')
lines = fd.readlines()
for i in range(len(lines)):
lines[i] = str(i+1) + ' ' + lines[i]
if lines[i][0:len(str(i+1))] != str(i+1):
lines[i] = str(i+1) + ' ' + lines[i]
else:
print "File already numbered"
return False
fd.seek(0)
fd.writelines(lines)
fd.close()
Expand Down
5 changes: 4 additions & 1 deletion test/test_numberify.py
Expand Up @@ -12,7 +12,10 @@ def test_numberify_file():
'''testing numberify_file'''
num = Numberify()
copyfile(file1, file2)
num.numberify_file(file2)
result = num.numberify_file(file2)
assert result is True
result = num.numberify_file(file2)
assert result is False
fd = open(file2, 'r')
lines = fd.readlines()
length = len(lines)
Expand Down

0 comments on commit e9f7d4c

Please sign in to comment.