class SerializerTest(unittest.TestCase): def setUp(self): self.serializer = Serializer() def assert_segments(self, expected: str, segments: list): expected = "UNA:+,? '" + expected + "'" message = self.serializer.serialize(segments, with_una=True) self.assertEqual(expected, message) def test_basic1(self): self.assert_segments("RFF+PD:50515", [Segment("RFF", ["PD", "50515"])]) def test_basic2(self): self.assert_segments("RFF+PD+50515", [Segment("RFF", "PD", "50515")]) def test_with_una_in_segments(self): self.assert_segments( "RFF+PD+45761", [Segment("UNA", ":+,?"), Segment("RFF", "PD", "45761")]) def test_escape_character(self): self.assert_segments( "ERC+10:The message does not make sense??", [Segment("ERC", ["10", "The message does not make sense?"])], ) def test_escape_component_separator(self): self.assert_segments("ERC+10:Name?: Craig", [Segment("ERC", ["10", "Name: Craig"])]) def test_escape_data_separator(self): self.assert_segments("DTM+735:?+0000:406", [Segment("DTM", ["735", "+0000", "406"])]) def test_escape_decimal_point(self): self.assert_segments("QTY+136:12,235", [Segment("QTY", ["136", "12,235"])]) def test_escape_segment_terminator(self): self.assert_segments("ERC+10:Craig?'s", [Segment("ERC", ["10", "Craig's"])]) def test_escape_sequence(self): self.assert_segments( "ERC+10:?:?+???' - ?:?+???' - ?:?+???'", [Segment("ERC", ["10", ":+?' - :+?' - :+?'"])], )
def serialize(self, break_lines: bool = False) -> str: """Serialize all the segments added to this object. :param break_lines: if True, insert line break after each segment terminator. """ header = self.get_header_segment() footer = self.get_footer_segment() out = [] if header: out.append(header) out += self.segments if footer: out.append(footer) return Serializer(self.characters).serialize( out, self.has_una_segment, break_lines, )
def serialize(self): u"""Serialize all the segments added to this object.""" return Serializer().serialize(self.segments, self.has_una_segment)
def serializer(): return Serializer()
def serialize(self) -> str: """Serialize all the segments added to this object.""" return Serializer(self.characters).serialize(self.segments, self.has_una_segment)
def setUp(self): self.serializer = Serializer()
def serialize(self, break_lines=False) -> str: """Serialize all the segments added to this object.""" return Serializer().serialize(self.segments, self.has_una_segment, break_lines)
def serialize(self, break_lines: bool = False) -> str: """Serialize all the segments added to this object. :param break_lines: if True, insert line break after each segment terminator. """ return Serializer().serialize(self.segments, self.has_una_segment, break_lines)