]> granicus.if.org Git - python/commitdiff
One unit test for distutils is not much, but is more than we had yesterday.
authorFred Drake <fdrake@acm.org>
Tue, 15 Jun 2004 15:49:46 +0000 (15:49 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 15 Jun 2004 15:49:46 +0000 (15:49 +0000)
We need to write more; hopefully the barrier is a little lower now.

Lib/distutils/tests/__init__.py [new file with mode: 0644]
Lib/distutils/tests/test_install_scripts.py [new file with mode: 0644]
Lib/test/test_distutils.py [new file with mode: 0644]

diff --git a/Lib/distutils/tests/__init__.py b/Lib/distutils/tests/__init__.py
new file mode 100644 (file)
index 0000000..7bdb912
--- /dev/null
@@ -0,0 +1,35 @@
+"""Test suite for distutils.
+
+This test suite consists of a collection of test modules in the
+distutils.tests package.  Each test module has a name starting with
+'test' and contains a function test_suite().  The function is expected
+to return an initialized unittest.TestSuite instance.
+
+Tests for the command classes in the distutils.command package are
+included in distutils.tests as well, instead of using a separate
+distutils.command.tests package, since command identification is done
+by import rather than matching pre-defined names.
+
+"""
+
+import os
+import sys
+import unittest
+
+
+here = os.path.dirname(__file__)
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    for fn in os.listdir(here):
+        if fn.startswith("test") and fn.endswith(".py"):
+            modname = "distutils.tests." + fn[:-3]
+            __import__(modname)
+            module = sys.modules[modname]
+            suite.addTest(module.test_suite())
+    return suite
+
+
+if __name__ == "__main__":
+    unittest.main(defaultTest="test_suite")
diff --git a/Lib/distutils/tests/test_install_scripts.py b/Lib/distutils/tests/test_install_scripts.py
new file mode 100644 (file)
index 0000000..f9a95ea
--- /dev/null
@@ -0,0 +1,46 @@
+"""Tests for distutils.command.install_scripts."""
+
+import os
+import unittest
+
+from distutils.command.install_scripts import install_scripts
+from distutils.core import Distribution
+
+
+class InstallScriptsTestCase(unittest.TestCase):
+
+    def test_default_settings(self):
+        dist = Distribution()
+        dist.command_obj["build"] = DummyCommand(build_scripts="/foo/bar")
+        dist.command_obj["install"] = DummyCommand(
+            install_scripts="/splat/funk",
+            force=1,
+            skip_build=1,
+            )
+        cmd = install_scripts(dist)
+        self.assert_(not cmd.force)
+        self.assert_(not cmd.skip_build)
+        self.assert_(cmd.build_dir is None)
+        self.assert_(cmd.install_dir is None)
+
+        cmd.finalize_options()
+
+        self.assert_(cmd.force)
+        self.assert_(cmd.skip_build)
+        self.assertEqual(cmd.build_dir, "/foo/bar")
+        self.assertEqual(cmd.install_dir, "/splat/funk")
+
+
+class DummyCommand:
+
+    def __init__(self, **kwargs):
+        for kw, val in kwargs.items():
+            setattr(self, kw, val)
+
+    def ensure_finalized(self):
+        pass
+
+
+
+def test_suite():
+    return unittest.makeSuite(InstallScriptsTestCase)
diff --git a/Lib/test/test_distutils.py b/Lib/test/test_distutils.py
new file mode 100644 (file)
index 0000000..fcd792d
--- /dev/null
@@ -0,0 +1,17 @@
+"""Tests for distutils.
+
+The tests for distutils are defined in the distutils.tests package;
+the test_suite() function there returns a test suite that's ready to
+be run.
+"""
+
+import distutils.tests
+import test.test_support
+
+
+def test_main():
+    test.test_support.run_unittest(distutils.tests.test_suite())
+
+
+if __name__ == "__main__":
+    test_main()