Skip to content

Commit de55560

Browse files
authored
Merge pull request #277 from bobleesj/test-func-format-compact
Use compact test comment style for each case under @pytest.mark.parametrize
2 parents c73f860 + 0324138 commit de55560

File tree

3 files changed

+61
-67
lines changed

3 files changed

+61
-67
lines changed

news/test-func-format-compact.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* test comment format with compact style without extra line for each comment
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

tests/test_diffraction_objects.py

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"do_args_1, do_args_2, expected_equality, wavelength_warning_expected",
1616
[
1717
# Test when __eq__ returns True and False
18-
# C1: Identical args, expect equality
19-
(
18+
( # C1: Identical args, expect equality
2019
{
2120
"name": "same",
2221
"scat_quantity": "x-ray",
@@ -38,8 +37,7 @@
3837
True,
3938
False,
4039
),
41-
# Different names, expect inequality
42-
(
40+
( # C2: Different names, expect inequality
4341
{
4442
"name": "something",
4543
"xtype": "tth",
@@ -57,8 +55,7 @@
5755
False,
5856
True,
5957
),
60-
# C2: One without wavelength, expect inequality
61-
(
58+
( # C3: One without wavelength, expect inequality
6259
{
6360
"wavelength": 0.71,
6461
"xtype": "tth",
@@ -75,8 +72,7 @@
7572
False,
7673
True,
7774
),
78-
# C3: Different wavelength values, expect inequality
79-
(
75+
( # C4: Different wavelength values, expect inequality
8076
{
8177
"wavelength": 0.71,
8278
"xtype": "tth",
@@ -94,8 +90,7 @@
9490
False,
9591
False,
9692
),
97-
# C4: Different scat_quantity, expect inequality
98-
(
93+
( # C5: Different scat_quantity, expect inequality
9994
{
10095
"scat_quantity": "x-ray",
10196
"xtype": "tth",
@@ -113,8 +108,7 @@
113108
False,
114109
True,
115110
),
116-
# C5: Different q xarray values, expect inequality
117-
(
111+
( # C6: Different q xarray values, expect inequality
118112
{
119113
"xtype": "q",
120114
"xarray": np.array([1.0, 2.0]),
@@ -129,8 +123,7 @@
129123
False,
130124
True,
131125
),
132-
# C6: Different metadata, expect inequality
133-
(
126+
( # C7: Different metadata, expect inequality
134127
{
135128
"xtype": "q",
136129
"xarray": np.empty(0),
@@ -167,8 +160,8 @@ def test_diffraction_objects_equality(
167160
# Test whether on_xtype returns the correct xarray values.
168161
# C1: tth to tth, expect no change in xarray value
169162
# 1. "tth" provided, expect tth
170-
# 2. "2theta" provided, expect tth
171163
("tth", np.array([30, 60])),
164+
# 2. "2theta" provided, expect tth
172165
("2theta", np.array([30, 60])),
173166
# C2: "q" provided, expect q converted from tth
174167
("q", np.array([0.51764, 1])),
@@ -198,8 +191,7 @@ def test_init_invalid_xtype():
198191
"org_do_args, target_do_args, scale_inputs, expected",
199192
[
200193
# Test whether scale_to() scales to the expected values
201-
# C1: Same x-array and y-array with 2.1 offset, expect yarray shifted by 2.1 offset
202-
(
194+
( # C1: Same x-array and y-array with 2.1 offset, expect yarray shifted by 2.1 offset
203195
{
204196
"xarray": np.array([10, 15, 25, 30, 60, 140]),
205197
"yarray": np.array([2, 3, 4, 5, 6, 7]),
@@ -220,8 +212,7 @@ def test_init_invalid_xtype():
220212
},
221213
{"xtype": "tth", "yarray": np.array([4.1, 5.1, 6.1, 7.1, 8.1, 9.1])},
222214
),
223-
# C2: Same length x-arrays with exact x-value match
224-
(
215+
( # C2: Same length x-arrays with exact x-value match
225216
{
226217
"xarray": np.array([10, 15, 25, 30, 60, 140]),
227218
"yarray": np.array([10, 20, 25, 30, 60, 100]),
@@ -242,8 +233,7 @@ def test_init_invalid_xtype():
242233
},
243234
{"xtype": "tth", "yarray": np.array([1, 2, 2.5, 3, 6, 10])},
244235
),
245-
# C3: Same length x-arrays with approximate x-value match
246-
(
236+
( # C3: Same length x-arrays with approximate x-value match
247237
{
248238
"xarray": np.array([0.12, 0.24, 0.31, 0.4]),
249239
"yarray": np.array([10, 20, 40, 60]),
@@ -264,8 +254,7 @@ def test_init_invalid_xtype():
264254
},
265255
{"xtype": "q", "yarray": np.array([1, 2, 4, 6])},
266256
),
267-
# C4: Different x-array lengths with approximate x-value match
268-
(
257+
( # C4: Different x-array lengths with approximate x-value match
269258
{
270259
"xarray": np.array([10, 25, 30.1, 40.2, 61, 120, 140]),
271260
"yarray": np.array([10, 20, 30, 40, 50, 60, 100]),
@@ -303,8 +292,7 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected):
303292
"org_do_args, target_do_args, scale_inputs",
304293
[
305294
# Test expected errors produced from scale_to() with invalid inputs
306-
# C1: none of q, tth, d, provided, expect ValueError
307-
(
295+
( # C1: none of q, tth, d, provided, expect ValueError
308296
{
309297
"xarray": np.array([0.1, 0.2, 0.3]),
310298
"yarray": np.array([1, 2, 3]),
@@ -324,8 +312,7 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected):
324312
"offset": 0,
325313
},
326314
),
327-
# C2: tth and d both provided, expect ValueErrort
328-
(
315+
( # C2: tth and d both provided, expect ValueErrort
329316
{
330317
"xarray": np.array([10, 25, 30.1, 40.2, 61, 120, 140]),
331318
"yarray": np.array([10, 20, 30, 40, 50, 60, 100]),
@@ -366,8 +353,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs):
366353
"do_args, get_array_index_inputs, expected_index",
367354
[
368355
# Test get_array_index() returns the expected index given xtype and value
369-
# C1: Target value is in the xarray and xtype is identical, expect exact index match
370-
(
356+
( # C1: Target value is in the xarray and xtype is identical, expect exact index match
371357
{
372358
"wavelength": 4 * np.pi,
373359
"xarray": np.array([30.005, 60]),
@@ -380,8 +366,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs):
380366
},
381367
[0],
382368
),
383-
# C2: Target value lies in the array, expect the (first) closest index
384-
(
369+
( # C2: Target value lies in the array, expect the (first) closest index
385370
{
386371
"wavelength": 4 * np.pi,
387372
"xarray": np.array([30, 60]),
@@ -408,8 +393,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs):
408393
[0],
409394
),
410395
# C3: Target value out of the range, expect the closest index
411-
# 1. Test with xtype of "q"
412-
(
396+
( # 1. Test with xtype of "q"
413397
{
414398
"wavelength": 4 * np.pi,
415399
"xarray": np.array([0.25, 0.5, 0.71]),
@@ -422,8 +406,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs):
422406
},
423407
[0],
424408
),
425-
# 2. Test with xtype of "tth"
426-
(
409+
( # 2. Test with xtype of "tth"
427410
{
428411
"wavelength": 4 * np.pi,
429412
"xarray": np.array([30, 60]),
@@ -488,8 +471,7 @@ def test_dump(tmp_path, mocker):
488471
"do_init_args, expected_do_dict, divide_by_zero_warning_expected",
489472
[
490473
# Test __dict__ of DiffractionObject instance initialized with valid arguments
491-
(
492-
# C1: Minimum arguments provided for init, expect all attributes set without None
474+
( # C1: Minimum arguments provided for init, expect all attributes set without None
493475
{
494476
"xarray": np.array([0.0, 90.0, 180.0]),
495477
"yarray": np.array([1.0, 2.0, 3.0]),
@@ -518,8 +500,7 @@ def test_dump(tmp_path, mocker):
518500
},
519501
True,
520502
),
521-
# C2: Initialize with an optional scat_quantity argument, expect non-empty string for scat_quantity
522-
(
503+
( # C2: Initialize with an optional scat_quantity argument, expect non-empty string for scat_quantity
523504
{
524505
"xarray": np.array([np.inf, 2 * np.sqrt(2) * np.pi, 2 * np.pi]),
525506
"yarray": np.array([1.0, 2.0, 3.0]),

tests/test_transforms.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
# 2. No wavelength provided, expected empty array of tth and wavelength UserWarning
1717
(None, np.empty((0)), np.empty((0))),
1818
# C2: Use non-empty q values to compute tth with or without wavelength
19-
# 1. No wavelength provided, expect valid tth values in degrees with wavelength UserWarning
20-
(
19+
( # 1. No wavelength provided, expect valid tth values in degrees with wavelength UserWarning
2120
None,
2221
np.array([0, 0.2, 0.4, 0.6, 0.8, 1]),
2322
np.array([0, 1, 2, 3, 4, 5]),
2423
),
25-
# 2. Wavelength provided, expect tth values of 2*arcsin(q) in degrees
26-
(4 * np.pi, np.array([0, 1 / np.sqrt(2), 1.0]), np.array([0, 90.0, 180.0])),
24+
( # 2. Wavelength provided, expect tth values of 2*arcsin(q) in degrees
25+
4 * np.pi,
26+
np.array([0, 1 / np.sqrt(2), 1.0]),
27+
np.array([0, 90.0, 180.0]),
28+
),
2729
],
2830
)
2931
def test_q_to_tth(wavelength, q, expected_tth, wavelength_warning_msg):
@@ -39,14 +41,12 @@ def test_q_to_tth(wavelength, q, expected_tth, wavelength_warning_msg):
3941
"wavelength, q, expected_error_type",
4042
[
4143
# Test ValeuError in q to tth conversion with invalid two-theta values.
42-
# C1: Invalid q values that result in tth > 180 degrees, expect ValueError
43-
(
44+
( # C1: Invalid q values that result in tth > 180 degrees, expect ValueError
4445
4 * np.pi,
4546
np.array([0.2, 0.4, 0.6, 0.8, 1, 1.2]),
4647
ValueError,
4748
),
48-
# C2: Wrong wavelength that results in tth > 180 degrees, expect ValueError
49-
(
49+
( # C2: Wrong wavelength that results in tth > 180 degrees, expect ValueError
5050
100,
5151
np.array([0, 0.2, 0.4, 0.6, 0.8, 1]),
5252
ValueError,
@@ -69,14 +69,12 @@ def test_q_to_tth_bad(wavelength, q, expected_error_type, invalid_q_or_d_or_wave
6969
# 2. No wavelength provided, expected empty array of q and wavelength UserWarning
7070
(4 * np.pi, np.array([]), np.array([])),
7171
# C2: Use non-empty tth values between 0-180 degrees to compute q, with or without wavelength
72-
# 1. No wavelength provided, expect valid q values between 0-1
73-
(
72+
( # 1. No wavelength provided, expect valid q values between 0-1
7473
None,
7574
np.array([0, 30, 60, 90, 120, 180]),
7675
np.array([0, 1, 2, 3, 4, 5]),
7776
),
78-
# 2. Wavelength provided, expect expected q values are sin15, sin30, sin45, sin60, sin90
79-
(
77+
( # 2. Wavelength provided, expect expected q values are sin15, sin30, sin45, sin60, sin90
8078
4 * np.pi,
8179
np.array([0, 30.0, 60.0, 90.0, 120.0, 180.0]),
8280
np.array([0, 0.258819, 0.5, 0.707107, 0.866025, 1]),
@@ -97,15 +95,13 @@ def test_tth_to_q(wavelength, tth, expected_q, wavelength_warning_msg):
9795
"wavelength, tth, expected_error_type, expected_error_msg",
9896
[
9997
# C1: Invalid tth value of > 180 degrees provided, with or without wavelength
100-
# 1. No wavelength provided, expect two theta ValueError
101-
(
98+
( # 1. No wavelength provided, expect two theta ValueError
10299
None,
103100
np.array([0, 30, 60, 90, 120, 181]),
104101
ValueError,
105102
"Two theta exceeds 180 degrees. Please check the input values for errors.",
106103
),
107-
# 2. Wavelength provided, expect two theta ValueError
108-
(
104+
( # 2. Wavelength provided, expect two theta ValueError
109105
4 * np.pi,
110106
np.array([0, 30, 60, 90, 120, 181]),
111107
ValueError,
@@ -125,14 +121,12 @@ def test_tth_to_q_bad(wavelength, tth, expected_error_type, expected_error_msg):
125121
# C1: Empty q values, expect empty d values
126122
(np.array([]), np.array([]), False),
127123
# C2:
128-
# 1. Valid q values, expect d values without warning
129-
(
124+
( # 1. Valid q values, expect d values without warning
130125
np.array([0.1, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi]),
131126
np.array([62.83185307, 2, 1, 0.66667, 0.5, 0.4]),
132127
False,
133128
),
134-
# 2. Valid q values containing 0, expect d values with divide by zero warning
135-
(
129+
( # 2. Valid q values containing 0, expect d values with divide by zero warning
136130
np.array([0, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi]),
137131
np.array([np.inf, 2, 1, 0.66667, 0.5, 0.4]),
138132
True,
@@ -180,8 +174,7 @@ def test_d_to_q(d, expected_q, zero_divide_error_expected):
180174
(4 * np.pi, np.array([]), np.array([]), False),
181175
# C3: User specified valid tth values between 0-180 degrees (without wavelength)
182176
(None, np.array([0, 30, 60, 90, 120, 180]), np.array([0, 1, 2, 3, 4, 5]), False),
183-
# C4: User specified valid tth values between 0-180 degrees (with wavelength)
184-
(
177+
( # C4: User specified valid tth values between 0-180 degrees (with wavelength)
185178
4 * np.pi,
186179
np.array([0, 30.0, 60.0, 90.0, 120.0, 180.0]),
187180
np.array([np.inf, 24.27636, 12.56637, 8.88577, 7.25520, 6.28319]),
@@ -204,15 +197,13 @@ def test_tth_to_d(wavelength, tth, expected_d, divide_by_zero_warning_expected,
204197
@pytest.mark.parametrize(
205198
"wavelength, tth, expected_error_type, expected_error_msg",
206199
[
207-
# C1: Invalid tth value of > 180 degrees, no wavelength, expect two theta ValueError
208-
(
200+
( # C1: Invalid tth value of > 180 degrees, no wavelength, expect two theta ValueError
209201
None,
210202
np.array([0, 30, 60, 90, 120, 181]),
211203
ValueError,
212204
"Two theta exceeds 180 degrees. Please check the input values for errors.",
213205
),
214-
# C2: Invalid tth value of > 180 degrees with wavelength, expect two theta ValueError
215-
(
206+
( # C2: Invalid tth value of > 180 degrees with wavelength, expect two theta ValueError
216207
4 * np.pi,
217208
np.array([0, 30, 60, 90, 120, 181]),
218209
ValueError,
@@ -234,8 +225,7 @@ def test_tth_to_d_invalid(wavelength, tth, expected_error_type, expected_error_m
234225
(4 * np.pi, np.empty((0)), np.empty(0), False),
235226
# C3: Valid d values, no wavelength, expect valid and non-empty tth values
236227
(None, np.array([1, 0.8, 0.6, 0.4, 0.2, 0]), np.array([0, 1, 2, 3, 4, 5]), True),
237-
# C4: Valid d values with wavelength, expect valid and non-empty thh values
238-
(
228+
( # C4: Valid d values with wavelength, expect valid and non-empty thh values
239229
4 * np.pi,
240230
np.array([4 * np.pi, 4 / np.sqrt(2) * np.pi, 4 / np.sqrt(3) * np.pi]),
241231
np.array([60.0, 90.0, 120.0]),

0 commit comments

Comments
 (0)