Exemplo n.º 1
0
    def test_write(self):
        for fp, obj in zip(self.valid_fps, self.ordination_results_objs):
            fh = StringIO()
            _ordination_results_to_ordres(obj, fh)
            obs = fh.getvalue()
            fh.close()

            with open(fp, 'U') as fh:
                exp = fh.read()

            npt.assert_equal(obs, exp)
Exemplo n.º 2
0
    def test_roundtrip_read_write(self):
        for fp in self.valid_fps:
            # Read.
            obj1 = _ordres_to_ordination_results(fp)

            # Write.
            fh = StringIO()
            _ordination_results_to_ordres(obj1, fh)
            fh.seek(0)

            # Read.
            obj2 = _ordres_to_ordination_results(fh)
            fh.close()

            assert_ordination_results_equal(obj1, obj2)
Exemplo n.º 3
0
 def test_to_file(self):
     """Should serialize a DissimilarityMatrix to file."""
     for dm_f_line, dm in zip(self.dm_f_lines, self.dms):
         for file_type in ('file like', 'file name'):
             if file_type == 'file like':
                 obs_f = StringIO()
                 dm.to_file(obs_f)
                 obs = obs_f.getvalue()
                 obs_f.close()
             elif file_type == 'file name':
                 with tempfile.NamedTemporaryFile('r+') as temp_file:
                     dm.to_file(temp_file.name)
                     temp_file.flush()
                     temp_file.seek(0)
                     obs = temp_file.read()
             self.assertEqual(obs, dm_f_line)
Exemplo n.º 4
0
 def test_to_file(self):
     """Should serialize a DissimilarityMatrix to file."""
     for dm_f_line, dm in zip(self.dm_f_lines, self.dms):
         for file_type in ('file like', 'file name'):
             if file_type == 'file like':
                 obs_f = StringIO()
                 dm.to_file(obs_f)
                 obs = obs_f.getvalue()
                 obs_f.close()
             elif file_type == 'file name':
                 with tempfile.NamedTemporaryFile('r+') as temp_file:
                     dm.to_file(temp_file.name)
                     temp_file.flush()
                     temp_file.seek(0)
                     obs = temp_file.read()
             self.assertEqual(obs, dm_f_line)
Exemplo n.º 5
0
    def test_to_file(self):
        for scores, test_path in zip(self.scores, self.test_paths):
            for file_type in ('file like', 'file name'):
                if file_type == 'file like':
                    obs_f = StringIO()
                    scores.to_file(obs_f)
                    obs = obs_f.getvalue()
                    obs_f.close()
                elif file_type == 'file name':
                    with tempfile.NamedTemporaryFile('r+') as temp_file:
                        scores.to_file(temp_file.name)
                        temp_file.flush()
                        temp_file.seek(0)
                        obs = temp_file.read()

                with open(get_data_path(test_path), 'U') as f:
                    exp = f.read()

                yield npt.assert_equal, obs, exp
Exemplo n.º 6
0
    def test_to_file(self):
        for scores, test_path in zip(self.scores, self.test_paths):
            for file_type in ('file like', 'file name'):
                if file_type == 'file like':
                    obs_f = StringIO()
                    scores.to_file(obs_f)
                    obs = obs_f.getvalue()
                    obs_f.close()
                elif file_type == 'file name':
                    with tempfile.NamedTemporaryFile('r+') as temp_file:
                        scores.to_file(temp_file.name)
                        temp_file.flush()
                        temp_file.seek(0)
                        obs = temp_file.read()

                with open(get_data_path(test_path), 'U') as f:
                    exp = f.read()

                yield npt.assert_equal, obs, exp
Exemplo n.º 7
0
    def test_roundtrip_read_write(self):
        for reader_fn, writer_fn, fhs in ((_dm_to_dissimilarity_matrix,
                                           _dissimilarity_matrix_to_dm,
                                           self.dissim_fhs),
                                          (_dm_to_distance_matrix,
                                           _distance_matrix_to_dm,
                                           self.dist_fhs)):
            for fh in fhs:
                # Read.
                dm1 = reader_fn(fh)

                # Write.
                out_fh = StringIO()
                writer_fn(dm1, out_fh)
                out_fh.seek(0)

                # Read.
                dm2 = reader_fn(out_fh)
                out_fh.close()

                self.assertEqual(dm1, dm2)
Exemplo n.º 8
0
    def test_write(self):
        for fn, objs, strs in ((_dissimilarity_matrix_to_dm, self.dissim_objs,
                                self.dissim_strs),
                               (_distance_matrix_to_dm, self.dist_objs,
                                self.dist_strs)):
            for obj, str_ in zip(objs, strs):
                fh = StringIO()
                fn(obj, fh)
                obs = fh.getvalue()
                fh.close()
                self.assertEqual(obs, str_)

        # Test writing CSV (TSV is written above).
        for fn, cls in ((_dissimilarity_matrix_to_dm, DissimilarityMatrix),
                        (_distance_matrix_to_dm, DistanceMatrix)):
            obj = cls(self.dm_3x3_data, ['a', 'b', 'c'])
            fh = StringIO()
            fn(obj, fh, delimiter=',')
            obs = fh.getvalue()
            fh.close()
            self.assertEqual(obs, DM_3x3_CSV)