예제 #1
0
    def test_serialize_multiline_string(self):

        a = String(1, 'a')
        b = String(2, 'b')
        c = String(3, 'c')
        d = String(4, 'd')
        definition = (a, b, c, d)

        line1 = Bunch()
        line1.a = 'a'
        line1.b = 'bb'
        line1.c = 'ccc'
        line1.d = 'dddd'

        line2 = Bunch()
        line2.a = 'A'
        line2.b = 'BB'
        line2.c = 'CCC'
        line2.d = 'DDDD'

        response = [line1, line2]

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, 'abbcccdddd\nABBCCCDDDD')
예제 #2
0
    def test_serialize_line_time_from_date_input_with_output_format(self):

        a = Time(12, 'a', '%I--%M//%S')
        b = Time(12, 'b', '%I--%M//%S')
        definition = (a, b)

        response = Bunch()
        response.a = datetime_time(15, 39, 1)
        response.b = datetime_time(23, 33, 44)

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '03--39//01  11--33//44  ')
예제 #3
0
    def test_serialize_line_time_from_string_input_with_output_format(self):

        a = Time(12, 'a', '%I--%M//%S')
        b = Time(12, 'b', '%I--%M//%S')
        definition = (a, b)

        response = Bunch()
        response.a = '15:39:01'
        response.b = '23:33:44'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '03--39//01  11--33//44  ')
예제 #4
0
    def test_serialize_line_date_from_date_input_with_output_format(self):

        a = Date(12, 'a', '%m-%d-%y')
        b = Date(12, 'b', '%m-%d-%y')
        definition = (a, b)

        response = Bunch()
        response.a = datetime_date(2017, 1, 25)
        response.b = datetime_date(2018, 2, 26)

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '01-25-17    02-26-18    ')
예제 #5
0
    def test_serialize_line_time_from_string_input(self):

        a = Time(16, 'a')
        b = Time(16, 'b')
        definition = (a, b)

        response = Bunch()
        response.a = '15:39'
        response.b = '23:33'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '15:39           23:33           ')
예제 #6
0
    def test_serialize_line_date_from_string_input_with_output_format(self):

        a = Date(12, 'a', '%m-%d-%y')
        b = Date(12, 'b', '%m-%d-%y')
        definition = (a, b)

        response = Bunch()
        response.a = '2017-01-25'
        response.b = '2018-02-26'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '01-25-17    02-26-18    ')
예제 #7
0
    def test_serialize_line_date_from_string_input(self):

        a = Date(16, 'a')
        b = Date(16, 'b')
        definition = (a, b)

        response = Bunch()
        response.a = '2017-01-25'
        response.b = '2018-02-26'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '2017-01-25      2018-02-26      ')
예제 #8
0
    def test_serialize_line_date_from_date_input(self):

        a = Date(16, 'a')
        b = Date(16, 'b')
        definition = (a, b)

        response = Bunch()
        response.a = datetime_date(2017, 1, 25)
        response.b = datetime_date(2018, 2, 26)

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '2017-01-25      2018-02-26      ')
예제 #9
0
    def test_serialize_line_timestamp_from_string_input_with_output_format(self):

        a = Timestamp(30, 'a', '%y/%m/%j-(%U)-%I--%M--%S')
        b = Timestamp(30, 'b', '%y/%m/%j-(%U)-%I--%M--%S')
        definition = (a, b)

        response = Bunch()
        response.a = '2017-01-25T21:30:53.020669'
        response.b = '2018-02-26T22:31:54.131770'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '17/01/025-(04)-09--30--53     18/02/057-(08)-10--31--54     ')
