bh@111: # Copyright (C) 2007, 2008 by Intevation GmbH bh@111: # Authors: bh@111: # Bernhard Herzog bh@111: # bh@111: # This program is free software under the GPL (>=v2) bh@111: # Read the file COPYING coming with the software for details. bh@111: bh@111: """Tests for the treepkg.util module""" bh@111: bh@111: import unittest bh@111: bh@111: from filesupport import FileTestMixin bh@111: bh@111: from treepkg.util import replace_in_file bh@111: bh@111: bh@111: class TestReplaceInFile(unittest.TestCase, FileTestMixin): bh@111: bh@111: def runtest(self, orig_contents, expected_contents, pattern, replacement): bh@111: filename = self.create_temp_file(self.id(), orig_contents) bh@111: replace_in_file(filename, pattern, replacement) bh@111: self.checkFileContents(filename, expected_contents) bh@111: bh@111: def test_version_replacement(self): bh@111: template = ("project foo version 1.0-svn%(rev)d" bh@111: "Some filler" bh@111: "text that sometimes" bh@111: "looks similar to the pattern" bh@111: "1.0-" bh@111: "foo 1.2-svn2" bh@111: "echo foo version 1.0-svn%(rev)d" bh@111: "" bh@111: "and more filler") bh@111: self.runtest(template % dict(rev=0), template % dict(rev=321), bh@111: r"1\.0-svn0", "1.0-svn321")