コード例 #1
0
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", ":+?' - :+?' - :+?'"])],
        )
コード例 #2
0
    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,
        )
コード例 #3
0
ファイル: message.py プロジェクト: versada/pydifact
 def serialize(self):
     u"""Serialize all the segments added to this object."""
     return Serializer().serialize(self.segments, self.has_una_segment)
コード例 #4
0
ファイル: test_serializer.py プロジェクト: nimarb/pydifact
def serializer():
    return Serializer()
コード例 #5
0
 def serialize(self) -> str:
     """Serialize all the segments added to this object."""
     return Serializer(self.characters).serialize(self.segments,
                                                  self.has_una_segment)
コード例 #6
0
 def setUp(self):
     self.serializer = Serializer()
コード例 #7
0
ファイル: message.py プロジェクト: qwyk/pydifact
 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)
コード例 #8
0
 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)