comparison test/test_util.py @ 111:7f6fb8103db0

Move the sed-like replacement code from enterprise/kdepim.py to treepkg/util.py This creates a new function treepkg.util.replace_in_file with some tests in test/test_util.py and new test support code in test/filesupport.py. Also, adapt enterprise/kdepim.py to use the new function.
author Bernhard Herzog <bh@intevation.de>
date Wed, 19 Mar 2008 19:50:32 +0000
parents
children 017179427c7f
comparison
equal deleted inserted replaced
110:ba677506e95e 111:7f6fb8103db0
1 # Copyright (C) 2007, 2008 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """Tests for the treepkg.util module"""
9
10 import unittest
11
12 from filesupport import FileTestMixin
13
14 from treepkg.util import replace_in_file
15
16
17 class TestReplaceInFile(unittest.TestCase, FileTestMixin):
18
19 def runtest(self, orig_contents, expected_contents, pattern, replacement):
20 filename = self.create_temp_file(self.id(), orig_contents)
21 replace_in_file(filename, pattern, replacement)
22 self.checkFileContents(filename, expected_contents)
23
24 def test_version_replacement(self):
25 template = ("project foo version 1.0-svn%(rev)d"
26 "Some filler"
27 "text that sometimes"
28 "looks similar to the pattern"
29 "1.0-"
30 "foo 1.2-svn2"
31 "echo foo version 1.0-svn%(rev)d"
32 ""
33 "and more filler")
34 self.runtest(template % dict(rev=0), template % dict(rev=321),
35 r"1\.0-svn0", "1.0-svn321")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)