Beispiel #1
0
    def test_write_fill_value_decimal_places_follow_column(self):
        """Fill values should follow the column's data's lead for decimal places.

        E.g. if the column has data [10.001, 11.123], the normal fill value -999
        should be written -999.000. I.e. as many trailing zeros as the data has.

        If the column has no data in it, default to the old-style C format
        string for how many decimal places to show.

        """
        with closing(StringIO()) as buff:
            dfile = DataFile()
            dfile.create_columns([
                'STNNBR', 'CASTNO', 'BTLNBR', '_DATETIME', 'CTDPRS', 'CTDOXY'
            ])
            dfile['STNNBR'].values = [None, None]
            dfile['CASTNO'].values = [None, None]
            dfile['BTLNBR'].values = [None, None]
            dfile['_DATETIME'].values = [None, None]
            dfile['CTDPRS'].values = [_decimal('10.0001'), None]
            dfile['CTDOXY'].values = [None, _decimal('243.23')]
            btlex.write(dfile, buff)

            result = buff.getvalue().split('\n')
            # CTDPRS default decplaces is 1 but the data has 4
            self.assertEqual('-999.0000', result[4].split(',')[5].lstrip())
            # CTDOXY default decplaces is 4 but the data has 2
            self.assertEqual('-999.00', result[3].split(',')[6].lstrip())
Beispiel #2
0
    def test_no_stamp_uses_users(self):
        """If the writer is not given a stamp, it will use the config stamp."""
        self.buff = StringIO(TestBottleExchange.sample)
        btlex.read(self.file, self.buff)
        self.buff.close()

        self.file.globals['stamp'] = ''

        self.buff = StringIO()
        btlex.write(self.file, self.buff)

        expected_stamp = config.stamp()

        first_line = self.buff.getvalue().split('\n')[0]
        self.assertEqual(expected_stamp, first_line.split(',')[1])
        self.buff.close()
Beispiel #3
0
    def test_write(self):
        self.buff = StringIO(self.sample_basic)
        btlex.read(self.file, self.buff)
        self.buff.close()

        self.buff = StringIO()
        btlex.write(self.file, self.buff)
        output = self.buff.getvalue()
        self.buff.close()

        for aaa, bbb in zip(self.sample_basic.split('\n'), output.split('\n')):
            aas = [x.strip() for x in aaa.split(',')]
            bbs = [x.strip() for x in bbb.split(',')]
            # Check that DBARS units has been updated from blank to METERS
            if len(aas) > 11 and aas[2] == u'':
                aas[11] = u'METERS'
            self.assertEqual(aas, bbs)
Beispiel #4
0
    def test_write_btl_date_time_no_decimals(self):
        """BTL_DATE and BTL_TIME should not have decimal places."""
        with closing(StringIO()) as buff:
            dfile = DataFile()
            dfile.create_columns([
                'STNNBR', 'CASTNO', 'BTLNBR', '_DATETIME', 'CTDPRS',
                'BTL_DATE', 'BTL_TIME'
            ])
            dfile['STNNBR'].values = [None, None]
            dfile['CASTNO'].values = [None, None]
            dfile['BTLNBR'].values = [None, None]
            dfile['_DATETIME'].values = [None, None]
            dfile['CTDPRS'].values = [_decimal('10.0001'), None]
            dfile['BTL_DATE'].values = [
                _decimal('19700101'),
                _decimal('19700102')
            ]
            dfile['BTL_TIME'].values = [_decimal('0000'), _decimal('1234')]
            btlex.write(dfile, buff)

            result = buff.getvalue().split('\n')
            self.assertEqual('19700101', result[3].split(',')[6].lstrip())
            self.assertEqual('1234', result[4].split(',')[7].lstrip())
Beispiel #5
0
    def test_write_exchange_decimal_places(self):
        """Decimal places should be kept from the original data."""
        with closing(StringIO()) as buff:
            dfile = DataFile()
            dfile.create_columns([
                'STNNBR', 'CASTNO', 'BTLNBR', '_DATETIME', 'CTDPRS',
                'LONGITUDE'
            ])
            dfile['STNNBR'].values = [None, None]
            dfile['CASTNO'].values = [None, None]
            dfile['BTLNBR'].values = [None, None]
            dfile['_DATETIME'].values = [None, None]
            dfile['CTDPRS'].values = [_decimal('10.0001'), None]
            dfile['LONGITUDE'].values = [
                _decimal('0.0000000'),
                _decimal('1.000000')
            ]
            btlex.write(dfile, buff)

            result = buff.getvalue().split('\n')
            # Decimal('0.0000000') is converted to 0E-7 by str. The formatting
            # has to be done manually.
            self.assertEqual('0.0000000', result[3].split(',')[5].lstrip())