Example #1
0
 def results(self, input_file, input_table, input_array):
     r"""list: Results that should be found in the output files."""
     assert (os.path.isfile(input_file))
     assert (os.path.isfile(input_table))
     assert (os.path.isfile(input_array))
     with open(input_file, 'r') as fd:
         icont = fd.read()
     with open(input_table, 'rb') as fd:
         iATT = serialize.table_to_array(fd.read(), comment='#')
     with open(input_array, 'rb') as fd:
         iATA = serialize.table_to_array(fd.read(), comment='#')
     return [icont, (self.check_table, iATT), (self.check_table, iATA)]
Example #2
0
    def func_deserialize(self, msg):
        r"""Deserialize a message.

        Args:
            msg: Message to be deserialized.

        Returns:
            obj: Deserialized message.

        """
        if self.format_str is None:
            raise RuntimeError("Format string is not defined.")
        if self.as_array:
            out = serialize.table_to_array(
                msg,
                self.format_str,
                use_astropy=self.use_astropy,
                names=self.get_field_names(as_bytes=True))
            out = self.datatype.coerce_type(out)
        else:
            out = list(serialize.process_message(msg, self.format_str))
        field_units = self.get_field_units()
        if field_units is not None:
            out = [units.add_units(x, u) for x, u in zip(out, field_units)]
        return out
Example #3
0
def test_array_to_table():
    r"""Test conversion of arrays to ASCII table and back."""
    flist = ['# %5s\t%ld\t%lf\t%g%+gj\n']
    for use_astropy in [False, True]:
        for f in flist:
            dtype = serialize.cformat2nptype(f)
            arr0 = np.ones(5, dtype)
            arr0['f0'][0] = b'hello'
            tab = serialize.array_to_table(arr0, f, use_astropy=use_astropy)
            arr1 = serialize.table_to_array(tab, f, use_astropy=use_astropy)
            np.testing.assert_array_equal(arr1, arr0)
Example #4
0
 def check_table(self, fname, iAT):
     r"""Assert that contents of input/output ascii tables are identical."""
     with open(fname, 'rb') as fd:
         oAT = serialize.table_to_array(fd.read(), comment='#')
     np.testing.assert_equal(oAT, iAT)