diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5284eb9c..db050d03 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore index aa0be710..a5a48d85 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,5 @@ bower_components/ # Virtual env /venv*/ +# Test +.coverage diff --git a/Makefile b/Makefile index f01e820f..e1ea6a12 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/dev-requirements.txt b/dev-requirements.txt index fee1ee83..93f9917d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,4 +1,5 @@ codespell +coverage fonttools>=4.43.0 # not directly required, pinned by Snyk to avoid a vulnerability gprof2dot matplotlib diff --git a/tests/conftest.py b/tests/conftest.py index fd1e92c8..c3fdd630 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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'): diff --git a/tests/test_perf.py b/tests/test_perf.py new file mode 100755 index 00000000..6b0caa81 --- /dev/null +++ b/tests/test_perf.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# +# Glances - An eye on your system +# +# SPDX-FileCopyrightText: 2024 Nicolas Hennion +# +# 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 diff --git a/tests/test_webui.py b/tests/test_webui.py index aca14334..60c45a77 100755 --- a/tests/test_webui.py +++ b/tests/test_webui.py @@ -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. diff --git a/tox.ini b/tox.ini index 4663461d..699b8967 100644 --- a/tox.ini +++ b/tox.ini @@ -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 diff --git a/unittest-xmlrpc.py b/unittest-xmlrpc.py index 0e438df8..141f41b9 100755 --- a/unittest-xmlrpc.py +++ b/unittest-xmlrpc.py @@ -20,7 +20,7 @@ from glances import __version__ from glances.client import GlancesClient SERVER_HOST = 'localhost' -SERVER_PORT = 61234 +SERVER_PORT = 61235 pid = None