Mercurial > treepkg
comparison test/test_util.py @ 169:261b75d7b972
Extend listdir_abs with an optional glob pattern
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 20 Jun 2008 15:51:24 +0000 |
parents | 876db132431a |
children | e1c7cd896310 |
comparison
equal
deleted
inserted
replaced
168:be07b88b44ea | 169:261b75d7b972 |
---|---|
5 # This program is free software under the GPL (>=v2) | 5 # This program is free software under the GPL (>=v2) |
6 # Read the file COPYING coming with the software for details. | 6 # Read the file COPYING coming with the software for details. |
7 | 7 |
8 """Tests for the treepkg.util module""" | 8 """Tests for the treepkg.util module""" |
9 | 9 |
10 import os | |
10 import unittest | 11 import unittest |
11 | 12 |
12 from filesupport import FileTestMixin | 13 from filesupport import FileTestMixin |
13 | 14 |
14 from treepkg.util import replace_in_file | 15 from treepkg.util import replace_in_file, listdir_abs |
15 | 16 |
16 | 17 |
17 class TestReplaceInFile(unittest.TestCase, FileTestMixin): | 18 class TestReplaceInFile(unittest.TestCase, FileTestMixin): |
18 | 19 |
19 def runtest(self, orig_contents, expected_contents, pattern, replacement): | 20 def runtest(self, orig_contents, expected_contents, pattern, replacement): |
46 "echo foo version 1.0-svn%(rev)d" | 47 "echo foo version 1.0-svn%(rev)d" |
47 "" | 48 "" |
48 "and more filler") | 49 "and more filler") |
49 self.runtest(template % dict(rev=0), template % dict(rev=0), | 50 self.runtest(template % dict(rev=0), template % dict(rev=0), |
50 r"0\.9-svn0", "1.0-svn321") | 51 r"0\.9-svn0", "1.0-svn321") |
52 | |
53 | |
54 class TestListDirAbs(unittest.TestCase, FileTestMixin): | |
55 | |
56 def setUp(self): | |
57 self.directory = self.create_temp_dir(self.id()) | |
58 | |
59 def test_listdir_abs(self): | |
60 self.create_files(self.directory, [("foo.orig.tgz", ""), | |
61 ("foo.dsc", ""), | |
62 ("foo.diff.gz", ""),]) | |
63 self.assertEquals(sorted(listdir_abs(self.directory)), | |
64 sorted([os.path.join(self.directory, d) | |
65 for d in ["foo.orig.tgz", "foo.dsc", | |
66 "foo.diff.gz"]])) | |
67 | |
68 def test_listdir_abs_pattern(self): | |
69 self.create_files(self.directory, [("foo.orig.tgz", ""), | |
70 ("foo.dsc", ""), | |
71 ("foo.diff.gz", ""),]) | |
72 self.assertEquals(sorted(listdir_abs(self.directory, '*.dsc')), | |
73 [os.path.join(self.directory, "foo.dsc")]) | |
74 |