|
1 | 1 | # stdlib |
2 | 2 | from uuid import UUID |
3 | 3 |
|
| 4 | +# 3rd party |
| 5 | +import pytest |
| 6 | + |
4 | 7 | # this package |
5 | 8 | from mh_utils.worklist_parser.classes import JobData |
6 | 9 | from tests.test_worklist_parser.test_parser import FakeSampleElement |
7 | 10 |
|
8 | 11 |
|
9 | | -def test_creation(): |
| 12 | +@pytest.mark.parametrize( |
| 13 | + "id, job_type, run_status", |
| 14 | + [ |
| 15 | + ("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", 7, 1), |
| 16 | + ("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", 7, 1), |
| 17 | + (UUID("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}"), "7", "1"), |
| 18 | + ] |
| 19 | + ) |
| 20 | +def test_creation(id, job_type, run_status): |
10 | 21 | data = JobData( |
11 | | - id="{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", |
12 | | - job_type=7, |
13 | | - run_status=1, |
| 22 | + id=id, |
| 23 | + job_type=job_type, |
| 24 | + run_status=run_status, |
14 | 25 | ) |
15 | 26 |
|
16 | 27 | assert data.id == UUID("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}") |
17 | 28 | assert data.job_type == 7 |
18 | 29 | assert data.run_status == 1 |
19 | 30 | assert data.sample_info == {} |
20 | 31 |
|
21 | | - data = JobData( |
22 | | - id="{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", |
23 | | - job_type=7, |
24 | | - run_status=1, |
25 | | - sample_info={"foo": "a string"}, |
26 | | - ) |
27 | | - |
28 | | - assert data.id == UUID("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}") |
29 | | - assert data.job_type == 7 |
30 | | - assert data.run_status == 1 |
31 | | - assert data.sample_info == {"foo": "a string"} |
32 | 32 |
|
| 33 | +@pytest.mark.parametrize( |
| 34 | + "id, job_type, run_status, sample_info", |
| 35 | + [ |
| 36 | + ("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", 7, 1, {"foo": "a string"}), |
| 37 | + (UUID("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}"), "7", "1", {"foo": "a string"}), |
| 38 | + ] |
| 39 | + ) |
| 40 | +def test_creation_sample_info(id, job_type, run_status, sample_info): |
33 | 41 | data = JobData( |
34 | | - id=UUID("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}"), |
35 | | - job_type="7", # type: ignore |
36 | | - run_status="1", # type: ignore |
37 | | - sample_info={"foo": "a string"}, |
| 42 | + id=id, |
| 43 | + job_type=job_type, |
| 44 | + run_status=run_status, |
| 45 | + sample_info=sample_info, |
38 | 46 | ) |
39 | 47 |
|
40 | 48 | assert data.id == UUID("{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}") |
@@ -65,40 +73,36 @@ def test_from_xml(): |
65 | 73 | assert data.run_status == 1 |
66 | 74 |
|
67 | 75 |
|
68 | | -def test_dict(): |
69 | | - data = JobData( |
| 76 | +@pytest.fixture() |
| 77 | +def sample_jobdata(): |
| 78 | + return JobData( |
70 | 79 | id="{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", |
71 | 80 | job_type=7, |
72 | 81 | run_status=1, |
73 | 82 | sample_info={"foo": "a string"}, |
74 | 83 | ) |
75 | 84 |
|
76 | | - assert dict(data) == { |
| 85 | + |
| 86 | +def test_dict(sample_jobdata): |
| 87 | + assert dict(sample_jobdata) == { |
77 | 88 | "id": "B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C".lower(), |
78 | 89 | "job_type": 7, |
79 | 90 | "run_status": 1, |
80 | 91 | "sample_info": {"foo": "a string"}, |
81 | 92 | } |
82 | 93 |
|
83 | 94 |
|
84 | | -def test_repr(): |
85 | | - data = JobData( |
86 | | - id="{B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C}", |
87 | | - job_type=7, |
88 | | - run_status=1, |
89 | | - sample_info={"foo": "a string"}, |
90 | | - ) |
91 | | - |
92 | | - assert str(data).startswith("JobData(") |
93 | | - assert str(data).endswith(")") |
94 | | - assert str(data) == ( |
| 95 | +def test_repr(sample_jobdata): |
| 96 | + assert str(sample_jobdata).startswith("JobData(") |
| 97 | + assert str(sample_jobdata).endswith(")") |
| 98 | + assert str(sample_jobdata) == ( |
95 | 99 | "JobData(" |
96 | 100 | f"id='{'B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C'.lower()}', " |
97 | 101 | "job_type=7, run_status=1)" |
98 | 102 | ) |
99 | | - assert repr(data).startswith("JobData(") |
100 | | - assert repr(data).endswith(")") |
101 | | - assert repr(data) == ( |
| 103 | + assert repr(sample_jobdata).startswith("JobData(") |
| 104 | + assert repr(sample_jobdata).endswith(")") |
| 105 | + assert repr(sample_jobdata) == ( |
102 | 106 | "JobData(" |
103 | 107 | f"id='{'B1F6E4D5-A300-40DF-8FB0-2A26FD8B8C0C'.lower()}', " |
104 | 108 | "job_type=7, run_status=1)" |
|
0 commit comments