[SCM] Control pipeline recipes from the European Southern Observatory branch, debian, updated. upstream/0.3.5.1-44-g3dc4a3b

Ole Streicher debian at liska.ath.cx
Mon Nov 26 12:25:26 UTC 2012


The following commit has been merged in the debian branch:
commit 65b7246efdb745b4d25cbb7d6ded5e36516a80ff
Author: Ole Streicher <debian at liska.ath.cx>
Date:   Mon Nov 26 12:09:50 2012 +0100

    updated test to new updatream version

diff --git a/test/TestRecipe.py b/test/TestRecipe.py
index 22cac17..16f84f9 100644
--- a/test/TestRecipe.py
+++ b/test/TestRecipe.py
@@ -183,9 +183,11 @@ class RecipeParams(RecipeTestCase):
 
     def test_dotted_par(self):
         '''Use a parameter that has a dot in its alias'''
-        self.assertEqual(self.recipe.param.dot_opt, 
+        self.assertEqual(self.recipe.param.dot.opt,
+                         self.recipe.param.dot['opt'])
+        self.assertEqual(self.recipe.param.dot.opt,
                          self.recipe.param['dot.opt'])
-        self.assertEqual(self.recipe.param.dot_opt, 
+        self.assertEqual(self.recipe.param.dot.opt,
                          self.recipe.param['iiinstrument.rtest.dotted.opt'])
 
     def test_iterate(self):
@@ -227,8 +229,11 @@ class RecipeParams(RecipeTestCase):
         '''[TAB] completition. 
         This requires to have   the __dir__() method working.
         '''
-        self.assertEqual(self.recipe.param.__dir__(), 
-                         [ p.name.replace('.','_') for p in self.recipe.param ])
+        self.assertEqual(set(self.recipe.param.__dir__()),
+                         set(p.name if '.' not in p.name
+                             else p.name.split('.', 1)[0]
+                             for p in self.recipe.param
+                             ))
 
 class RecipeCalib(RecipeTestCase):
     def test_set(self):
@@ -272,16 +277,6 @@ class RecipeExec(RecipeTestCase):
                 pyfits.PrimaryHDU(numpy.random.random_integers(0, 65000,
                                                                self.image_size))])
 
-    def test_frames_keyword(self):
-        '''Raw and calibration frames specified as keywords'''
-        self.recipe.tag = None
-        res = self.recipe(raw_RRRECIPE_DOCATG_RAW = self.raw_frame, 
-                          calib_FLAT = self.flat_frame)
-        self.assertTrue(isinstance(res, cpl.Result))
-        self.assertTrue(isinstance(res.THE_PRO_CATG_VALUE, pyfits.HDUList))
-        self.assertTrue(abs(self.raw_frame[0].data 
-                            - res.THE_PRO_CATG_VALUE[0].data).max() == 0)
-
     def test_frames_keyword_dict(self):
         '''Raw and calibration frames specified as keyword dict'''
         self.recipe.tag = None
@@ -296,7 +291,7 @@ class RecipeExec(RecipeTestCase):
         '''Raw frame specified as keyword, calibration frame set in recipe'''
         self.recipe.tag = None
         self.recipe.calib.FLAT = self.flat_frame
-        res = self.recipe(raw_RRRECIPE_DOCATG_RAW = self.raw_frame)
+        res = self.recipe({'RRRECIPE_DOCATG_RAW':self.raw_frame})
         self.assertTrue(isinstance(res, cpl.Result))
         self.assertTrue(isinstance(res.THE_PRO_CATG_VALUE, pyfits.HDUList))
 
@@ -360,18 +355,17 @@ class RecipeExec(RecipeTestCase):
         hdu = pyfits.open(res.THE_PRO_CATG_VALUE)
         self.assertTrue(isinstance(hdu, pyfits.HDUList))
 
