Skip to content

Commit 6b929de

Browse files
author
m.calka
committed
[plotpy] mise à jour des test
- Migration des tests contentenu dans les sources sous if __name__ == "__main__" vers des fichiers tests (il doit en rester) - Création d'un test pour la console dockable, la console n'affiche pas le retour d'une commande ( à corriger) - Correction des méthodes utilisé dans la tranformation d'une image, l'utilisation de l'objet Matrix de numpy a été en partie remplacé l'objet Matrix sera déprécié dans les futurs versions de numpy (à remplcaer en cas de monté en version de numpy) - test_benchmark.py Fail si exécuté dans le framework de test (problème identifié sur une propriété privé self.__data de qwtPlot - Automatisation des tests en fonction de l'environnement de lancement, si lancé via pytest - Migration de la gestion des dlls et disthelpers.py vers guidata Etat acctuel des tests 3 failed, 391 passed, 7 skipped - Les 7 tests skipped, ne sont pas exécutés car il présente des effets de bords si exétuté dans le framework de test
1 parent 0501dde commit 6b929de

File tree

86 files changed

+3930
-3482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3930
-3482
lines changed

.coveragerc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
parallel = True
33
omit =
44
*/plotpy/tests/*
5-
*.vscode/extensions*
5+
*.vscode/extensions*
6+
*/sift/*
7+
*/guidata/*

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ sift/qt.conf
4545
doc/source/deployment_example/qt.conf
4646

4747
# Virtual env
48-
.venv/
48+
.venv/
49+
htmlcov

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"python.testing.pytestArgs": [
3838
"-v",
3939
"--cov",
40-
"--cov-report=xml",
40+
"--cov-report=html",
41+
"--mode=unattended",
4142
"plotpy",
4243
],
4344
}

.vscode/tasks.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,34 @@
5555
"clear": false
5656
}
5757
},
58+
{
59+
"label": "Run gui tests runner",
60+
"type": "shell",
61+
"command": "cmd",
62+
"args": [
63+
"/c",
64+
"gui_tests_runner.bat"
65+
],
66+
"options": {
67+
"cwd": "scripts",
68+
"env": {
69+
"UNATTENDED": "1",
70+
"PYTHON": "${env:PLOTPY_PYTHON_DEV}",
71+
}
72+
},
73+
"group": {
74+
"kind": "build",
75+
"isDefault": true
76+
},
77+
"presentation": {
78+
"echo": true,
79+
"reveal": "always",
80+
"focus": false,
81+
"panel": "shared",
82+
"showReuseMessage": true,
83+
"clear": false
84+
}
85+
},
5886
{
5987
"label": "Run Pylint",
6088
"type": "shell",
@@ -148,6 +176,30 @@
148176
"clear": true
149177
}
150178
},
179+
{
180+
"label": "Display Coverage",
181+
"type": "shell",
182+
"command": "cmd",
183+
"args": [
184+
"/c",
185+
"display_cov.bat",
186+
],
187+
"options": {
188+
"cwd": "scripts",
189+
},
190+
"group": {
191+
"kind": "build",
192+
"isDefault": false
193+
},
194+
"presentation": {
195+
"echo": true,
196+
"reveal": "never",
197+
"focus": false,
198+
"panel": "shared",
199+
"showReuseMessage": false,
200+
"clear": true
201+
}
202+
},
151203
/* {
152204
"label": "Run Coverage",
153205
"type": "shell",

conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# content of conftest.py
2+
import pytest
3+
4+
VALID_ARGS = ["unattended"]
5+
6+
7+
def mode_checker(value):
8+
msg = "mode must specify a test execution type : 'attended' or 'unattended"
9+
if value not in VALID_ARGS:
10+
raise pytest.UsageError(msg)
11+
12+
return value
13+
14+
15+
def pytest_addoption(parser):
16+
parser.addoption(
17+
"--mode",
18+
action="store",
19+
default="attended",
20+
help="Unattended mode for gui tests",
21+
type=mode_checker,
22+
)
23+
24+
25+
# XXX: Not used, left here as example
26+
# @pytest.fixture
27+
# def unattended(request):
28+
# unattended_arg = request.config.getoption("--mode")
29+
# return unattended_arg.lower() == "unattended"

dev/pip_list.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pygls 0.13.1
5151
Pygments 2.13.0
5252
pylint 2.16.1
5353
pyparsing 3.0.9
54-
PyQt5 5.15.8
54+
PyQt5 5.15.9
5555
PyQt5-Qt5 5.15.2
5656
PyQt5-sip 12.11.0
5757
pyspellchecker 0.7.1
@@ -76,6 +76,7 @@ sphinx-rtd-theme 0.5.1
7676
sphinxcontrib-applehelp 1.0.2
7777
sphinxcontrib-devhelp 1.0.2
7878
sphinxcontrib-htmlhelp 2.0.0
79+
sphinxcontrib-jquery 2.0.0
7980
sphinxcontrib-jsmath 1.0.1
8081
sphinxcontrib-qthelp 1.0.3
8182
sphinxcontrib-serializinghtml 1.1.5

dev/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Cython
2222
pytest
2323
pytest-qt
2424
pytest-cov
25+
pytest-html
2526
pytest-xvfb
2627
flaky
2728
pydicom

doc/source/deployment_example/create_exe.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
Deployment script using `plotpy.core.disthelpers` (py2exe or cx_Freeze)
88
"""
99

10-
from plotpy.utils.packaging_helpers import Distribution
10+
from guidata.disthelpers import Distribution
11+
12+
from plotpy.utils.packaging_helpers import add_plotpy
1113

1214

1315
def create_exe():
@@ -19,6 +21,8 @@ def create_exe():
1921
"simpledialog.pyw",
2022
excludes=["IPython", "tkinter", "scipy"],
2123
)
24+
if "plotpy" not in dist.module_import_func_dict.keys():
25+
dist.module_import_func_dict["plotpy"] = add_plotpy
2226
dist.add_modules("plotpy")
2327
dist.build_cx_freeze() # use `build_py2exe` to use py2exe instead
2428

plotpy/env.py

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause or the CeCILL-B License
4+
# (see plotpy/__init__.py for details)
5+
6+
"""
7+
Plotpy environmnent utilities
8+
"""
9+
10+
import argparse
11+
import enum
12+
import os
13+
import platform
14+
import pprint
15+
import sys
16+
17+
18+
class VerbosityLevels(enum.Enum):
19+
"""Print verbosity levels (for testing purpose)"""
20+
21+
QUIET = "quiet"
22+
MINIMAL = "minimal"
23+
NORMAL = "normal"
24+
25+
26+
class PlotpyExecEnv:
27+
"""Object representing CodraFT test environment"""
28+
29+
UNATTENDED_ARG = "unattended"
30+
VERBOSE_ARG = "verbose"
31+
SCREENSHOT_ARG = "screenshot"
32+
DELAY_ARG = "delay"
33+
UNATTENDED_ENV = "PLOTPY_UNATTENDED_TESTS"
34+
VERBOSE_ENV = "PLOTPY_VERBOSITY_LEVEL"
35+
SCREENSHOT_ENV = "PLOTPY_TAKE_SCREENSHOT"
36+
DELAY_ENV = "PLOTPY_DELAY_BEFORE_QUIT"
37+
38+
def __init__(self):
39+
self.h5files = None
40+
self.h5browser_file = None
41+
self.demo_mode = False
42+
self.parse_args()
43+
44+
def enable_demo_mode(self, delay: int):
45+
"""Enable demo mode"""
46+
self.demo_mode = True
47+
self.unattended = True
48+
self.delay = delay
49+
50+
@staticmethod
51+
def __get_mode(env):
52+
"""Get mode value"""
53+
return os.environ.get(env) is not None
54+
55+
@staticmethod
56+
def __set_mode(env, value):
57+
"""Set mode value"""
58+
if env in os.environ:
59+
os.environ.pop(env)
60+
if value:
61+
os.environ[env] = "1"
62+
63+
@property
64+
def unattended(self):
65+
"""Get unattended value"""
66+
return self.__get_mode(self.UNATTENDED_ENV)
67+
68+
@unattended.setter
69+
def unattended(self, value):
70+
"""Set unattended value"""
71+
self.__set_mode(self.UNATTENDED_ENV, value)
72+
73+
@property
74+
def screenshot(self):
75+
"""Get screenshot value"""
76+
return self.__get_mode(self.SCREENSHOT_ENV)
77+
78+
@screenshot.setter
79+
def screenshot(self, value):
80+
"""Set screenshot value"""
81+
self.__set_mode(self.SCREENSHOT_ENV, value)
82+
if value: # pragma: no cover
83+
self.unattended = value
84+
85+
@property
86+
def verbose(self):
87+
"""Get verbosity level"""
88+
return os.environ.get(self.VERBOSE_ENV, VerbosityLevels.NORMAL.value)
89+
90+
@verbose.setter
91+
def verbose(self, value):
92+
"""Set verbosity level"""
93+
os.environ[self.VERBOSE_ENV] = value
94+
95+
@property
96+
def delay(self):
97+
"""Delay (seconds) before quitting application in unattended mode"""
98+
try:
99+
return int(os.environ.get(self.DELAY_ENV))
100+
except (TypeError, ValueError):
101+
return 0
102+
103+
@delay.setter
104+
def delay(self, value: int):
105+
"""Set delay (seconds) before quitting application in unattended mode"""
106+
os.environ[self.DELAY_ENV] = str(value)
107+
108+
def parse_args(self):
109+
"""Parse command line arguments"""
110+
parser = argparse.ArgumentParser(description="Run CodraFT")
111+
# parser.add_argument(
112+
# "h5",
113+
# nargs="?",
114+
# type=str,
115+
# help="HDF5 file names (separated by ';'), "
116+
# "optionally with dataset name (separated by ',')",
117+
# )
118+
# parser.add_argument(
119+
# "-b",
120+
# "--h5browser",
121+
# required=False,
122+
# type=str,
123+
# metavar="path",
124+
# help="path to open with HDF5 browser",
125+
# )
126+
# parser.add_argument(
127+
# "-v", "--version", action="store_true", help="show CodraFT version"
128+
# )
129+
parser.add_argument(
130+
"--mode",
131+
choices=[self.UNATTENDED_ARG, self.SCREENSHOT_ARG],
132+
required=False,
133+
help="unattended: non-interactive test mode ; "
134+
"screenshot: unattended mode, with automatic screenshots",
135+
)
136+
parser.add_argument(
137+
"--" + self.DELAY_ARG,
138+
type=int,
139+
default=0,
140+
help="delay (seconds) before quitting application in unattended mode",
141+
)
142+
parser.add_argument(
143+
"--" + self.VERBOSE_ARG,
144+
choices=[lvl.value for lvl in VerbosityLevels],
145+
required=False,
146+
default=VerbosityLevels.NORMAL.value,
147+
help="verbosity level: for debugging/testing purpose",
148+
)
149+
args, _unknown = parser.parse_known_args()
150+
# if args.h5:
151+
# self.h5files = args.h5.split(";")
152+
# if args.h5browser:
153+
# self.h5browser_file = args.h5browser
154+
# if args.version:
155+
# version = os.environ["CODRAFT_VERSION"]
156+
# print(f"CodraFT {version} on {platform.system()}")
157+
# sys.exit()
158+
self.set_env_from_args(args)
159+
160+
def set_env_from_args(self, args):
161+
"""Set appropriate environment variables"""
162+
if args.mode is not None:
163+
self.unattended = args.mode == self.UNATTENDED_ARG
164+
self.screenshot = args.mode == self.SCREENSHOT_ARG
165+
if args.verbose is not None:
166+
self.verbose = args.verbose
167+
self.delay = args.delay
168+
169+
def print(self, *objects, sep=" ", end="\n", file=sys.stdout, flush=False):
170+
"""Print in file, depending on verbosity level"""
171+
# print(f"unattended={self.unattended} ; verbose={self.verbose} ; ")
172+
# print(f"screenshot={self.screenshot}; delay={self.delay}")
173+
if (self.verbose != VerbosityLevels.QUIET.value) and (
174+
self.verbose != VerbosityLevels.MINIMAL.value or file == sys.stderr
175+
):
176+
print(*objects, sep=sep, end=end, file=file, flush=flush)
177+
# TODO: [P4] Eventually add logging here
178+
179+
def pprint(
180+
self,
181+
obj,
182+
stream=None,
183+
indent=1,
184+
width=80,
185+
depth=None,
186+
compact=False,
187+
sort_dicts=True,
188+
):
189+
"""Pretty-print in stream, depending on verbosity level"""
190+
if (self.verbose != VerbosityLevels.QUIET.value) and (
191+
self.verbose != VerbosityLevels.MINIMAL.value or stream == sys.stderr
192+
):
193+
pprint.pprint(
194+
obj,
195+
stream=stream,
196+
indent=indent,
197+
width=width,
198+
depth=depth,
199+
compact=compact,
200+
sort_dicts=sort_dicts,
201+
)
202+
203+
204+
execenv = PlotpyExecEnv()

0 commit comments

Comments
 (0)