Skip to content

Commit da885fc

Browse files
authored
fix dicomio tag mismatch (#30760) (#35658)
* fix dicomio tag mismatch (#30760) * upd CHANGES.md (#30760) * apply tox (#30760) * fix linting: line too long (#30760) * update GCS and keep only 00081190 as volatile (#30760)
1 parent 9f3b7d9 commit da885fc

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
* Fixed X (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).
103103
* [YAML] Fixed handling of missing optional fields in JSON parsing ([#35179](https://github.com/apache/beam/issues/35179)).
104104
* [Python] Fix WriteToBigQuery transform using CopyJob does not work with WRITE_TRUNCATE write disposition ([#34247](https://github.com/apache/beam/issues/34247))
105+
* [Python] Fixed dicomio tags mismatch in integration tests ([#35658](https://github.com/apache/beam/pull/35658)).
106+
105107

106108
## Known Issues
107109

sdks/python/apache_beam/io/gcp/healthcare/dicomio_integration_test.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@
6464
RAND_LEN = 15
6565
SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
6666

67+
# Tag 00081190 contains temp store name which contains currentDate
68+
VOLATILE_TAGS = {"00081190"}
69+
70+
71+
def normalize_outer(elem: dict) -> dict:
72+
elem = dict(elem) # shallow copy
73+
elem["result"] = [normalize_instance(d) for d in elem.get("result", [])]
74+
return elem
75+
76+
77+
def normalize_instance(instance: dict) -> dict:
78+
return {k: v for k, v in instance.items() if k not in VOLATILE_TAGS}
79+
6780

6881
def random_string_generator(length):
6982
letters_and_digits = string.ascii_letters + string.digits
@@ -173,17 +186,22 @@ def test_dicom_search_instances(self):
173186
results_all = (
174187
p
175188
| 'create all dict' >> beam.Create([input_dict_all])
176-
| 'search all' >> DicomSearch())
189+
| 'search all' >> DicomSearch()
190+
| 'normalize all' >> beam.Map(normalize_outer))
177191
results_refine = (
178192
p
179193
| 'create refine dict' >> beam.Create([input_dict_refine])
180-
| 'search refine' >> DicomSearch())
194+
| 'search refine' >> DicomSearch()
195+
| 'normalize refine' >> beam.Map(normalize_outer))
196+
197+
expected_all_norm = normalize_outer(expected_dict_all)
198+
expected_refine_norm = normalize_outer(expected_dict_refine)
181199

182200
assert_that(
183-
results_all, equal_to([expected_dict_all]), label='all search assert')
201+
results_all, equal_to([expected_all_norm]), label='all search assert')
184202
assert_that(
185203
results_refine,
186-
equal_to([expected_dict_refine]),
204+
equal_to([expected_refine_norm]),
187205
label='refine search assert')
188206

189207
@pytest.mark.it_postcommit
@@ -218,8 +236,13 @@ def test_dicom_store_instance_from_gcs(self):
218236

219237
self.assertEqual(status_code, 200)
220238

221-
# List comparison based on different version of python
222-
self.assertCountEqual(result, self.expected_output_all_metadata)
239+
actual_norm = [normalize_instance(r) for r in result]
240+
expected_norm = [
241+
normalize_instance(r) for r in self.expected_output_all_metadata
242+
]
243+
244+
# Order-insensitive deep equality
245+
self.assertCountEqual(actual_norm, expected_norm)
223246

224247

225248
if __name__ == '__main__':

0 commit comments

Comments
 (0)