Commits

Anonymous committed 2d61b0f

fixing up utests and python clid.db deciphering code

Comments (0)

Files changed (5)

+2009-01-19  Sebastien Binet  <binet@farnsworth>
+
+	* tagging CLIDComps-00-05-01
+	* fixing up utests and python clid.db deciphering code
+	* M python/clidGenerator.py
+	* M test/CLIDRegistry_test.cxx
+	* M test/ClassIDSvc_test.cxx
+	* M test/_clid_unittest.py
+
 2009-01-15  Sebastien Binet  <binet@farnsworth>
 
 	* tagging CLIDComps-00-05-00

python/clidGenerator.py

 # @author CETull@lbl.gov
 # @brief Athena CLID Generator Class
 #
-import string, re, os
+import string, re, os, csv
 
 ## Athena CLID Generator Class
 class clidGenerator:
     "Athena CLID Generator"
     __clidGenerator_type = "Basic"
-    __clidGenerator_version = "$Revision: 1.2 $"
+    __clidGenerator_version = "$Revision: 1.3 $"
     # CLID Mask: Determines bits used for CLID
     __mask = 0x0FFFFFFF
     # CLID Repositories - Dictionaries of CLID<=>Name
         try:
             for cliddb in self.__cliddbs:
                 if os.path.isfile(cliddb):
-                    input = open(cliddb,'r')
-                    s = input.readlines()
-                    for l in s:
-                        ll = string.split(l)
-                        if len(ll) == 3:
-                            self.__clidRep[int(ll[0])] = ll[1]
-                            self.__nameRep[ll[1]] = int(ll[0])
-                            self.__clidPkg[int(ll[0])] = ll[2]
-                    input.close()
+                    for row in csv.reader (open(cliddb, 'r'),
+                                           delimiter=';'):
+                        row = [i.strip() for i in row]
+                        if len(row) >= 3:
+                            self.__clidRep[int(row[0])] = row[1]
+                            self.__nameRep[row[1]] = int(row[0])
+                            self.__clidPkg[int(row[0])] = row[2]
                 else:
                     print "No CLID DataBase file <%s> " % cliddb        
-        except:
-            print "Error reading from CLID DataBase files <%s> " %  self.__cliddbs
+        except Exception, err:
+            print "Error reading from CLID DataBase files <%s>:\n%s " %  (
+                self.__cliddbs,
+                err)
+            
     def setCLIDDB(self, db, debug):
         "Initializes a CLID Generator object with a CLID Database"
         if db:

test/CLIDRegistry_test.cxx

 /** @file CLIDRegistry_test.cxx 
  *  @brief unit test for CLIDRegistry
  *
- * $Id: CLIDRegistry_test.cxx,v 1.1 2007-12-14 00:40:44 binet Exp $
+ * $Id: CLIDRegistry_test.cxx,v 1.2 2009-01-19 17:02:55 binet Exp $
  * @author Paolo Calafiura <pcalafiura@lbl.gov> - ATLAS Collaboration
  */
 
   cerr << "*** CLIDRegistry_test starts ***" <<endl;
   Athena::PackageInfo info(PACKAGE_VERSION);
 #ifdef COMPILEFAIL
-  CLIDRegistry::addEntry<12>("Foo", info);
+  CLIDRegistry::addEntry<12>("Foo", info, "Foo");
   //no upper limit  CLIDRegistry::addEntry<1245736740>("Foo", info);
 #endif
-  CLIDRegistry::addEntry<1234>("Foo", info);
-  CLIDRegistry::addEntry<4321>("Bar", info);
+  CLIDRegistry::addEntry<1234>("Foo", info, "Foo");
+  CLIDRegistry::addEntry<4321>("Bar", info, "Bar");
   assert( distance(CLIDRegistry::begin(), CLIDRegistry::end()) == 2 );
   assert( get<0>(*CLIDRegistry::begin()) == 1234 );
   assert( get<1>(*CLIDRegistry::begin()) == "Foo" );

test/ClassIDSvc_test.cxx

 /** @file ClassIDSvc_test.cxx  
  * @brief unit test for ClassIDSvc
  * @author ATLAS Collaboration
- * $Id: ClassIDSvc_test.cxx,v 1.4 2007-12-14 00:04:22 binet Exp $
+ * $Id: ClassIDSvc_test.cxx,v 1.5 2009-01-19 17:02:55 binet Exp $
  ***************************************************************************/
 
 #undef NDEBUG
   ASSERTERROR(pClassIDSvc->setTypePackageForID(9945, "Bli", info).isSuccess());
   assert(pClassIDSvc->setTypePackageForID(7890, "Bla", info2).isSuccess());
   assert(pClassIDSvc->setTypePackageForID(7890, " Bla", info2).isSuccess());
-  assert(pClassIDSvc->setTypePackageForID(7890, "   Bl a ", info2).isSuccess());
-  assert(pClassIDSvc->setTypePackageForID(7890, " B  l a ", info2).isSuccess());
+  assert(pClassIDSvc->setTypePackageForID(7890, "   Bl a ", info2).isFailure());
+  assert(pClassIDSvc->setTypePackageForID(7890, " B  l a ", info2).isFailure());
   assert(pClassIDSvc->setTypePackageForID(7890, "Bla   ", info2).isSuccess());
+  assert(pClassIDSvc->setTypePackageForID(7890, " Bla  ", info2).isSuccess());
 
 
   string name; 

test/_clid_unittest.py

    def test2GenClids( self ):
       """Testing clidGenerator with no clid.db"""
       # get rid of expected error message
-      sys.stdout = file("dummyIgnore.txt", 'w')
+      sys.stdout = open("dummyIgnore.txt", 'w')
       self.cgen = clidGenerator("NOTTHERE.db")
       sys.stdout = sys.__stdout__
-      os.unlink("dummyIgnore.txt");
+      os.remove("dummyIgnore.txt");
       
       self.assertEqual( 245732527, self.cgen.genClidFromName("DataObject") )
       self.assertEqual( 205083834, self.cgen.genClidFromName("Data<Foo23_45___Bar_, dsfl__>") )