Skip to content

Commit 46c7be8

Browse files
committed
Use refined param names for pytest parametrize
1 parent afe814b commit 46c7be8

File tree

1 file changed

+80
-74
lines changed

1 file changed

+80
-74
lines changed

tests/test_diffraction_objects.py

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -370,67 +370,70 @@ def test_dump(tmp_path, mocker):
370370
assert actual == expected
371371

372372

373+
test_init_valid_params = [
374+
( # instantiate just array attributes
375+
{
376+
"xarray": np.array([0.0, 90.0, 180.0]),
377+
"yarray": np.array([1.0, 2.0, 3.0]),
378+
"xtype": "tth",
379+
"wavelength": 4.0 * np.pi,
380+
},
381+
{
382+
"_all_arrays": np.array(
383+
[
384+
[1.0, 0.0, 0.0, np.float64(np.inf)],
385+
[2.0, 1.0 / np.sqrt(2), 90.0, np.sqrt(2) * 2 * np.pi],
386+
[3.0, 1.0, 180.0, 1.0 * 2 * np.pi],
387+
]
388+
),
389+
"metadata": {},
390+
"_input_xtype": "tth",
391+
"name": "",
392+
"scat_quantity": "",
393+
"qmin": np.float64(0.0),
394+
"qmax": np.float64(1.0),
395+
"tthmin": np.float64(0.0),
396+
"tthmax": np.float64(180.0),
397+
"dmin": np.float64(2 * np.pi),
398+
"dmax": np.float64(np.inf),
399+
"wavelength": 4.0 * np.pi,
400+
},
401+
),
402+
( # instantiate just array attributes
403+
{
404+
"xarray": np.array([np.inf, 2 * np.sqrt(2) * np.pi, 2 * np.pi]),
405+
"yarray": np.array([1.0, 2.0, 3.0]),
406+
"xtype": "d",
407+
"wavelength": 4.0 * np.pi,
408+
"scat_quantity": "x-ray",
409+
},
410+
{
411+
"_all_arrays": np.array(
412+
[
413+
[1.0, 0.0, 0.0, np.float64(np.inf)],
414+
[2.0, 1.0 / np.sqrt(2), 90.0, np.sqrt(2) * 2 * np.pi],
415+
[3.0, 1.0, 180.0, 1.0 * 2 * np.pi],
416+
]
417+
),
418+
"metadata": {},
419+
"_input_xtype": "d",
420+
"name": "",
421+
"scat_quantity": "x-ray",
422+
"qmin": np.float64(0.0),
423+
"qmax": np.float64(1.0),
424+
"tthmin": np.float64(0.0),
425+
"tthmax": np.float64(180.0),
426+
"dmin": np.float64(2 * np.pi),
427+
"dmax": np.float64(np.inf),
428+
"wavelength": 4.0 * np.pi,
429+
},
430+
),
431+
]
432+
433+
373434
@pytest.mark.parametrize(
374435
"init_args, expected_do_dict",
375-
[
376-
( # instantiate just array attributes
377-
{
378-
"xarray": np.array([0.0, 90.0, 180.0]),
379-
"yarray": np.array([1.0, 2.0, 3.0]),
380-
"xtype": "tth",
381-
"wavelength": 4.0 * np.pi,
382-
},
383-
{
384-
"_all_arrays": np.array(
385-
[
386-
[1.0, 0.0, 0.0, np.float64(np.inf)],
387-
[2.0, 1.0 / np.sqrt(2), 90.0, np.sqrt(2) * 2 * np.pi],
388-
[3.0, 1.0, 180.0, 1.0 * 2 * np.pi],
389-
]
390-
),
391-
"metadata": {},
392-
"_input_xtype": "tth",
393-
"name": "",
394-
"scat_quantity": "",
395-
"qmin": np.float64(0.0),
396-
"qmax": np.float64(1.0),
397-
"tthmin": np.float64(0.0),
398-
"tthmax": np.float64(180.0),
399-
"dmin": np.float64(2 * np.pi),
400-
"dmax": np.float64(np.inf),
401-
"wavelength": 4.0 * np.pi,
402-
},
403-
),
404-
( # instantiate just array attributes
405-
{
406-
"xarray": np.array([np.inf, 2 * np.sqrt(2) * np.pi, 2 * np.pi]),
407-
"yarray": np.array([1.0, 2.0, 3.0]),
408-
"xtype": "d",
409-
"wavelength": 4.0 * np.pi,
410-
"scat_quantity": "x-ray",
411-
},
412-
{
413-
"_all_arrays": np.array(
414-
[
415-
[1.0, 0.0, 0.0, np.float64(np.inf)],
416-
[2.0, 1.0 / np.sqrt(2), 90.0, np.sqrt(2) * 2 * np.pi],
417-
[3.0, 1.0, 180.0, 1.0 * 2 * np.pi],
418-
]
419-
),
420-
"metadata": {},
421-
"_input_xtype": "d",
422-
"name": "",
423-
"scat_quantity": "x-ray",
424-
"qmin": np.float64(0.0),
425-
"qmax": np.float64(1.0),
426-
"tthmin": np.float64(0.0),
427-
"tthmax": np.float64(180.0),
428-
"dmin": np.float64(2 * np.pi),
429-
"dmax": np.float64(np.inf),
430-
"wavelength": 4.0 * np.pi,
431-
},
432-
),
433-
],
436+
test_init_valid_params,
434437
)
435438
def test_init_valid(init_args, expected_do_dict):
436439
actual_do_dict = DiffractionObject(**init_args).__dict__
@@ -440,21 +443,24 @@ def test_init_valid(init_args, expected_do_dict):
440443
assert diff == {}
441444

442445

443-
@pytest.mark.parametrize(
444-
"init_args, error_message",
445-
[
446-
( # UC1: no arguments provided
447-
{},
448-
"missing 3 required positional arguments: 'xarray', 'yarray', and 'xtype'",
449-
),
450-
( # UC2: only xarray and yarray provided
451-
{"xarray": np.array([0.0, 90.0]), "yarray": np.array([0.0, 90.0])},
452-
"missing 1 required positional argument: 'xtype'",
453-
),
454-
],
455-
)
456-
def test_init_invalid_args(init_args, error_message):
457-
with pytest.raises(TypeError, match=error_message):
446+
test_init_invalid_params = [
447+
( # UC1: no arguments provided
448+
{},
449+
"missing 3 required positional arguments: 'xarray', 'yarray', and 'xtype'",
450+
),
451+
( # UC2: only xarray and yarray provided
452+
{"xarray": np.array([0.0, 90.0]), "yarray": np.array([0.0, 90.0])},
453+
"missing 1 required positional argument: 'xtype'",
454+
),
455+
]
456+
457+
458+
@pytest.mark.parametrize("init_args, expected_error_msg", test_init_invalid_params)
459+
def test_init_invalid_args(
460+
init_args,
461+
expected_error_msg,
462+
):
463+
with pytest.raises(TypeError, match=expected_error_msg):
458464
DiffractionObject(**init_args)
459465

460466

0 commit comments

Comments
 (0)