Ejemplo n.º 1
0
    def test_read_1file_with_header(self):
        reader = CSVReader(self.file_with_header)
        self.assertEqual(reader.number_of_trajectories(), 1)
        self.assertEqual(reader.dimension(), self.nd)
        self.assertEqual(reader.n_frames_total(), self.nt)

        output = reader.get_output()

        np.testing.assert_almost_equal(output[0], self.data)
Ejemplo n.º 2
0
 def test_csvreader(self):
     data = np.random.random((101, 3))
     fn = tempfile.mktemp()
     try:
         np.savetxt(fn, data)
         # calc offsets
         offsets = [0]
         with open(fn, PyCSVReader.DEFAULT_OPEN_MODE) as new_fh:
             while new_fh.readline():
                 offsets.append(new_fh.tell())
         reader = PyCSVReader(fn)
         assert reader.dimension() == 3
         trajinfo = reader._get_traj_info(fn)
         np.testing.assert_equal(offsets, trajinfo.offsets)
     finally:
         os.unlink(fn)
Ejemplo n.º 3
0
    def test_compare_readline(self):
        data = np.arange(99*3).reshape(-1, 3)
        with tempfile.NamedTemporaryFile(delete=False) as f:
            fn = f.name
            np.savetxt(fn, data)
            # calc offsets
            reader = CSVReader(fn)
            assert reader.dimension() == 3
            trajinfo = reader._get_traj_info(fn)
            offset = [0]
            with open(fn, CSVReader.DEFAULT_OPEN_MODE) as fh2:
                while fh2.readline():
                    offset.append(fh2.tell())
                fh2.seek(0)
                np.testing.assert_equal(trajinfo.offsets, offset)
                for ii, off in enumerate(trajinfo.offsets):
                    fh2.seek(off)
                    line = fh2.readline()
                    fh2.seek(offset[ii])
                    line2 = fh2.readline()

                    self.assertEqual(line, line2, "differs at offset %i (%s != %s)" % (ii, off, offset[ii]))