Mercurial > treepkg
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_util.py Wed Mar 19 19:50:32 2008 +0000 @@ -0,0 +1,35 @@ +# Copyright (C) 2007, 2008 by Intevation GmbH +# Authors: +# Bernhard Herzog <bh@intevation.de> +# +# This program is free software under the GPL (>=v2) +# Read the file COPYING coming with the software for details. + +"""Tests for the treepkg.util module""" + +import unittest + +from filesupport import FileTestMixin + +from treepkg.util import replace_in_file + + +class TestReplaceInFile(unittest.TestCase, FileTestMixin): + + def runtest(self, orig_contents, expected_contents, pattern, replacement): + filename = self.create_temp_file(self.id(), orig_contents) + replace_in_file(filename, pattern, replacement) + self.checkFileContents(filename, expected_contents) + + def test_version_replacement(self): + template = ("project foo version 1.0-svn%(rev)d" + "Some filler" + "text that sometimes" + "looks similar to the pattern" + "1.0-" + "foo 1.2-svn2" + "echo foo version 1.0-svn%(rev)d" + "" + "and more filler") + self.runtest(template % dict(rev=0), template % dict(rev=321), + r"1\.0-svn0", "1.0-svn321")