From b7096783ba823146c85d916eb8957922a90aa511 Mon Sep 17 00:00:00 2001 From: Christoph Deil Date: Fri, 3 Jul 2015 12:03:04 +0200 Subject: [PATCH] Add test function to ctools Python package --- cscripts/Makefile.am | 9 ++++++++- cscripts/__init__.py | 51 +++++++++++++++++++++++++++++++++++++++------------ cscripts/tests/__init__.py | 2 ++ cscripts/tests/test_binned.py | 8 ++++++++ cscripts/tests/test_unbinned.py | 8 ++++++++ 5 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 cscripts/tests/__init__.py create mode 100644 cscripts/tests/test_binned.py create mode 100644 cscripts/tests/test_unbinned.py diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am index 0a456ec..6478134 100644 --- a/cscripts/Makefile.am +++ b/cscripts/Makefile.am @@ -17,12 +17,19 @@ linkscripts = cspull cssens cstsdist cscaldb csresmap \ cshessobs csobsdef csspec cslightcrv \ csinfo +testscripts = tests/__init__.py \ + tests/test_unbinned.py \ + tests/test_binned.py + + # Distribute scripts -EXTRA_DIST = $(binscripts) $(pythonscripts) +EXTRA_DIST = $(binscripts) $(pythonscripts) $(testscripts) binscriptsdir = $(bindir) binscripts_DATA = $(binscripts) pythonscriptsdir = $(pythondir)/cscripts pythonscripts_DATA = $(pythonscripts) +testscriptsdir = $(pythondir)/cscripts/tests +testscripts_DATA = $(testscripts) # Add hook rule to create symbolic links for cscripts install-data-hook: diff --git a/cscripts/__init__.py b/cscripts/__init__.py index 56aa7ae..c339834 100644 --- a/cscripts/__init__.py +++ b/cscripts/__init__.py @@ -1,15 +1,24 @@ +"""cscripts --- Python scripts from the ctools package. + +http://cta.irap.omp.eu/ctools/ +""" + + # List all scripts in this module -__all__ = ["cscaldb", \ - "cshessobs", \ - "csinfo", \ - "cslightcrv", \ - "csobsdef", \ - "cspull", \ - "csresmap", \ - "cssens", \ - "csspec", \ - "cstsdist", \ - "obsutils"] +__all__ = [ + "cscaldb", + "cshessobs", + "csinfo", + "cslightcrv", + "csobsdef", + "cspull", + "csresmap", + "cssens", + "csspec", + "cstsdist", + "obsutils", + "test", +] # Import from .cscaldb import cscaldb @@ -22,4 +31,22 @@ from .csresmap import csresmap from .cssens import cssens from .csspec import csspec from .cstsdist import cstsdist -import obsutils \ No newline at end of file +from . import obsutils + + +def test(): + """Run ctools tests. + """ + import unittest + from .tests.test_unbinned import TestUnbinnedAnalysis + from .tests.test_binned import TestBinnedAnalysis + # suite = unittest.TestLoader().loadTestsFromTestCase(TestUnbinnedAnalysis) + # unittest.TextTestRunner(verbosity=2).run(suite) + test_suite = unittest.TestSuite() + + # Test cases must be listed manually here ... + # we currently don't use unittest for test collection + test_suite.addTest(unittest.makeSuite(TestUnbinnedAnalysis)) + test_suite.addTest(unittest.makeSuite(TestBinnedAnalysis)) + + unittest.TextTestRunner(verbosity=2).run(test_suite) diff --git a/cscripts/tests/__init__.py b/cscripts/tests/__init__.py new file mode 100644 index 0000000..24b20ee --- /dev/null +++ b/cscripts/tests/__init__.py @@ -0,0 +1,2 @@ +"""Tests that can be run for an installed ctools package. +""" diff --git a/cscripts/tests/test_binned.py b/cscripts/tests/test_binned.py new file mode 100644 index 0000000..ec29682 --- /dev/null +++ b/cscripts/tests/test_binned.py @@ -0,0 +1,8 @@ +"""Test binned analysis. +""" +import unittest + +class TestBinnedAnalysis(unittest.TestCase): + + def test_it(self): + self.assertEqual('foo'.upper(), 'FOO') diff --git a/cscripts/tests/test_unbinned.py b/cscripts/tests/test_unbinned.py new file mode 100644 index 0000000..eb5dd12 --- /dev/null +++ b/cscripts/tests/test_unbinned.py @@ -0,0 +1,8 @@ +"""Test unbinned analysis. +""" +import unittest + +class TestUnbinnedAnalysis(unittest.TestCase): + + def test_it(self): + self.assertEqual('foo'.upper(), 'FOO') -- libgit2 0.21.4