mirror of https://github.com/nicolargo/glances.git
Improve unittest #2757
This commit is contained in:
parent
b4402bfc53
commit
1624e66f48
|
|
@ -23,11 +23,11 @@ jobs:
|
||||||
with:
|
with:
|
||||||
args: 'check'
|
args: 'check'
|
||||||
|
|
||||||
- name: Static type check
|
# - name: Static type check
|
||||||
run: |
|
# run: |
|
||||||
echo "Skipping static type check for the moment, too much error...";
|
# echo "Skipping static type check for the moment, too much error...";
|
||||||
# pip install pyright
|
# # pip install pyright
|
||||||
# pyright glances
|
# # pyright glances
|
||||||
|
|
||||||
|
|
||||||
test-linux:
|
test-linux:
|
||||||
|
|
@ -52,8 +52,8 @@ jobs:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install pytest
|
python -m pip install pytest
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
|
||||||
|
|
||||||
- name: Unitary tests
|
- name: Unitary tests
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -115,11 +115,12 @@ jobs:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
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
|
- name: Unitary tests
|
||||||
run: |
|
run: |
|
||||||
python ./unittest-core.py
|
python -m pytest ./tests/test_core.py
|
||||||
|
|
||||||
# Error when trying to implement #2749
|
# Error when trying to implement #2749
|
||||||
# pkg: No packages available to install matching 'py-pip' have been found in the repositories
|
# 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
|
# pkg install -y python3 py-pip
|
||||||
# run: |
|
# run: |
|
||||||
# set -e -x
|
# set -e -x
|
||||||
|
# python3 -m pip install pytest
|
||||||
# python3 -m pip install --user -r requirements.txt
|
# python3 -m pip install --user -r requirements.txt
|
||||||
# python ./unittest-core.py
|
# python3 -m pytest ./tests/test_core.py
|
||||||
|
|
|
||||||
|
|
@ -65,3 +65,5 @@ bower_components/
|
||||||
# Virtual env
|
# Virtual env
|
||||||
/venv*/
|
/venv*/
|
||||||
|
|
||||||
|
# Test
|
||||||
|
.coverage
|
||||||
|
|
|
||||||
3
Makefile
3
Makefile
|
|
@ -91,6 +91,9 @@ test: ## Run All unit tests
|
||||||
test-core: ## Run Core unit tests
|
test-core: ## Run Core unit tests
|
||||||
$(PYTEST) tests/test_core.py
|
$(PYTEST) tests/test_core.py
|
||||||
|
|
||||||
|
test-perf: ## Run Perf unit tests
|
||||||
|
$(PYTEST) tests/test_perf.py
|
||||||
|
|
||||||
test-restful: ## Run Restful API unit tests
|
test-restful: ## Run Restful API unit tests
|
||||||
$(PYTEST) tests/test_restful.py
|
$(PYTEST) tests/test_restful.py
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
codespell
|
codespell
|
||||||
|
coverage
|
||||||
fonttools>=4.43.0 # not directly required, pinned by Snyk to avoid a vulnerability
|
fonttools>=4.43.0 # not directly required, pinned by Snyk to avoid a vulnerability
|
||||||
gprof2dot
|
gprof2dot
|
||||||
matplotlib
|
matplotlib
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,21 @@ from selenium import webdriver
|
||||||
from selenium.webdriver import ChromeOptions
|
from selenium.webdriver import ChromeOptions
|
||||||
from selenium.webdriver.chrome.service import Service as ChromeService
|
from selenium.webdriver.chrome.service import Service as ChromeService
|
||||||
|
|
||||||
|
from glances.main import GlancesMain
|
||||||
|
from glances.stats import GlancesStats
|
||||||
|
|
||||||
SERVER_PORT = 61234
|
SERVER_PORT = 61234
|
||||||
URL = f"http://localhost:{SERVER_PORT}"
|
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")
|
@pytest.fixture(scope="session")
|
||||||
def glances_webserver():
|
def glances_webserver():
|
||||||
if os.path.isfile('./venv/bin/python'):
|
if os.path.isfile('./venv/bin/python'):
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -23,6 +23,20 @@ def glances_homepage(firefox_browser):
|
||||||
return 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):
|
def test_title(glances_webserver, glances_homepage):
|
||||||
"""
|
"""
|
||||||
Test Glances home page title.
|
Test Glances home page title.
|
||||||
|
|
|
||||||
6
tox.ini
6
tox.ini
|
|
@ -23,8 +23,6 @@ deps =
|
||||||
uvicorn
|
uvicorn
|
||||||
jinja2
|
jinja2
|
||||||
requests
|
requests
|
||||||
|
pytest
|
||||||
commands =
|
commands =
|
||||||
python unittest-core.py
|
python -m pytest tests/test_core.py
|
||||||
; python unittest-restful.py
|
|
||||||
; python unittest-xmlrpc.py
|
|
||||||
;flake8 --exclude=build,.tox,.git
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ from glances import __version__
|
||||||
from glances.client import GlancesClient
|
from glances.client import GlancesClient
|
||||||
|
|
||||||
SERVER_HOST = 'localhost'
|
SERVER_HOST = 'localhost'
|
||||||
SERVER_PORT = 61234
|
SERVER_PORT = 61235
|
||||||
pid = None
|
pid = None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue