Ejemplo n.º 1
0
    def stopTestRun(self):
        self.hook.stopTestRun()
        self._stream.flush()
        self._stream.close()
        run_id = self._name()
        if not self._run_id:
            final_path = os.path.join(self._repository.base, str(run_id))
            atomicish_rename(self.fname, final_path)
        if self._metadata:
            db = my_dbm.open(self._repository._path('meta.dbm'), 'c')
            try:
                dbm_run_id = str(run_id)
                db[dbm_run_id] = str(self._metadata)
            finally:
                db.close()

        # May be too slow, but build and iterate.
        db = my_dbm.open(self._repository._path('times.dbm'), 'c')
        try:
            db_times = {}
            for key, value in self._times.items():
                if type(key) != str:
                    key = key.encode('utf8')
                db_times[key] = value
            if getattr(db, 'update', None):
                db.update(db_times)
            else:
                for key, value in db_times.items():
                    db[key] = value
        finally:
            db.close()
        if not self._run_id:
            self._run_id = run_id
Ejemplo n.º 2
0
 def _get_metadata(self, run_id):
     db = my_dbm.open(self._path('meta.dbm'), 'c')
     try:
         metadata = db.get(str(run_id))
     finally:
         db.close()
     return metadata
Ejemplo n.º 3
0
 def find_metadata(self, metadata):
     run_ids = []
     db = my_dbm.open(self._path('meta.dbm'), 'c')
     try:
         for run_id in db:
             if db.get(run_id) == metadata:
                 run_ids.append(run_id)
     finally:
         db.close()
     return run_ids
Ejemplo n.º 4
0
 def _get_test_times(self, test_ids):
     # May be too slow, but build and iterate.
     # 'c' because an existing repo may be missing a file.
     try:
         db = my_dbm.open(self._path('times.dbm'), 'c')
     except my_dbm.error:
         os.remove(self._path('times.dbm'))
         db = my_dbm.open(self._path('times.dbm'), 'c')
     try:
         result = {}
         for test_id in test_ids:
             if type(test_id) != str:
                 test_id = test_id.encode('utf8')
             stripped_test_id = utils.cleanup_test_name(test_id)
             # gdbm does not support get().
             try:
                 duration = db[stripped_test_id]
             except KeyError:
                 duration = None
             if duration is not None:
                 result[test_id] = float(duration)
         return result
     finally:
         db.close()