view test/test_util.py @ 171:c0ea6cbb0fd2

Add "--debbuildopts -b" to "pbuilder build" command line to stop pbuilder from creating a source package. The .changes would otherwise contain references to that new source package instead of the one we passed to pbuilder. The checksums for the two source packages would be different so the .changes file would not match the source package that treepkg produces.
author Bernhard Herzog <bh@intevation.de>
date Mon, 23 Jun 2008 16:12:01 +0000
parents 261b75d7b972
children e1c7cd896310
line wrap: on
line source
# 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 os
import unittest

from filesupport import FileTestMixin

from treepkg.util import replace_in_file, listdir_abs


class TestReplaceInFile(unittest.TestCase, FileTestMixin):

    def runtest(self, orig_contents, expected_contents, pattern, replacement):
        filename = self.create_temp_file(self.id(), orig_contents)
        changed = replace_in_file(filename, pattern, replacement)
        self.assertEquals(changed, orig_contents != expected_contents)
        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")

    def test_no_matches(self):
        """Tests replace_in_file when no matches are found"""
        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=0),
                     r"0\.9-svn0", "1.0-svn321")


class TestListDirAbs(unittest.TestCase, FileTestMixin):

    def setUp(self):
        self.directory = self.create_temp_dir(self.id())

    def test_listdir_abs(self):
        self.create_files(self.directory, [("foo.orig.tgz", ""),
                                           ("foo.dsc", ""),
                                           ("foo.diff.gz", ""),])
        self.assertEquals(sorted(listdir_abs(self.directory)),
                          sorted([os.path.join(self.directory, d)
                                  for d in ["foo.orig.tgz", "foo.dsc",
                                            "foo.diff.gz"]]))

    def test_listdir_abs_pattern(self):
        self.create_files(self.directory, [("foo.orig.tgz", ""),
                                           ("foo.dsc", ""),
                                           ("foo.diff.gz", ""),])
        self.assertEquals(sorted(listdir_abs(self.directory, '*.dsc')),
                          [os.path.join(self.directory, "foo.dsc")])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)