|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# |
|
3
|
|
|
# Glances - An eye on your system |
|
4
|
|
|
# |
|
5
|
|
|
# SPDX-FileCopyrightText: 2025 Nicolas Hennion <[email protected]> |
|
6
|
|
|
# |
|
7
|
|
|
# SPDX-License-Identifier: LGPL-3.0-only |
|
8
|
|
|
# |
|
9
|
|
|
|
|
10
|
|
|
"""Glances API unitary tests suite.""" |
|
11
|
|
|
|
|
12
|
|
|
from glances import __version__, api |
|
13
|
|
|
|
|
14
|
|
|
# Global variables |
|
15
|
|
|
# ================= |
|
16
|
|
|
|
|
17
|
|
|
# Init Glances API |
|
18
|
|
|
# test_config = core.get_config() |
|
19
|
|
|
# test_args = core.get_args() |
|
20
|
|
|
gl = api.GlancesAPI(args_begin_at=2) |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
# Pytest functions to test the Glances API version |
|
24
|
|
|
def test_glances_api_version(): |
|
25
|
|
|
assert gl.__version__ == __version__.split('.')[0] |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
def test_glances_api_plugins(): |
|
29
|
|
|
# Check that the plugins list is not empty |
|
30
|
|
|
assert len(gl.plugins()) > 0 |
|
31
|
|
|
# Check that the cpu plugin is in the list of plugins |
|
32
|
|
|
assert 'cpu' in gl.plugins() |
|
33
|
|
|
# Check that the network plugin is in the list of plugins |
|
34
|
|
|
assert 'network' in gl.plugins() |
|
35
|
|
|
# Check that the processcount plugin is in the list of plugins |
|
36
|
|
|
assert 'processcount' in gl.plugins() |
|
37
|
|
|
# Check that the processlist plugin is in the list of plugins |
|
38
|
|
|
assert 'processlist' in gl.plugins() |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
def test_glances_api_plugin_cpu(): |
|
42
|
|
|
# Check that the cpu plugin is available |
|
43
|
|
|
assert gl.cpu is not None |
|
44
|
|
|
# Get list of keys (cpu stat fields) |
|
45
|
|
|
keys = gl.cpu.keys() |
|
46
|
|
|
# Check that the keys are not empty |
|
47
|
|
|
assert len(keys) > 0 |
|
48
|
|
|
# Check that the cpu plugin has a total item |
|
49
|
|
|
assert gl.cpu['total'] is not None |
|
50
|
|
|
# and is a float |
|
51
|
|
|
assert isinstance(gl.cpu['total'], float) |
|
52
|
|
|
# test the get method |
|
53
|
|
|
assert isinstance(gl.cpu.get('total'), float) |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
def test_glances_api_plugin_network(): |
|
57
|
|
|
# Check that the network plugin is available |
|
58
|
|
|
assert gl.network is not None |
|
59
|
|
|
# Get list of keys (interfaces) |
|
60
|
|
|
keys = gl.network.keys() |
|
61
|
|
|
# Check that the keys are not empty |
|
62
|
|
|
assert len(keys) > 0 |
|
63
|
|
|
# Check that the first item is a dictionary |
|
64
|
|
|
assert isinstance(gl.network[keys[0]], dict) |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
def test_glances_api_plugin_process(): |
|
68
|
|
|
# Get list of keys (processes) |
|
69
|
|
|
keys = gl.processcount.keys() |
|
70
|
|
|
# Check that the keys are not empty |
|
71
|
|
|
assert len(keys) > 0 |
|
72
|
|
|
# Check that processcount total is > 0 |
|
73
|
|
|
assert gl.processcount['total'] > 0 |
|
74
|
|
|
|
|
75
|
|
|
# Get list of keys (processes) |
|
76
|
|
|
keys = gl.processlist.keys() |
|
77
|
|
|
# Check that first key is an integer (PID) |
|
78
|
|
|
assert isinstance(keys[0], int) |
|
79
|
|
|
# Check that the first item is a dictionary |
|
80
|
|
|
assert isinstance(gl.processlist[keys[0]], dict) |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
def test_glances_api_limits(): |
|
84
|
|
|
assert isinstance(gl.cpu.limits, dict) |
|
85
|
|
|
|