Improve unittest #2757

This commit is contained in:
nicolargo
2024-12-28 18:08:52 +01:00
parent b4402bfc53
commit 1624e66f48
9 changed files with 70 additions and 15 deletions

View File

@@ -23,11 +23,11 @@ jobs:
with:
args: 'check'
- name: Static type check
run: |
echo "Skipping static type check for the moment, too much error...";
# pip install pyright
# pyright glances
# - name: Static type check
# run: |
# echo "Skipping static type check for the moment, too much error...";
# # pip install pyright
# # pyright glances
test-linux:
@@ -52,8 +52,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install pytest
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
- name: Unitary tests
run: |
@@ -115,11 +115,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install pytest
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
- name: Unitary tests
run: |
python ./unittest-core.py
python -m pytest ./tests/test_core.py
# Error when trying to implement #2749
# pkg: No packages available to install matching 'py-pip' have been found in the repositories
@@ -139,5 +140,6 @@ jobs:
# pkg install -y python3 py-pip
# run: |
# set -e -x
# python3 -m pip install pytest
# python3 -m pip install --user -r requirements.txt
# python ./unittest-core.py
# python3 -m pytest ./tests/test_core.py

2
.gitignore vendored
View File

@@ -65,3 +65,5 @@ bower_components/
# Virtual env
/venv*/
# Test
.coverage

View File

@@ -91,6 +91,9 @@ test: ## Run All unit tests
test-core: ## Run Core unit tests
$(PYTEST) tests/test_core.py
test-perf: ## Run Perf unit tests
$(PYTEST) tests/test_perf.py
test-restful: ## Run Restful API unit tests
$(PYTEST) tests/test_restful.py

View File

@@ -1,4 +1,5 @@
codespell
coverage
fonttools>=4.43.0 # not directly required, pinned by Snyk to avoid a vulnerability
gprof2dot
matplotlib

View File

@@ -25,10 +25,21 @@ from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService
from glances.main import GlancesMain
from glances.stats import GlancesStats
SERVER_PORT = 61234
URL = f"http://localhost:{SERVER_PORT}"
@pytest.fixture(scope="session")
def glances_stats():
core = GlancesMain(args_begin_at=2)
stats = GlancesStats(config=core.get_config(), args=core.get_args())
yield stats
stats.end()
@pytest.fixture(scope="session")
def glances_webserver():
if os.path.isfile('./venv/bin/python'):

24
tests/test_perf.py Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env python
#
# Glances - An eye on your system
#
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <nicolas@nicolargo.com>
#
# SPDX-License-Identifier: LGPL-3.0-only
#
"""Glances unitary tests suite for Glances perf."""
from glances.timer import Timer
def test_perf_update(glances_stats):
"""
Test Glances home page title.
"""
perf_timer = Timer(3)
counter = 0
while not perf_timer.finished():
glances_stats.update()
counter += 1
assert counter > 3

View File

@@ -23,6 +23,20 @@ def glances_homepage(firefox_browser):
return firefox_browser
def test_loading_time(glances_webserver, glances_homepage):
"""
Test Glances home page loading time.
"""
assert glances_webserver is not None
navigation_start = glances_homepage.execute_script("return window.performance.timing.navigationStart")
response_start = glances_homepage.execute_script("return window.performance.timing.responseStart")
dom_complete = glances_homepage.execute_script("return window.performance.timing.domComplete")
backend_perf = response_start - navigation_start
frontend_perf = dom_complete - response_start
assert backend_perf < 1000 # ms
assert frontend_perf < 1000 # ms
def test_title(glances_webserver, glances_homepage):
"""
Test Glances home page title.

View File

@@ -23,8 +23,6 @@ deps =
uvicorn
jinja2
requests
pytest
commands =
python unittest-core.py
; python unittest-restful.py
; python unittest-xmlrpc.py
;flake8 --exclude=build,.tox,.git
python -m pytest tests/test_core.py

View File

@@ -20,7 +20,7 @@ from glances import __version__
from glances.client import GlancesClient
SERVER_HOST = 'localhost'
SERVER_PORT = 61234
SERVER_PORT = 61235
pid = None