Test Failed
Push — develop ( c8a592...8fb49d )
by Nicolas
02:36 queued 14s
created

conftest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 4

3 Functions

Rating   Name   Duplication   Size   Complexity  
A glances_stats() 0 6 1
A firefox_browser() 0 15 1
A glances_webserver() 0 13 2
1
#!/usr/bin/env python
2
#
3
# Glances - An eye on your system
4
#
5
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <[email protected]>
6
#
7
# SPDX-License-Identifier: LGPL-3.0-only
8
#
9
10
"""Glances unitary tests suite for the WebUI.
11
12
Need chromedriver command line (example on Ubuntu system):
13
$ sudo apt install chromium-chromedriver
14
15
The chromedriver command line should be in your path (/usr/bin)
16
"""
17
18
import os
19
import shlex
20
import subprocess
21
import time
22
23
import pytest
24
from selenium import webdriver
25
from selenium.webdriver import ChromeOptions
26
from selenium.webdriver.chrome.service import Service as ChromeService
27
28
from glances.main import GlancesMain
29
from glances.stats import GlancesStats
30
31
SERVER_PORT = 61234
32
URL = f"http://localhost:{SERVER_PORT}"
33
34
35
@pytest.fixture(scope="session")
36
def glances_stats():
37
    core = GlancesMain(args_begin_at=2)
38
    stats = GlancesStats(config=core.get_config(), args=core.get_args())
39
    yield stats
40
    stats.end()
41
42
43
@pytest.fixture(scope="session")
44
def glances_webserver():
45
    if os.path.isfile('./venv/bin/python'):
46
        cmdline = "./venv/bin/python"
47
    else:
48
        cmdline = "python"
49
    cmdline += f" -m glances -B 0.0.0.0 -w --browser -p {SERVER_PORT} -C ./conf/glances.conf"
50
    args = shlex.split(cmdline)
51
    pid = subprocess.Popen(args)
52
    time.sleep(3)
53
    yield pid
54
    pid.terminate()
55
    time.sleep(1)
56
57
58
@pytest.fixture(scope="session")
59
def firefox_browser():
60
    """Init Firefox browser."""
61
    opt = ChromeOptions()
62
    opt.add_argument("--headless")
63
    opt.add_argument("--start-maximized")
64
    srv = ChromeService()
65
    driver = webdriver.Chrome(options=opt, service=srv)
66
67
    # Yield the WebDriver instance
68
    driver.implicitly_wait(10)
69
    yield driver
70
71
    # Close the WebDriver instance
72
    driver.quit()
73