Mercurial > treepkg
changeset 439:8e0c81870e5e treepkg-status
cleanup modules
fix test_info testcases
added testcases for remove_trailingslashes and expand_filename
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Fri, 06 Aug 2010 11:06:08 +0000 |
parents | 3a3cad8f6f60 |
children | eadcb1bb54e2 |
files | bin/publishdebianpackages.py bin/publishpackages.py test/test_info.py test/test_util.py treepkg/publish.py treepkg/util.py |
diffstat | 6 files changed, 41 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/publishdebianpackages.py Thu Aug 05 16:21:47 2010 +0000 +++ b/bin/publishdebianpackages.py Fri Aug 06 11:06:08 2010 +0000 @@ -20,10 +20,9 @@ from treepkg.readconfig import read_config_section, convert_bool from treepkg.run import call, capture_output from treepkg.cmdexpand import cmdexpand -from treepkg.publish import copy_arch_to_publishdir, expand_filename, \ - prefix_for_remote_command, remove_trailing_slashes +from treepkg.publish import copy_arch_to_publishdir, prefix_for_remote_command -from treepkg.util import md5sum +from treepkg.util import md5sum, expand_filename, remove_trailing_slashes from treepkg.info.status import TreepkgInfo from treepkg.info.data import Package from treepkg.info.data import CacheDb @@ -83,11 +82,6 @@ **variables)) return TreepkgInfo.fromxml(xml) -def get_binary_arch(arch): - if not arch is None and not arch.startswith("binary") and arch != "source": - arch = "binary-" + arch - return arch - def check_package_is_new(packagename, destdir, packagemd5sum): destpackage = os.path.join(destdir, packagename) if not os.path.isfile(destpackage):
--- a/bin/publishpackages.py Thu Aug 05 16:21:47 2010 +0000 +++ b/bin/publishpackages.py Fri Aug 06 11:06:08 2010 +0000 @@ -19,8 +19,8 @@ from treepkg.readconfig import read_config_section, convert_bool from treepkg.run import call, capture_output from treepkg.cmdexpand import cmdexpand -from treepkg.util import ensure_directory, listdir_abs -from treepkg.publish import remove_trailing_slashes, expand_filename +from treepkg.util import ensure_directory, listdir_abs, \ + remove_trailing_slashes, expand_filename from treepkg.publish import prefix_for_remote_command, copy_to_publishdir config_desc = ["distribution", "section", "num_newest",
--- a/test/test_info.py Thu Aug 05 16:21:47 2010 +0000 +++ b/test/test_info.py Fri Aug 06 11:06:08 2010 +0000 @@ -11,14 +11,10 @@ import os import sys -test_dir = os.path.dirname(__file__) -sys.path.append(os.path.join(test_dir, os.pardir)) - from treepkg.info.status import TreepkgInfo, TreepkgRootInfo from filesupport import FileTestMixin - -from publishdebianpackages import get_binary_arch +from treepkg.publish import get_binary_arch class TreepkgInfoTest(unittest.TestCase, FileTestMixin): config_contents = """\ @@ -83,7 +79,7 @@ xml = dom.toxml() self.assertEquals("<info><name>testtreepkg</name></info>", xml) -class TestPublishDebianPackages(unittest.TestCase, FileTestMixin): +class TestPublish(unittest.TestCase, FileTestMixin): def test_get_binary_arch(self): source = get_binary_arch("source")
--- a/test/test_util.py Thu Aug 05 16:21:47 2010 +0000 +++ b/test/test_util.py Fri Aug 06 11:06:08 2010 +0000 @@ -12,7 +12,9 @@ from filesupport import FileTestMixin -from treepkg.util import replace_in_file, listdir_abs, md5sum +from treepkg.util import replace_in_file, listdir_abs, md5sum, \ + remove_trailing_slashes, expand_filename + class TestReplaceInFile(unittest.TestCase, FileTestMixin): @@ -82,3 +84,21 @@ def test_md5sum(self): sum = md5sum(self.testfile) self.assertEquals("a12511153555c1f0f0a1eda200733a3f", sum) + +class TestRemoveTrailingSlashes(unittest.TestCase): + + def test_remove_trailing_slashes(self): + dir_w_slash = "/tmp/dir/" + dir_wo_slash = "/tmp/dir" + + self.assertEquals(dir_wo_slash, remove_trailing_slashes(dir_w_slash)) + self.assertEquals(dir_wo_slash, remove_trailing_slashes(dir_wo_slash)) + +class TestExpandFilename(unittest.TestCase): + + def test_expand_filenam(self): + os.environ['MY_TEST_VAR'] = "def" + path = "/abc/${MY_TEST_VAR}/" + + self.assertEquals("/abc/def/", expand_filename(path)) +
--- a/treepkg/publish.py Thu Aug 05 16:21:47 2010 +0000 +++ b/treepkg/publish.py Fri Aug 06 11:06:08 2010 +0000 @@ -13,15 +13,6 @@ from treepkg.run import call, capture_output from treepkg.cmdexpand import cmdexpand -def remove_trailing_slashes(s): - return s.rstrip("/") - -def expand_filename(filename): - """ - Applies os.path.expanduser and os.path.expandvars to filename - """ - return os.path.expandvars(os.path.expanduser(filename)) - def prefix_for_remote_command(user, host): """Returns the ssh call needed to run a command on a remote host. If host is empty, the function assumes the command is to be run on @@ -97,4 +88,8 @@ rsync_flags=rsync_flags, remote_destdir=remote_destdir, **variables)) +def get_binary_arch(arch): + if not arch is None and not arch.startswith("binary") and arch != "source": + arch = "binary-" + arch + return arch
--- a/treepkg/util.py Thu Aug 05 16:21:47 2010 +0000 +++ b/treepkg/util.py Fri Aug 06 11:06:08 2010 +0000 @@ -174,3 +174,13 @@ f.close() return m.hexdigest() +def remove_trailing_slashes(s): + return s.rstrip("/") + +def expand_filename(filename): + """ + Applies os.path.expanduser and os.path.expandvars to filename + """ + return os.path.expandvars(os.path.expanduser(filename)) + +