Mercurial > treepkg
comparison test/test_util.py @ 160:017179427c7f
Make treepkg/utilreplace_in_file return whether any substitutions were made.
Add a corresponding test.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 19 Jun 2008 12:25:30 +0000 |
parents | 7f6fb8103db0 |
children | 876db132431a |
comparison
equal
deleted
inserted
replaced
159:3f2ec4314855 | 160:017179427c7f |
---|---|
16 | 16 |
17 class TestReplaceInFile(unittest.TestCase, FileTestMixin): | 17 class TestReplaceInFile(unittest.TestCase, FileTestMixin): |
18 | 18 |
19 def runtest(self, orig_contents, expected_contents, pattern, replacement): | 19 def runtest(self, orig_contents, expected_contents, pattern, replacement): |
20 filename = self.create_temp_file(self.id(), orig_contents) | 20 filename = self.create_temp_file(self.id(), orig_contents) |
21 replace_in_file(filename, pattern, replacement) | 21 changed = replace_in_file(filename, pattern, replacement) |
22 print "TestReplaceInFile.runtest", changed | |
23 self.assertEquals(changed, orig_contents != expected_contents) | |
22 self.checkFileContents(filename, expected_contents) | 24 self.checkFileContents(filename, expected_contents) |
23 | 25 |
24 def test_version_replacement(self): | 26 def test_version_replacement(self): |
25 template = ("project foo version 1.0-svn%(rev)d" | 27 template = ("project foo version 1.0-svn%(rev)d" |
26 "Some filler" | 28 "Some filler" |
31 "echo foo version 1.0-svn%(rev)d" | 33 "echo foo version 1.0-svn%(rev)d" |
32 "" | 34 "" |
33 "and more filler") | 35 "and more filler") |
34 self.runtest(template % dict(rev=0), template % dict(rev=321), | 36 self.runtest(template % dict(rev=0), template % dict(rev=321), |
35 r"1\.0-svn0", "1.0-svn321") | 37 r"1\.0-svn0", "1.0-svn321") |
38 | |
39 def test_no_matches(self): | |
40 """Tests replace_in_file when no matches are found""" | |
41 template = ("project foo version 1.0-svn%(rev)d" | |
42 "Some filler" | |
43 "text that sometimes" | |
44 "looks similar to the pattern" | |
45 "1.0-" | |
46 "foo 1.2-svn2" | |
47 "echo foo version 1.0-svn%(rev)d" | |
48 "" | |
49 "and more filler") | |
50 self.runtest(template % dict(rev=0), template % dict(rev=0), | |
51 r"0\.9-svn0", "1.0-svn321") |