Invoked with 'python setup.py test'. We will put it to use in the
following patches.

Signed-off-by: Cole Robinson <[email protected]>
---
 .gitignore |    1 +
 setup.py   |   51 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 tests/koan/__init__.py

diff --git a/.gitignore b/.gitignore
index 38e707e..5ac62a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ MANIFEST
 TAGS
 .project
 .pydevproject
+.coverage
 
 # docs - ignore pod output
 docs/*.gz
diff --git a/setup.py b/setup.py
index 8184e24..cbbaa3a 100644
--- a/setup.py
+++ b/setup.py
@@ -1,13 +1,18 @@
 #!/usr/bin/env python
-import glob, os, time, yaml
-from distutils.core import setup
+import glob, os, sys, time, yaml
+from distutils.core import setup, Command
 from distutils.command.build_py import build_py as _build_py
+import unittest
 
 try:
     import subprocess
 except:
     import cobbler.sub_process as subprocess
 
+try:
+    import coverage
+except:
+    converage = None
 
 VERSION = "2.3.1"
 OUTPUT_DIR = "config"
@@ -107,6 +112,46 @@ class build_py(_build_py):
         gen_build_version()
         _build_py.run(self)
 
+#####################################################################
+## Test Command #####################################################
+#####################################################################
+
+class test_command(Command):
+    user_options = []
+
+    def initialize_options(self):
+        pass
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        testfiles = []
+        testdirs = ["koan"]
+
+        for d in testdirs:
+            testdir = os.path.join(os.getcwd(), "tests", d)
+
+            for t in glob.glob(os.path.join(testdir, '*.py')):
+                if t.endswith('__init__.py'):
+                    continue
+                testfile = '.'.join(['tests', d,
+                                     os.path.splitext(os.path.basename(t))[0]])
+                testfiles.append(testfile)
+
+        tests = unittest.TestLoader().loadTestsFromNames(testfiles)
+        runner = unittest.TextTestRunner(verbosity = 1)
+
+        if coverage:
+            coverage.erase()
+            coverage.start()
+
+        result = runner.run(tests)
+
+        if coverage:
+            coverage.stop()
+        sys.exit(int(bool(len(result.failures) > 0 or
+                          len(result.errors) > 0)))
+
 
 #####################################################################
 ## Actual Setup.py Script ###########################################
@@ -136,7 +181,7 @@ if __name__ == "__main__":
 
 
     setup(
-        cmdclass={'build_py': build_py},
+        cmdclass={'build_py': build_py, 'test': test_command},
         name = "cobbler",
         version = VERSION,
         description = "Network Boot and Update Server",
diff --git a/tests/koan/__init__.py b/tests/koan/__init__.py
new file mode 100644
index 0000000..e69de29
-- 
1.7.7.5

_______________________________________________
cobbler mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/cobbler

Reply via email to