from glances.thresholds import GlancesThresholdOk from glances.thresholds import GlancesThresholdCareful from glances.thresholds import GlancesThresholdWarning from glances.thresholds import GlancesThresholdCritical from glances.thresholds import GlancesThresholds from glances.plugins.glances_plugin import GlancesPlugin from glances.compat import subsample, range # Global variables # ================= # Init Glances core core = GlancesMain() # Init Glances stats stats = GlancesStats(config=core.get_config(), args=core.get_args()) # Unitest class # ============== print('Unitary tests for Glances %s' % __version__) class TestGlances(unittest.TestCase): """Test Glances class.""" def setUp(self): """The function is called *every time* before test_*.""" print('\n' + '=' * 78) def test_000_update(self): """Update stats (mandatory step for all the stats).
import time import unittest # Global variables # ================= # Init Glances core from glances.main import GlancesMain core = GlancesMain() if not core.is_standalone(): print('ERROR: Glances core should be ran in standalone mode') sys.exit(1) # Init Glances stats from glances.stats import GlancesStats stats = GlancesStats() from glances import __version__ from glances.globals import WINDOWS from glances.outputs.glances_bars import Bar # Unitest class # ============== print('Unitary tests for Glances %s' % __version__) class TestGlances(unittest.TestCase): """Test Glances class.""" def setUp(self): """The function is called *every time* before test_*.""" print('\n' + '=' * 78)
def __init__(self, config=None, args=None): self.config = config self.args = args # Quiet mode self._quiet = args.quiet self.refresh_time = args.time # Init stats start_duration = Counter() start_duration.reset() self.stats = GlancesStats(config=config, args=args) logger.debug("Plugins initialisation duration: {} seconds".format( start_duration.get())) # Modules (plugins and exporters) are loaded at this point # Glances can display the list if asked... if args.modules_list: self.display_modules_list() sys.exit(0) # If process extended stats is disabled by user if not args.enable_process_extended: logger.debug("Extended stats for top process are disabled") glances_processes.disable_extended() else: logger.debug("Extended stats for top process are enabled") glances_processes.enable_extended() # Manage optionnal process filter if args.process_filter is not None: glances_processes.process_filter = args.process_filter if (not WINDOWS) and args.no_kernel_threads: # Ignore kernel threads in process list glances_processes.disable_kernel_threads() # Initial system informations update start_duration.reset() self.stats.update() logger.debug("First stats update duration: {} seconds".format( start_duration.get())) if self.quiet: logger.info("Quiet mode is ON, nothing will be displayed") # In quiet mode, nothing is displayed glances_processes.max_processes = 0 elif args.stdout: logger.info( "Stdout mode is ON, following stats will be displayed: {}". format(args.stdout)) # Init screen self.screen = GlancesStdout(config=config, args=args) elif args.stdout_csv: logger.info( "Stdout CSV mode is ON, following stats will be displayed: {}". format(args.stdout)) # Init screen self.screen = GlancesStdoutCsv(config=config, args=args) else: # Default number of processes to displayed is set to 50 glances_processes.max_processes = 50 # Init screen self.screen = GlancesCursesStandalone(config=config, args=args) # Check the latest Glances version self.outdated = Outdated(config=config, args=args)