[Treepkg-commits] r43 - trunk/test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue May 20 20:47:17 CEST 2008


Author: bh
Date: 2008-05-20 20:47:16 +0200 (Tue, 20 May 2008)
New Revision: 43

Added:
   trunk/test/test_builder.py
Log:
Add test/test_builder.py with tests for treepkg.builder


Added: trunk/test/test_builder.py
===================================================================
--- trunk/test/test_builder.py	2008-04-02 10:49:57 UTC (rev 42)
+++ trunk/test/test_builder.py	2008-05-20 18:47:16 UTC (rev 43)
@@ -0,0 +1,62 @@
+# Copyright (C) 2007, 2008 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Tests for treepkg.builder"""
+
+import sys
+import os
+import unittest
+
+from treepkg.builder import PBuilder
+
+from filesupport import FileTestMixin
+
+# helper program to dump the command line arguments into a file so that
+# test cases can check them.
+dump_command_line_py = """
+import sys
+open(sys.argv[1], 'w').write(repr(sys.argv[2:]))
+"""
+
+
+class TestPBuilder(unittest.TestCase, FileTestMixin):
+
+    def setUp(self):
+        self.dump_command_line = self.create_temp_file("dump_command_line.py",
+                                                       dump_command_line_py)
+        self.command_line_file = self.temp_file_name("command_line")
+        self.root_command = [sys.executable, self.dump_command_line,
+                             self.command_line_file]
+
+    def check_command_line(self, args):
+        self.checkFileContents(self.command_line_file, repr(args))
+
+    def test_build(self):
+        """Tests the PBuilder.build method.
+        The test checks whether the build method creates the binary_dir
+        and then checks the arguments with which the root command is
+        called.  The test is a little too strict because it expects a
+        specific order of the arguments even though the order of some of
+        the arguments doesn't matter.
+
+        A more thorough test of the build method is implicity done by
+        the packager tests.
+        """
+        binary_dir_name = self.temp_file_name("binary")
+        if os.path.exists(binary_dir_name):
+            os.rmdir(binary_dir_name)
+        # sanity check: the binary directory must not exist yet.
+        self.failIf(os.path.exists(binary_dir_name))
+
+        builder = PBuilder("my_pbuilderrc", self.root_command)
+        builder.build("my_dsc_file", binary_dir_name, "the_logfile")
+        self.check_command_line(['/usr/sbin/pbuilder', 'build',
+                                 '--configfile', 'my_pbuilderrc',
+                                 '--logfile', 'the_logfile',
+                                 '--buildresult', binary_dir_name,
+                                 'my_dsc_file'])
+        self.failUnless(os.path.isdir(binary_dir_name))


Property changes on: trunk/test/test_builder.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the Treepkg-commits mailing list