예제 #10
0
    def test_serialize_line_timestamp_from_datetime_input_with_output_format(self):

        a = Timestamp(30, 'a', '%y/%m/%j-(%U)-%I--%M--%S')
        b = Timestamp(30, 'b', '%y/%m/%j-(%U)-%I--%M--%S')
        definition = (a, b)

        response = Bunch()
        response.a = datetime_datetime(2017, 1, 25, 21, 30, 53, 20669)
        response.b = datetime_datetime(2018, 2, 26, 22, 31, 54, 131770)

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '17/01/025-(04)-09--30--53     18/02/057-(08)-10--31--54     ')
예제 #11
0
    def test_serialize_line_timestamp_from_string_input(self):

        a = Timestamp(26, 'a')
        b = Timestamp(36, 'b')
        definition = (a, b)

        response = Bunch()
        response.a = '2017-01-25T21:30:53.020669'
        response.b = '2018-02-26T22:31:54.131770'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '2017-01-25T21:30:53.0206692018-02-26T22:31:54.131770          ')
예제 #12
0
    def test_serialize_line_timestamp_from_datetime_input(self):

        a = Timestamp(26, 'a')
        b = Timestamp(36, 'b')
        definition = (a, b)

        response = Bunch()
        response.a = datetime_datetime(2017, 1, 25, 21, 30, 53, 20669)
        response.b = datetime_datetime(2018, 2, 26, 22, 31, 54, 131770)

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '2017-01-25T21:30:53.0206692018-02-26T22:31:54.131770          ')
예제 #13
0
    def test_serialize_line_time_from_date_input(self):

        a = Time(16, 'a')
        b = Time(16, 'b')
        definition = (a, b)

        response = Bunch()
        response.a = datetime_time(15, 39, 1)
        response.b = datetime_time(23, 33, 44)

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '15:39:01        23:33:44        ')
예제 #14
0
    def test_serialize_line_decimal_from_decimal_input_quantize_scale(self):

        a = FWDecimal(4, 2, 'a')
        b = FWDecimal(5, 2, 'b')
        c = FWDecimal(6, 2, 'c')
        d = FWDecimal(7, 2, 'd')
        definition = (a, b, c, d)

        response = Bunch()
        response.a = Decimal('1.1')
        response.b = Decimal('22.22')
        response.c = Decimal('333.3333')
        response.d = Decimal('4444.4444')

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '1.1022.22333.334444.44')
예제 #15
0
    def test_serialize_line_decimal_from_float_input(self):

        a = FWDecimal(4, 2, 'a')
        b = FWDecimal(5, 2, 'b')
        c = FWDecimal(6, 2, 'c')
        d = FWDecimal(7, 2, 'd')
        definition = (a, b, c, d)

        response = Bunch()
        response.a = 1.0
        response.b = 22.0
        response.c = 333.0
        response.d = 4444.0

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, '1.0022.00333.004444.00')
예제 #16
0
    def test_serialize_line_string_padding_right_fill_char(self):

        a = String(1, 'a')
        b = String(2, 'b')
        c = String(3, 'c', fill_char='#')
        d = String(4, 'd', fill_char='^')
        definition = (a, b, c, d)

        response = Bunch()
        response.a = 'a'
        response.b = 'b'
        response.c = 'cc'
        response.d = 'd'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, 'ab cc#d^^^')
예제 #17
0
    def test_serialize_line_string(self):

        a = String(1, 'a')
        b = String(2, 'b')
        c = String(3, 'c')
        d = String(4, 'd')
        definition = (a, b, c, d)

        response = Bunch()
        response.a = 'a'
        response.b = 'bb'
        response.c = 'ccc'
        response.d = 'dddd'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, 'abbcccdddd')
예제 #18
0
    def test_serialize_line_string_padding_left(self):

        class MyString(String):
            padding = PADDING.LEFT

        a = MyString(1, 'a')
        b = MyString(2, 'b')
        c = MyString(3, 'c')
        d = MyString(4, 'd')
        definition = (a, b, c, d)

        response = Bunch()
        response.a = 'a'
        response.b = 'b'
        response.c = 'cc'
        response.d = 'd'

        fw = FixedWidth(definition)
        result = fw.serialize(response)
        self.assertEquals(result, 'a b cc   d')