Commit b7096783ba823146c85d916eb8957922a90aa511

Authored by Christoph Deil
1 parent 551763bd

Add test function to ctools Python package

cscripts/Makefile.am
... ... @@ -17,12 +17,19 @@ linkscripts = cspull cssens cstsdist cscaldb csresmap \
17 17 cshessobs csobsdef csspec cslightcrv \
18 18 csinfo
19 19  
  20 +testscripts = tests/__init__.py \
  21 + tests/test_unbinned.py \
  22 + tests/test_binned.py
  23 +
  24 +
20 25 # Distribute scripts
21   -EXTRA_DIST = $(binscripts) $(pythonscripts)
  26 +EXTRA_DIST = $(binscripts) $(pythonscripts) $(testscripts)
22 27 binscriptsdir = $(bindir)
23 28 binscripts_DATA = $(binscripts)
24 29 pythonscriptsdir = $(pythondir)/cscripts
25 30 pythonscripts_DATA = $(pythonscripts)
  31 +testscriptsdir = $(pythondir)/cscripts/tests
  32 +testscripts_DATA = $(testscripts)
26 33  
27 34 # Add hook rule to create symbolic links for cscripts
28 35 install-data-hook:
... ...
cscripts/__init__.py
  1 +"""cscripts --- Python scripts from the ctools package.
  2 +
  3 +http://cta.irap.omp.eu/ctools/
  4 +"""
  5 +
  6 +
1 7 # List all scripts in this module
2   -__all__ = ["cscaldb", \
3   - "cshessobs", \
4   - "csinfo", \
5   - "cslightcrv", \
6   - "csobsdef", \
7   - "cspull", \
8   - "csresmap", \
9   - "cssens", \
10   - "csspec", \
11   - "cstsdist", \
12   - "obsutils"]
  8 +__all__ = [
  9 + "cscaldb",
  10 + "cshessobs",
  11 + "csinfo",
  12 + "cslightcrv",
  13 + "csobsdef",
  14 + "cspull",
  15 + "csresmap",
  16 + "cssens",
  17 + "csspec",
  18 + "cstsdist",
  19 + "obsutils",
  20 + "test",
  21 +]
13 22  
14 23 # Import
15 24 from .cscaldb import cscaldb
... ... @@ -22,4 +31,22 @@ from .csresmap import csresmap
22 31 from .cssens import cssens
23 32 from .csspec import csspec
24 33 from .cstsdist import cstsdist
25   -import obsutils
26 34 \ No newline at end of file
  35 +from . import obsutils
  36 +
  37 +
  38 +def test():
  39 + """Run ctools tests.
  40 + """
  41 + import unittest
  42 + from .tests.test_unbinned import TestUnbinnedAnalysis
  43 + from .tests.test_binned import TestBinnedAnalysis
  44 + # suite = unittest.TestLoader().loadTestsFromTestCase(TestUnbinnedAnalysis)
  45 + # unittest.TextTestRunner(verbosity=2).run(suite)
  46 + test_suite = unittest.TestSuite()
  47 +
  48 + # Test cases must be listed manually here ...
  49 + # we currently don't use unittest for test collection
  50 + test_suite.addTest(unittest.makeSuite(TestUnbinnedAnalysis))
  51 + test_suite.addTest(unittest.makeSuite(TestBinnedAnalysis))
  52 +
  53 + unittest.TextTestRunner(verbosity=2).run(test_suite)
... ...
cscripts/tests/__init__.py 0 โ†’ 100644
  1 +"""Tests that can be run for an installed ctools package.
  2 +"""
... ...
cscripts/tests/test_binned.py 0 โ†’ 100644
  1 +"""Test binned analysis.
  2 +"""
  3 +import unittest
  4 +
  5 +class TestBinnedAnalysis(unittest.TestCase):
  6 +
  7 + def test_it(self):
  8 + self.assertEqual('foo'.upper(), 'FOO')
... ...
cscripts/tests/test_unbinned.py 0 โ†’ 100644
  1 +"""Test unbinned analysis.
  2 +"""
  3 +import unittest
  4 +
  5 +class TestUnbinnedAnalysis(unittest.TestCase):
  6 +
  7 + def test_it(self):
  8 + self.assertEqual('foo'.upper(), 'FOO')
... ...