-    def test_param_keyword(self):
-        '''Parameter handling via keyword arg'''
-        res = self.recipe(self.raw_frame, 
-                          param_stropt = 'more').THE_PRO_CATG_VALUE
-        self.assertEqual(res[0].header['HIERARCH ESO QC STROPT'], 'more')
-
     def test_param_keyword_dict(self):
         '''Parameter handling via keyword dict'''
         res = self.recipe(self.raw_frame, 
                           param = { 'stropt':'more' }).THE_PRO_CATG_VALUE
         self.assertEqual(res[0].header['HIERARCH ESO QC STROPT'], 'more')
 
+    def test_param_keyword_dict_wrong(self):
+        '''Parameter handling via keyword dict'''
+        self.assertRaises(KeyError, self.recipe,
+                          self.raw_frame, param = { 'wrong':True })
+
     def test_param_setting(self):
         '''Parameter handling via recipe setting'''
         self.recipe.param.stropt = 'more'
@@ -389,7 +383,7 @@ class RecipeExec(RecipeTestCase):
     def test_param_overwrite(self):
         '''Overwrite the recipe setting param via via keyword arg'''
         self.recipe.param.stropt = 'more'
-        res = self.recipe(self.raw_frame, param_stropt = 'less').THE_PRO_CATG_VALUE
+        res = self.recipe(self.raw_frame, param = {'stropt':'less'}).THE_PRO_CATG_VALUE
         self.assertEqual(res[0].header['HIERARCH ESO QC STROPT'], 'less')
 
     def test_param_types(self):
@@ -408,37 +402,31 @@ class RecipeExec(RecipeTestCase):
         self.assertEqual(res[0].header['HIERARCH ESO QC ENUMOPT'], 'third')
         self.assertEqual(res[0].header['HIERARCH ESO QC RANGEOPT'], 0.125)
         
+    def test_environment_setting(self):
+        '''Additional environment parameter via recipe setting'''
+        self.recipe.env['TESTENV'] = 'unkk'
+        res = self.recipe(self.raw_frame).THE_PRO_CATG_VALUE
+        self.assertEqual(res[0].header['HIERARCH ESO QC TESTENV'], 'unkk')
+
+    def test_environment_keyword(self):
+        '''Additional environment parameter via recipe call keyword'''
+        res = self.recipe(self.raw_frame, 
+                          env = {'TESTENV':'kknu'}).THE_PRO_CATG_VALUE
+        self.assertEqual(res[0].header['HIERARCH ESO QC TESTENV'], 'kknu')
+
     def test_error(self):
         '''Error handling'''
         self.recipe.tag = 'some_unknown_tag'
         self.assertRaises(cpl.CplError, self.recipe, self.raw_frame)
 
-    def test_corrupted(self):
-        '''Handling of recipe crashes because of corrupted memory'''
-        self.recipe.param.crashing = 'free'
-        self.assertRaises(cpl.RecipeCrash, self.recipe, self.raw_frame)
-
-    def test_segfault(self):
-        '''Handling of recipe crashes because of segmentation fault'''
-        self.recipe.param.crashing = 'segfault'
-        self.assertRaises(cpl.RecipeCrash, self.recipe, self.raw_frame)
-
-    def test_cleanup_after_crash(self):
-        '''Test that a second run after a crash will succeed'''
-        output_dir = os.path.join(self.temp_dir, 'out')
-        self.recipe.output_dir = output_dir
-        self.recipe.param.crashing = 'segfault'
-        self.assertRaises(cpl.RecipeCrash, self.recipe, self.raw_frame)
-        del self.recipe.param.crashing 
-        self.recipe(self.raw_frame)
-
     def test_parallel(self):
         '''Parallel execution'''
         results = list()
         for i in range(20):
             # mark each frame so that we can see their order
             self.raw_frame[0].header.update('HIERARCH ESO RAW1 NR', i)
