def test_compare_equal_segments(self): """Just make sure that comparing Segment objects works""" a = [Segment(u"RFF", [u"PD", u"50515"])] b = [Segment(u"RFF", [u"PD", u"50515"])] assert a is not b, \ u"Two separatedly created Segment objects may not be a singleton." self.assertEqual(a, b)
def test_get_segment(self): message = Message.from_segments([ Segment(u"36CF", 1), Segment(u"36CF", 2), ]) segment = message.get_segment(u"36CF") self.assertEqual(Segment(u"36CF", 1), segment)
def test_get_segments(self): message = Message.from_segments( [Segment(u"36CF", 1), Segment(u"CPD"), Segment(u"36CF", 2)]) segments = list(message.get_segments(u"36CF")) self.assertEqual([ Segment(u"36CF", 1), Segment(u"36CF", 2), ], segments)
def test_get_segment_code(self): segment = Segment(u"OMD") self.assertEqual(u"OMD", segment.tag)
def test_create_with_segments(self): message = Message.from_segments([Segment(u"36CF")]) self.assertEqual([ Segment(u"36CF"), ], message.segments)
def test_escape_sequence(self): self.assert_segments(u"ERC+10:?:?+??' - ?:?+??' - ?:?+??'", [ Segment(u"ERC", [u"10", u"", u":+?' - :+?' - :+?'"]), ])
def test_escape_data_separator(self): self.assert_segments(u"DTM+735:?+0000:406", [ Segment(u"DTM", [u"735", u"", u"+0000", u"", u"406"]), ])
def test_get_list_element(self): segment = Segment(u"OMD", *self.elements) self.assertEqual([u"field2", u"extra"], segment.elements[1])
def test_escape_character(self): self.assert_segments(u"ERC+10:The message does not make sense?", [ Segment(u"ERC", [u"10", u"", u"The message does not make sense?"]), ])
def test_escape_component_separator(self): self.assert_segments(u"ERC+10:Name?: Craig", [ Segment(u"ERC", [u"10", u"", u"Name: Craig"]), ])
def test_basic2(self): self.assert_segments(u"RFF+PD+50515", [ Segment(u"RFF", u"PD", u"50515"), ])
def test_basic1(self): self.assert_segments(u"RFF+PD:50515", [ Segment(u"RFF", [u"PD", u"", u"50515"]), ])
def test_una_parser3(self): # UNA headers are a special parsing task and must be processed # correctly. tokens = self.parser.parse(u"UNA12345'TEST'") self.assertEqual(tokens.next(), Segment(u'UNA', u"12345'")) self.assertEqual(tokens.next(), Segment(u'TEST'))
def test_all_elements(self): segment = Segment(u"OMD", *self.elements) self.assertEqual(self.elements, segment.elements)
def test_escape_decimal_point(self): self.assert_segments(u"QTY+136:12,235", [ Segment(u"QTY", [u"136", u"", u"12,235"]), ])
def test_get_single_element(self): segment = Segment(u"OMD", *self.elements) self.assertEqual(u"field1", segment.elements[0])
def test_escape_segment_terminator(self): self.assert_segments(u"ERC+10:Craig?'s", [ Segment(u"ERC", [u"10", u"", u"Craig's"]), ])
def test_get_non_existing_element(self): segment = Segment(u"OMD", *self.elements) with self.assertRaises(IndexError): segment.elements[7]
def setUp(self): self.parser = Parser() self.default_una_segment = Segment(u'UNA', u":+,? '")