Esempio n. 1
0
    def test_traverse_all_segment_codes_no_groups_no_loop(self):
        cuscar_schema = load_schema("schema_for_test.json")
        traverser = SchemaTraverser(cuscar_schema)

        all_segment_codes = [
            i['code'] for i in traverser.segment_generator(follow_loops=False)
        ]
        expected = ['UNA', 'UNB', 'BGM', 'DTM', 'UNT', 'UNZ']
        self.assertEqual(all_segment_codes, expected)
Esempio n. 2
0
    def test_will_fail_if_cannot_find_segment(self):
        cuscar_schema = load_schema("schema_for_test.json")
        traverser = SchemaTraverser(cuscar_schema)

        self.assertEqual(
            traverser.find_segment_forward('UNB')[0]['code'], 'UNB')
        with self.assertRaises(Exception) as context:
            traverser.find_segment_forward('XXX')

        self.assertTrue('Segment not found XXX' in str(context.exception))
Esempio n. 3
0
    def test_traverse_all_segment_codes_with_groups_and_loops(self):
        cuscar_schema = load_schema("schema_for_test2.json")
        traverser = SchemaTraverser(cuscar_schema)

        all_segment_codes = [
            i['code'] for i in traverser.segment_generator(follow_loops=True)
        ]

        expected = [
            'UNA', 'UNB', 'AUT', 'DTM', 'DTM', 'DTM', 'DTM', 'DTM', 'DTM',
            'DTM', 'DTM', 'DTM', 'RFF', 'RFF', 'RFF', 'RFF', 'RFF', 'RFF',
            'RFF', 'RFF', 'RFF', 'UNT', 'UNZ'
        ]
        self.assertEqual(all_segment_codes, expected)
Esempio n. 4
0
def handle_message(message, schema, codeset_manager, verbose,
                   show_only_unknown, handler):
    traverser = SchemaTraverser(schema)
    handler.start()
    for segment_index in range(0, len(message.segments)):
        segment = message.segments[segment_index]
        (segment_schema,
         schema_position) = traverser.find_segment_forward(segment.tag)
        if segment_schema != None:
            if not show_only_unknown:
                handle_segment(segment, segment_schema, schema_position,
                               codeset_manager, verbose, handler)
        else:
            handler.visit_unknown_segment(segment)
    handler.end()
Esempio n. 5
0
    def test_can_find_forward_by_segment_code_no_repeating(self):
        cuscar_schema = load_schema("schema_for_test.json")
        traverser = SchemaTraverser(cuscar_schema)

        self.assertEqual(
            traverser.find_segment_forward('UNB')[0]['code'], 'UNB')
        self.assertEqual(
            traverser.find_segment_forward('BGM')[0]['code'], 'BGM')
        self.assertEqual(
            traverser.find_segment_forward('DTM')[0]['code'], 'DTM')
        self.assertEqual(
            traverser.find_segment_forward('UNT')[0]['code'], 'UNT')