-            results.append(self.recipe(self.raw_frame, param_intopt = i,
+            results.append(self.recipe(self.raw_frame, param = {'intopt':i},
+                                       env = {'TESTENV':('knu%02i' % i)},
                                        threaded = True))
         for i, res in enumerate(results):
             # check if we got the correct type
@@ -446,6 +434,9 @@ class RecipeExec(RecipeTestCase):
             # check if we have the correct parameter
             self.assertEqual(res.THE_PRO_CATG_VALUE[0].header[
                     'HIERARCH ESO QC INTOPT'], i)
+            # check if we have the correct environment
+            self.assertEqual(res.THE_PRO_CATG_VALUE[0].header[
+                    'HIERARCH ESO QC TESTENV'], ('knu%02i' % i))
             # check if we have the correct input frame
             self.assertEqual(res.THE_PRO_CATG_VALUE[0].header[
                     'HIERARCH ESO RAW1 NR'], i)
@@ -482,6 +473,26 @@ class RecipeExec(RecipeTestCase):
         self.assertEqual(len(md5sum), 
                          len('9d123996fa9a7bda315d07e063043454'))
 
+class RecipeCrashing(RecipeTestCase):
+    def test_corrupted(self):
+        '''Handling of recipe crashes because of corrupted memory'''
+        self.recipe.param.crashing = 'free'
+        self.assertRaises(cpl.RecipeCrash, self.recipe, self.raw_frame)
+
+    def test_segfault(self):
+        '''Handling of recipe crashes because of segmentation fault'''
+        self.recipe.param.crashing = 'segfault'
+        self.assertRaises(cpl.RecipeCrash, self.recipe, self.raw_frame)
+
+    def test_cleanup_after_crash(self):
+        '''Test that a second run after a crash will succeed'''
+        output_dir = os.path.join(self.temp_dir, 'out')
+        self.recipe.output_dir = output_dir
+        self.recipe.param.crashing = 'segfault'
+        self.assertRaises(cpl.RecipeCrash, self.recipe, self.raw_frame)
+        del self.recipe.param.crashing
+        self.recipe(self.raw_frame)
+
 class RecipeRes(RecipeTestCase):
     def setUp(self):
         RecipeTestCase.setUp(self)
@@ -508,9 +519,15 @@ class RecipeRes(RecipeTestCase):
             self.assertTrue(isinstance(hdu, pyfits.HDUList))
 
 class RecipeEsorex(CplTestCase):
+    def setUp(self):
+        CplTestCase.setUp(self)
+        self.temp_dir = tempfile.mkdtemp()
+
     def tearDown(self):
         CplTestCase.tearDown(self)
-        cpl.msg.level = cpl.msg.OFF
+        cpl.esorex.msg.level = cpl.esorex.msg.OFF
+        cpl.esorex.log.level = cpl.esorex.msg.OFF
+        shutil.rmtree(self.temp_dir)
 
     def test_read_sof(self):
         '''Read a SOF file'''
@@ -538,12 +555,34 @@ class RecipeEsorex(CplTestCase):
         
     def test_esorex_init(self):
         '''Init CPL from an esorex.rc file'''
-        rcfile = 'esorex.caller.recipe-dir=/some/dir\n' \
-        'esorex.caller.msg-level=debug'
+        rcfile = '''esorex.caller.recipe-dir=/some/dir
+        esorex.caller.msg-level=debug
+        esorex.caller.log-level=info
+        esorex.caller.log-dir=%s
+        esorex.caller.log-file=some.log''' % self.temp_dir
         cpl.esorex.init(rcfile)
-        self.assertEqual(cpl.msg.level, cpl.msg.DEBUG)
+        self.assertEqual(cpl.esorex.msg.level, cpl.esorex.msg.DEBUG)
+        self.assertEqual(cpl.esorex.log.level, cpl.esorex.msg.INFO)
+        self.assertEqual(cpl.esorex.log.dir, self.temp_dir)
+        self.assertEqual(cpl.esorex.log.filename, 'some.log')
         self.assertEqual(cpl.Recipe.path, ['/some/dir'])
 
+    def test_esorex_log(self):
+        '''Write a logfile controlled by the convienence logger'''
+        dirname = os.path.join(self.temp_dir, 'log')
+        filename = 'python-cpl.log'
+        log_msg = 'Esorex convienence log'
+        os.mkdir(dirname)
+        cpl.esorex.log.dir = dirname
+        cpl.esorex.log.filename = filename
+        cpl.esorex.log.level = cpl.esorex.log.INFO
+        filename = os.path.join(dirname, filename)
+        logging.getLogger('cpl').info(log_msg)
+        self.assertTrue(os.path.exists(filename))
+        log_content = open(filename).read()
+        self.assertTrue(log_msg in log_content)
+        self.assertTrue('INFO' in log_content)
+
 class RecipeLog(RecipeTestCase):
     def setUp(self):
         RecipeTestCase.setUp(self)
@@ -570,6 +609,7 @@ class RecipeLog(RecipeTestCase):
 
     def test_logging_DEBUG(self):
         '''Injection of CPL messages into the python logging system'''
+        self.handler.clear()
         logging.getLogger().setLevel(logging.DEBUG)
         self.recipe(self.raw_frame)
 
@@ -621,6 +661,22 @@ class RecipeLog(RecipeTestCase):
         self.recipe(self.raw_frame, logname = 'othername')
         self.assertNotEqual(len(self.other_handler.logs), 0)
 
+    def test_logging_multiline(self):
+        '''Multiple lines in messages'''
+        self.handler.clear()
+        logging.getLogger('cpl.rtest').setLevel(logging.INFO)
+        self.recipe(self.raw_frame)
+        # check that the multi line log sequence appears
+        multiline = 0
+        tag = 'multiline#'
+        for l in self.handler.logs:
+            if tag not in l.msg:
+                continue
+            i = int(l.msg[l.msg.index(tag)+len(tag):].split()[0])
+            self.assertEqual(multiline + 1, i)
+            multiline = i
+        self.assertEqual(multiline, 3)
+
     def test_result(self):
         '''"log" attribute of the result object'''
         res = self.recipe(self.raw_frame)
@@ -708,7 +764,7 @@ class ProcessingInfo(RecipeTestCase):
     def test_version(self):
         '''Version information'''
         self.assertEqual(self.pinfo.version[0], self.recipe.version[0])
-        self.assertEqual(self.pinfo.cpl_version, 'cpl-%s' % cpl.lib_version)
+        self.assertEqual(self.pinfo.cpl_version, 'cpl-%s' % self.recipe.cpl_version)
 
     def test_md5(self):
         '''MD5 checksums'''
diff --git a/test/iiinstrumentp/recipes/rtest.c b/test/iiinstrumentp/recipes/rtest.c
index 3632f20..0e3fa89 100644
--- a/test/iiinstrumentp/recipes/rtest.c
+++ b/test/iiinstrumentp/recipes/rtest.c
@@ -365,6 +365,9 @@ static int rtest(cpl_frameset            * frameset,
     cpl_image *image = cpl_image_load(cpl_frame_get_filename(rawframe),
 				      CPL_TYPE_FLOAT, 0, 0);
 
+    /* A multiline debug message */
+    cpl_msg_info(cpl_func, "multiline#1\nmultiline#2\nmultiline#3");
+
     /* Do some fake processing */
     usleep((unsigned int)(1e6*sleep_secs));
 
@@ -388,6 +391,12 @@ static int rtest(cpl_frameset            * frameset,
 	cpl_propertylist_append_string(qclist, "ESO QC ENUMOPT", "(null)");
     }
     cpl_propertylist_append_double(qclist, "ESO QC RANGEOPT", range_option);
+    const char *testenv = getenv("TESTENV");
+    if (testenv != NULL) {
+	cpl_propertylist_append_string(qclist, "ESO QC TESTENV", testenv);
+    } else {
+	cpl_propertylist_append_string(qclist, "ESO QC TESTENV", "(null)");
+    }
 
     prestate = cpl_errorstate_get();
 

-- 
Control pipeline recipes from the European Southern Observatory



More information about the debian-science-commits mailing list