Skip to content

Commit

Permalink
Make sure error messages find their way into the target file
Browse files Browse the repository at this point in the history
  • Loading branch information
knatten committed Aug 29, 2011
1 parent 2be86d4 commit b348c46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
*.pyc
SnippetySnip*.tgz
*.swp
use_dev.sh
6 changes: 3 additions & 3 deletions python/SnippetySnip/snippetysnip.py
Expand Up @@ -10,7 +10,7 @@ def get_snippet(file_name, snippet_name):
try:
file = open(file_name, 'r')
except IOError as e:
return "ERROR: Couldn't open file: %s" % e
return "ERROR: Couldn't open file: %s\n" % e
for line in file:
if snippet_begin in line:
in_snippet = True
Expand All @@ -22,9 +22,9 @@ def get_snippet(file_name, snippet_name):
snippet += line

if not found_tag:
return "ERROR: Didn't find %s" % snippet_begin
return "ERROR: Didn't find %s\n" % snippet_begin
if in_snippet:
return "ERROR: Didn't find snippetysnip_end after %s" % snippet_begin
return "ERROR: Didn't find snippetysnip_end after %s\n" % snippet_begin
return snippet


Expand Down
6 changes: 3 additions & 3 deletions python/SnippetySnip/test.py
Expand Up @@ -9,17 +9,17 @@ def test_gets_snippet(self):

def test_missing_snippet_returns_errormessage(self):
self.assertEqual(
"ERROR: Didn't find snippetysnip_begin:platypus",
"ERROR: Didn't find snippetysnip_begin:platypus\n",
get_snippet("example.cpp", "platypus"))

def test_missing_snippet_end_returns_errormessage(self):
self.assertEqual(
"ERROR: Didn't find snippetysnip_end after snippetysnip_begin:error",
"ERROR: Didn't find snippetysnip_end after snippetysnip_begin:error\n",
get_snippet("example.cpp", "error"))

def test_missing_file_returns_errormessage(self):
self.assertEqual(
"ERROR: Couldn't open file: [Errno 2] No such file or directory: 'missing_file.cpp'",
"ERROR: Couldn't open file: [Errno 2] No such file or directory: 'missing_file.cpp'\n",
get_snippet("missing_file.cpp", "tag"))

class Test_find_end_line(unittest.TestCase):
Expand Down

0 comments on commit b348c46

Please sign in to comment.