Skip to content

Commit

Permalink
test: changes tests to be version agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
svituz committed Jan 9, 2024
1 parent 7bce619 commit 8d1fd26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
31 changes: 20 additions & 11 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import absolute_import

import os
import platform
import re
import sys
import tempfile
import unittest

import hl7apy
from hl7apy.core import Group, Field, Component, SubComponent
from hl7apy.exceptions import ValidationError
from hl7apy.parser import parse_message, parse_segments, parse_segment, parse_field
from hl7apy.validation import VALIDATION_LEVEL
from hl7apy.exceptions import ValidationError


class TestValidation(unittest.TestCase):
Expand Down Expand Up @@ -94,7 +96,9 @@ def _test_report_file(self, error_type):
regex = 'Error:.*'
elif error_type == 'WARNING':
regex = 'Warning:.*'
self.assertRegexpMatches(s, regex)

self.assertTrue(re.search(regex, s))

os.remove(self.report_file)

def test_well_structured_message(self):
Expand Down Expand Up @@ -177,7 +181,8 @@ def test_having_more_groups(self):
"""
msg = self._create_message(self.oml_o33)
oml_o33_patient = Group('OML_O33_PATIENT')
segments = parse_segments('PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009~^^^^^^L|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100\rPV1||O|||||||||||||||||1107080001^^^LIS')
segments = parse_segments(
'PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009~^^^^^^L|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100\rPV1||O|||||||||||||||||1107080001^^^LIS')
oml_o33_patient.children = segments
msg.add(oml_o33_patient)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
Expand Down Expand Up @@ -384,7 +389,6 @@ def test_wd_type_field(self):
self.assertRaises(ValidationError, parsed_s.validate)



class TestMessageProfile(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -414,10 +418,13 @@ def _test_report_file(self, error_type, present=True):
regex = 'Warning:.*'
else:
return
if present:
self.assertRegex(s, regex)
else:
self.assertNotRegex(s, regex)

if sys.version_info == '2':
if present:
self.assertTrue(re.search(regex, s))
else:
self.assertFalse(re.search(regex, s))

os.remove(self.report_file)

def test_well_structured_message(self):
Expand Down Expand Up @@ -561,7 +568,8 @@ def test_wrong_segment(self):
The message used has an unexpected SPM
"""
msg = self._create_message(self.rsp_k21)
spm = parse_segment('SPM|1|100187400201^||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r')
spm = parse_segment(
'SPM|1|100187400201^||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r')
msg.add(spm)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
self._test_report_file('ERROR')
Expand All @@ -573,7 +581,8 @@ def test_wrong_group(self):
"""
msg = self._create_message(self.rsp_k21)
oml_o33_patient = Group('OML_O33_PATIENT')
segments = parse_segments('PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009~^^^^^^L|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100\rPV1||O|||||||||||||||||1107080001^^^LIS')
segments = parse_segments(
'PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009~^^^^^^L|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100\rPV1||O|||||||||||||||||1107080001^^^LIS')
oml_o33_patient.children = segments
msg.add(oml_o33_patient)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
Expand Down

0 comments on commit 8d1fd26

Please sign in to comment.