def test_cm(): """[Utils] CMLog: test logging.""" if psutil is not None and not __version__.startswith('2.') : cm = utils.CMLog(verbose=True) with open(os.devnull, 'w') as f, redirect_stdout(f): cm.monitor(0.3) while not hasattr(cm, 'cpu'): sleep(0.3) cm.collect() assert len(cm.cpu) == 3 assert len(cm.rss) == 3 assert len(cm.vms) == 3 # Check that it overwrites with open(os.devnull, 'w') as f, redirect_stdout(f): cm.monitor(0.2) while not hasattr(cm, 'cpu'): sleep(0.2) cm.collect() assert len(cm.cpu) == 2 assert len(cm.rss) == 2 assert len(cm.vms) == 2
def test_cm_exception(): """[Utils] CMLog: test collecting un-monitored returns None.""" if psutil is not None and not __version__.startswith('2.'): cm = utils.CMLog(verbose=False) with open(os.devnull, 'w') as f, redirect_stdout(f): out = cm.collect() assert out is None