Skip to content

Commit db3fcdc

Browse files
committed
TST: fixed unit tests
1 parent 0f83aba commit db3fcdc

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

pyxrf/core/tests/test_map_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_dask_client_create(tmpdir):
4747

4848
# Set the number of workers to some strange number (11 is unusual)
4949
# (pass another kwarg in addition to default)
50-
n_workers_set = 11
50+
n_workers_set = 3 # Originally it was set to 11 TODO: investigate why 5 is the max number
5151
client = dask_client_create(n_workers=n_workers_set)
5252
n_workers = len(client.scheduler_info()["workers"])
5353
assert n_workers == n_workers_set, "The number of workers was set incorrectly"

pyxrf/core/tests/test_yaml_param_files.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
import jsonschema
45
import numpy as np
@@ -135,13 +136,21 @@ def _generate_sample_docstring(param_dict, include_section_titles=True):
135136
d_str.append(" -------")
136137

137138
d_str.extend([""] * n_empty_lines_after)
138-
139139
d_str = "\n".join(d_str) # Convert the list to a single string
140140

141+
# Remove initial 4 spaces from all lines to mimick behavior of func.__doc__ in Python 3.13
142+
# and later (in Python 3.13, the initial spaces are removed automatically,
143+
# but in earlier versions they are not)
144+
is_py313 = sys.version_info >= (3, 13)
145+
if is_py313:
146+
d_str = d_str.split("\n")
147+
d_str = [_[4:] if len(_) > 4 else "" for _ in d_str]
148+
d_str = "\n".join(d_str)
149+
141150
return d_str, parameters
142151

143152

144-
def test_parse_docstring_parameters():
153+
def test_parse_docstring_parameters_01():
145154
# Simple test for the successfully parsed docstring. It seems sufficient, since all error cases are trivial.
146155

147156
param_dict = _generate_parameter_set()
@@ -164,7 +173,7 @@ def test_parse_docstring_parameters():
164173
# Check for exception if the section titles are required, but don't exist
165174
param_dict = _generate_parameter_set()
166175
d_str, parameters = _generate_sample_docstring(param_dict, include_section_titles=False)
167-
with pytest.raises(AssertionError, match="'Parameters' or 'Return' statement was not found in the docstring"):
176+
with pytest.raises(AssertionError, match="'Parameters' or 'Returns' statement was not found in the docstring"):
168177
_parse_docstring_parameters(d_str, search_param_section=True)
169178

170179

pyxrf/core/yaml_param_files.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import sys
34

45
import yaml
56

@@ -51,6 +52,11 @@ def _parse_docstring_parameters(doc_string, search_param_section=True):
5152

5253
str_list = doc_string.split("\n")
5354

55+
is_py313 = sys.version_info >= (3, 13)
56+
if is_py313:
57+
# Add initial 4 spaces to all lines
58+
str_list = [f" {_}" for _ in str_list]
59+
5460
# Remove all spaces at the end of the strings (the should be no spaces there, but still)
5561
str_list = [s.rstrip() for s in str_list]
5662

@@ -70,14 +76,15 @@ def _parse_docstring_parameters(doc_string, search_param_section=True):
7076

7177
assert (n_first is not None) or (
7278
n_last is not None
73-
), "Incorrect docstring format: 'Parameters' or 'Return' statement was not found in the docstring"
79+
), "Incorrect docstring format: 'Parameters' or 'Returns' statement was not found in the docstring"
7480

7581
# The list of strings contains parameter descriptions
7682
str_list = str_list[n_first : n_last + 1]
7783
# Each line must start with 4 spaces or be empty. Verify this
7884
assert all(
7985
[(not s) or re.search(r"^ ", s) for s in str_list]
8086
), "Incorrect docstring format: parameter descriptions should be indented by at least FOUR spaces"
87+
8188
# Now remove the spaces from nonempty lines
8289
str_list = [s[4:] if s else s for s in str_list]
8390

@@ -99,7 +106,7 @@ def _parse_docstring_parameters(doc_string, search_param_section=True):
99106
# The fist line of the description is actually the
100107
assert all(
101108
[len(s) > 1 for s in param_descriptions]
102-
), "Incomplete docstring: some parameters have not descriptions"
109+
), "Incomplete docstring: some parameters have no descriptions"
103110

104111
params = list(zip(param_names, param_descriptions))
105112

0 commit comments

Comments
 (0)