Only suppress sre_x modules if re._x modules exist #180
GitHub Actions / Unit Test Results
failed
Dec 24, 2023 in 0s
1 fail, 290 pass in 59m 17s
Annotations
Check warning on line 0 in tests.Stoner.test_doc_samples
github-actions / Unit Test Results
1 out of 5 runs failed: test_scripts[/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py] (tests.Stoner.test_doc_samples)
artifacts/Unit Test Results (Python 3.7)/pytest.xml
Raw output
script = '/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py'
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f6b48e91f90>
@pytest.mark.parametrize("script", get_scripts())
@pytest.mark.filterwarnings("ignore:.*:RuntimeWarning")
def test_scripts(script, monkeypatch):
"""Import each of the sample scripts in turn and see if they ran without error"""
print(f"Trying script {script}")
try:
os.chdir(datadir)
> runpy.run_path(script)
/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/tests/Stoner/test_doc_samples.py:36:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
path_name = '/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py'
init_globals = None, run_name = '<run_path>'
def run_path(path_name, init_globals=None, run_name=None):
"""Execute code located at the specified filesystem location
Returns the resulting top level namespace dictionary
The file path may refer directly to a Python script (i.e.
one that could be directly executed with execfile) or else
it may refer to a zipfile or directory containing a top
level __main__.py script.
"""
if run_name is None:
run_name = "<run_path>"
pkg_name = run_name.rpartition(".")[0]
importer = get_importer(path_name)
# Trying to avoid importing imp so as to not consume the deprecation warning.
is_NullImporter = False
if type(importer).__module__ == 'imp':
if type(importer).__name__ == 'NullImporter':
is_NullImporter = True
if isinstance(importer, type(None)) or is_NullImporter:
# Not a valid sys.path entry, so run the code directly
# execfile() doesn't help as we want to allow compiled files
code, fname = _get_code_from_file(run_name, path_name)
return _run_module_code(code, init_globals, run_name,
> pkg_name=pkg_name, script_name=fname)
/home/runner/micromamba-root/envs/test-environment/lib/python3.7/runpy.py:263:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
code = <code object <module> at 0x7f6b4a4d0540, file "/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py", line 1>
init_globals = None, mod_name = '<run_path>', mod_spec = None, pkg_name = ''
script_name = '/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py'
def _run_module_code(code, init_globals=None,
mod_name=None, mod_spec=None,
pkg_name=None, script_name=None):
"""Helper to run code in new namespace with sys modified"""
fname = script_name if mod_spec is None else mod_spec.origin
with _TempModule(mod_name) as temp_module, _ModifiedArgv0(fname):
mod_globals = temp_module.module.__dict__
_run_code(code, mod_globals, init_globals,
> mod_name, mod_spec, pkg_name, script_name)
/home/runner/micromamba-root/envs/test-environment/lib/python3.7/runpy.py:96:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
code = <code object <module> at 0x7f6b4a4d0540, file "/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py", line 1>
run_globals = {'Data': <class 'Stoner.core.data.Data'>, '__builtins__': {'ArithmeticError': <class 'ArithmeticError'>, 'AssertionErr...seException': <class 'BaseException'>, ...}, '__cached__': None, '__doc__': 'Plot data using multiple sub-plots.', ...}
init_globals = None, mod_name = '<run_path>', mod_spec = None, pkg_name = ''
script_name = '/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py'
def _run_code(code, run_globals, init_globals=None,
mod_name=None, mod_spec=None,
pkg_name=None, script_name=None):
"""Helper to run code in nominated namespace"""
if init_globals is not None:
run_globals.update(init_globals)
if mod_spec is None:
loader = None
fname = script_name
cached = None
else:
loader = mod_spec.loader
fname = mod_spec.origin
cached = mod_spec.cached
if pkg_name is None:
pkg_name = mod_spec.parent
run_globals.update(__name__ = mod_name,
__file__ = fname,
__cached__ = cached,
__doc__ = None,
__loader__ = loader,
__package__ = pkg_name,
__spec__ = mod_spec)
> exec(code, run_globals)
/home/runner/micromamba-root/envs/test-environment/lib/python3.7/runpy.py:85:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""Plot data using multiple sub-plots."""
# pylint: disable=invalid-name
from Stoner import Data
p = Data("sample.txt", setas="xyy")
# Quick plot
p.plot(multiple="panels")
# Helps to fix layout !
> p.set_layout_engine("tight")
/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py:9:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = ============================================= ============= ============ ===========
TDI Format 1.5 ... 5.28799 1785.456
============================================= ============= ============ ===========
name = 'set_layout_engine'
def __getattr__(self, name):
"""Wrap attribute access with extra renaming logic.
Args:
name (string):
Name of attribute the following attributes are supported:
- fig - the current plt figure reference
- axes - the plt axes object for the current plot
- xlim - the X axis limits
- ylim - the Y axis limits
All other attributes are passed over to the parent class
"""
func = None
o_name = name
mapping = dict(
[
("plt_", (plt, "pyplot")), # Need to be explicit in 2.7!
("ax_", (plt.Axes, "axes")),
("fig_", (plt.Figure, "figure")),
]
)
try:
return object.__getattribute__(self, o_name)
except AttributeError:
pass
if plt.get_fignums(): # Store the current figure and axes
tfig = plt.gcf()
tax = tfig.gca() # protect the current axes and figure
else:
tfig = None
tax = None
# First look for a function in the pyplot package
for prefix, (obj, key) in mapping.items():
name = o_name[len(prefix) :] if o_name.startswith(prefix) else o_name
if name in dir(obj):
try:
return self._pyplot_proxy(name, key)
except AttributeError:
pass
# Nowcheck for prefixed access on axes and figures with get_
if name.startswith("ax_") and f"get_{name[3:]}" in dir(plt.Axes):
name = name[3:]
if f"get_{name}" in dir(plt.Axes) and self.__figure:
ax = self.fig.gca()
func = ax.__getattribute__(f"get_{name}")
if name.startswith("fig_") and f"get_{name[4:]}" in dir(plt.Figure):
name = name[4:]
if f"get_{name}" in dir(plt.Figure) and self.__figure:
fig = self.fig
func = fig.__getattribute__(f"get_{name}")
if func is None: # Ok Fallback to lookinf again at parent class
> return super().__getattr__(o_name)
/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/Stoner/plot/core.py:575:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = ============================================= ============= ============ ===========
TDI Format 1.5 ... 5.28799 1785.456
============================================= ============= ============ ===========
name = 'set_layout_engine'
def __getattr__(self, name):
"""Handle some special pseudo attributes that map to the setas columns.
Args:
name (string):
The name of the attribute to be returned.
Returns:
Various:
the DataFile object in various forms
Supported attributes:
- records:
return the DataFile data as a numpy structured
array - i.e. rows of elements whose keys are column headings
- clone:
returns a deep copy of the current DataFile instance
Otherwise the name parameter is tried as an argument to :py:meth:`DataFile.column` and the resultant column
is returned. If DataFile.column raises a KeyError this is remapped as an AttributeError.
"""
setas_cols = ("x", "y", "z", "d", "e", "f", "u", "v", "w", "r", "q", "p")
if name != "debug" and self.debug:
print(name)
try:
return super().__getattr__(name)
except AttributeError:
ret = self.__dict__.get(name, type(self).__dict__.get(name, None))
if ret is not None:
return ret
if name in setas_cols:
ret = self._getattr_col(name)
if ret is not None:
return ret
if name in self.setas.cols:
ret = self.setas.cols[name]
if ret is not None and ret != []:
return ret
try:
col = self._data._setas.find_col(name)
return self.column(col)
except (KeyError, IndexError):
pass
if name in setas_cols: # Probably tried to use a setas col when it wasn't defined
raise StonerSetasError(
f"Tried accessing a {name} column, but setas is not defined and {name} is not a column name either"
)
> raise AttributeError(f"{name} is not an attribute of DataFile nor a column name")
E AttributeError: set_layout_engine is not an attribute of DataFile nor a column name
/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/Stoner/Core.py:513: AttributeError
During handling of the above exception, another exception occurred:
script = '/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py'
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f6b48e91f90>
@pytest.mark.parametrize("script", get_scripts())
@pytest.mark.filterwarnings("ignore:.*:RuntimeWarning")
def test_scripts(script, monkeypatch):
"""Import each of the sample scripts in turn and see if they ran without error"""
print(f"Trying script {script}")
try:
os.chdir(datadir)
runpy.run_path(script)
fignum = len(plt.get_fignums())
assert fignum >= 1, f"{script} Did not produce any figures !"
print("Done")
plt.close("all")
except Exception:
error = format_exc()
print(f"Failed with\n{error}")
> assert False, f"Script {script} failed with {error}"
E AssertionError: Script /home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py failed with Traceback (most recent call last):
E File "/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/tests/Stoner/test_doc_samples.py", line 36, in test_scripts
E runpy.run_path(script)
E File "/home/runner/micromamba-root/envs/test-environment/lib/python3.7/runpy.py", line 263, in run_path
E pkg_name=pkg_name, script_name=fname)
E File "/home/runner/micromamba-root/envs/test-environment/lib/python3.7/runpy.py", line 96, in _run_module_code
E mod_name, mod_spec, pkg_name, script_name)
E File "/home/runner/micromamba-root/envs/test-environment/lib/python3.7/runpy.py", line 85, in _run_code
E exec(code, run_globals)
E File "/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/doc/samples/multiple_panels_plot.py", line 9, in <module>
E p.set_layout_engine("tight")
E File "/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/Stoner/plot/core.py", line 575, in __getattr__
E return super().__getattr__(o_name)
E File "/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/Stoner/Core.py", line 513, in __getattr__
E raise AttributeError(f"{name} is not an attribute of DataFile nor a column name")
E AttributeError: set_layout_engine is not an attribute of DataFile nor a column name
E
E assert False
/home/runner/work/Stoner-PythonCode/Stoner-PythonCode/tests/Stoner/test_doc_samples.py:44: AssertionError