view test/test_util.py @ 232:e3cda08d2619

When checking whether to build a new revision, also update the rules working copy, use it's revision too when comparing the current revision with the already built revisions and use it when building a new revision. Update the tests for this. Part of this change is that now, the default revision for the rules is 0 not 1 as previously. To avoid extra builds, existing treepkg instances will have to be updated so that the directories end in -0 not -1. There will be a tool to help with this.
author Bernhard Herzog <bh@intevation.de>
date Tue, 13 Jan 2009 15:01:22 +0000
parents e3ab8aca2b08
children bfd1c6a155fa
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("orig", orig_contents)
        changed = replace_in_file(filename, pattern, replacement)
        self.assertEquals(changed, orig_contents != expected_contents)
        self.check_file_contents(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("a_directory")

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

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