Exemple #1
0
    def test_buildingid_csv_DictPipe_LatLngDictDecoder_FieldNotUniqueError(self):
        decoder_in = LatLngDictDecoder('Latitude', 'Longitude')

        encoder_out = BaseGeometryDictEncoder('UBID', openlocationcode.PAIR_CODE_LENGTH_)

        encoder_err = ErrorDictEncoder('UBID')

        dict_pipe = DictPipe(decoder_in, encoder_out, encoder_err)

        io_in = io.StringIO('Latitude,Longitude,UBID')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        with self.assertRaisesRegex(FieldNotUniqueError, re.escape('field \'UBID\' has already been taken')):
            dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})

        io_in = io.StringIO('Latitude,Longitude,UBID_Error_Name')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        with self.assertRaisesRegex(FieldNotUniqueError, re.escape('field \'UBID_Error_Name\' has already been taken')):
            dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})

        io_in = io.StringIO('Latitude,Longitude,UBID_Error_Message')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        with self.assertRaisesRegex(FieldNotUniqueError, re.escape('field \'UBID_Error_Message\' has already been taken')):
            dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})
Exemple #2
0
    def test_buildingid_csv_DictPipe_WKTDictDecoder(self):
        decoder_in = WKTDictDecoder('WKT')

        encoder_out = BaseGeometryDictEncoder('UBID', openlocationcode.PAIR_CODE_LENGTH_)

        encoder_err = ErrorDictEncoder('UBID')

        dict_pipe = DictPipe(decoder_in, encoder_out, encoder_err)

        io_in = io.StringIO('WKT\r\nPOINT (0 0)\r\n')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})

        self.assertEqual('WKT\r\nPOINT (0 0)\r\n', io_in.getvalue())
        self.assertEqual('WKT,UBID\r\nPOINT (0 0),6FG22222+22-0-0-0-0\r\n', io_out.getvalue())
        self.assertEqual('', io_err.getvalue())

        io_in = io.StringIO('WKT\r\nx\r\n')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})

        self.assertEqual('WKT\r\nx\r\n', io_in.getvalue())
        self.assertEqual('', io_out.getvalue())
        self.assertEqual('WKT,UBID_Error_Name,UBID_Error_Message\r\nx,WKTReadingError,Could not create geometry because of errors while reading input.\r\n', io_err.getvalue())
Exemple #3
0
    def test_buildingid_csv_DictPipe_LatLngDictDecoder(self):
        decoder_in = LatLngDictDecoder('Latitude', 'Longitude')

        encoder_out = BaseGeometryDictEncoder('UBID', openlocationcode.PAIR_CODE_LENGTH_)

        encoder_err = ErrorDictEncoder('UBID')

        dict_pipe = DictPipe(decoder_in, encoder_out, encoder_err)

        io_in = io.StringIO('Latitude,Longitude\r\n0,0\r\n')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})

        self.assertEqual('Latitude,Longitude\r\n0,0\r\n', io_in.getvalue())
        self.assertEqual('Latitude,Longitude,UBID\r\n0,0,6FG22222+22-0-0-0-0\r\n', io_out.getvalue())
        self.assertEqual('', io_err.getvalue())

        io_in = io.StringIO('Latitude,Longitude\r\nx,x\r\n')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})

        self.assertEqual('Latitude,Longitude\r\nx,x\r\n', io_in.getvalue())
        self.assertEqual('', io_out.getvalue())
        self.assertEqual('Latitude,Longitude,UBID_Error_Name,UBID_Error_Message\r\nx,x,ValueError,could not convert string to float: \'x\'\r\n', io_err.getvalue())
Exemple #4
0
    def test_buildingid_csv_DictPipe_WKTDictDecoder_FieldNotFoundError(self):
        decoder_in = WKTDictDecoder('WKT')

        encoder_out = BaseGeometryDictEncoder('UBID', openlocationcode.PAIR_CODE_LENGTH_)

        encoder_err = ErrorDictEncoder('UBID')

        dict_pipe = DictPipe(decoder_in, encoder_out, encoder_err)

        io_in = io.StringIO('x')
        io_out = io.StringIO('')
        io_err = io.StringIO('')

        with self.assertRaisesRegex(FieldNotFoundError, re.escape('field \'WKT\' is not defined')):
            dict_pipe.run(io_in, io_out, io_err, args_in=[], kwargs_in={}, args_out=[], kwargs_out={})