Beispiel #1
0
    def test_assign_value_with_component_separator(self):
        cmp_str = 'xxx^yyy'
        c = Component()
        c.value = cmp_str
        self.assertEqual(c.to_er7(), 'xxx\S\yyy')

        c = Component('CWE_1')
        c.value = cmp_str
        self.assertEqual(c.to_er7(), 'xxx\S\yyy')

        c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
        c.value = cmp_str
        self.assertEqual(c.to_er7(), 'xxx\S\yyy')
Beispiel #2
0
    def test_assign_value_traversal(self):
        subcmp_str = 'xxx'

        c1 = Component('CX_10')
        c2 = Component('CX_10')
        c1.cwe_1 = subcmp_str
        c2.cwe_1.value = subcmp_str
        self.assertEqual(c1.to_er7(), c2.to_er7())

        s1 = Segment('PID')
        s2 = Segment('PID')
        s1.pid_4.pid_4_10_1.value = subcmp_str
        s2.pid_4.pid_4_10_1 = subcmp_str
        self.assertEqual(s1.to_er7(), s2.to_er7())
Beispiel #3
0
    def test_assign_value_quiet(self):
        cmp_str = 'xxx'
        c = Component('CWE_1')
        c.value = cmp_str
        parsed_cmp = parse_component(cmp_str, 'CWE_1')
        self.assertEqual(c.to_er7(), parsed_cmp.to_er7())

        c = Component('CWE_1') # more child than allowed
        c.value = '1&2'
        for dt in ('ST', 'ID', 'FT', 'GTS', 'IS', 'TX'):
            c = Component(datatype=dt) # max length reached string type
            c.value = 65537*'a'
        for dt in ('NM', 'SI'):
            c = Component(datatype=dt)
            c.value = 65537*'1'

        complex_cmp_str = 'xxx&yyy&zzz'
        c = Component('CX_10', validation_level=VALIDATION_LEVEL.QUIET)
        c.value = complex_cmp_str
        parsed_cmp = parse_component(complex_cmp_str, 'CX_10', datatype='CWE', validation_level=VALIDATION_LEVEL.STRICT)
        self.assertEqual(c.to_er7(), parsed_cmp.to_er7())
Beispiel #4
0
    def test_assign_value_strict(self):
        cmp_str = 'xxx'
        c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
        c.value = cmp_str
        parsed_cmp = parse_component(cmp_str, 'CWE_1')
        self.assertEqual(c.to_er7(), parsed_cmp.to_er7())

        c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
        with self.assertRaises(MaxChildLimitReached):
            c.value = '1&2'

        with self.assertRaises(MaxLengthReached):
            for dt in ('ST', 'ID', 'FT', 'GTS', 'IS', 'TX'):
                c = Component(datatype=dt, validation_level=VALIDATION_LEVEL.STRICT) # max length reached string type
                c.value = 65537*'a'
            for dt in ('NM', 'SI'):
                c = Component(datatype=dt, validation_level=VALIDATION_LEVEL.STRICT)
                c.value = int(65537*'1')

        complex_cmp_str = 'xxx&yyy&zzz'
        c = Component('CX_10', validation_level=VALIDATION_LEVEL.STRICT)
        c.value = complex_cmp_str
        parsed_cmp = parse_component(complex_cmp_str, 'CX_10', datatype='CWE', validation_level=VALIDATION_LEVEL.STRICT)
        self.assertEqual(c.to_er7(), parsed_cmp.to_er7())