def setup (self): # # SQLite DB for testing # self.db_fd, self.db_name = tempfile.mkstemp (suffix='.db') # # create the collector # self.collector = CpuStatsCollector (1, self.db_name)
class TestCpuStatsCollector ( ): """ Class for testing CpuStatsCollector functionality.- """ def setup (self): # # SQLite DB for testing # self.db_fd, self.db_name = tempfile.mkstemp (suffix='.db') # # create the collector # self.collector = CpuStatsCollector (1, self.db_name) def test_run (self): """ Checks the collector 'run' method works correctly.- """ self.collector.start ( ) time.sleep (3) self.collector.shutdown ( ) s = self.collector.sa_session last_time = None q = s.query (CpuUsageEntity).order_by (CpuUsageEntity.time.desc ( )) assert (q.count ( ) > 0) for m in q: assert (m.user >= 0.0 and m.user < 100.0) assert (m.system >= 0.0 and m.system < 100.0) if last_time is not None: assert (last_time > m.time + self.collector.interval) last_time = m.time def teardown (self): os.close (self.db_fd) os.unlink (self.db_name)
esky_wrapper = esky.Esky (esky.util.appdir_from_executable (sys.executable), update_url) else: esky_wrapper = type ('Enum', ( ), {'version': 'NOT FROZEN'}) # # Esky packager needs this to correctly freeze the application # cherrypy.engine.autoreload.unsubscribe ( ) # # create the CPU-usage statistics collector # stats_db = os.path.join (BASE_PATH, cherrypy.config.get ('stats.database')) cpu_stat = CpuStatsCollector (int (cherrypy.config.get ('stats.cpu.interval')), stats_db) # # start it and register to the event bus to stop it when CherryPy exits # cpu_stat.start ( ) cherrypy.engine.subscribe ('stop', cpu_stat.shutdown) # # start the daemon # cherrypy.tree.mount (Daemon (this_client, esky_wrapper), '/') cherrypy.engine.start ( ) cherrypy.engine.block ( ) #