Esempio n. 1
0
    def test_package_resource(self):
        package_resource = file_utils.PackageResource(test_data,
                                                      "text_file.txt")

        expected = "Sphinx of black quartz — judge my vow. 紫の猿の皿洗い機."
        with file_utils.open_text_resource(package_resource) as f:
            test_contents = f.read()
            assert test_contents == expected
Esempio n. 2
0
  def _load_data_file(self, datafile: _FileType) -> pd.DataFrame:
    with file_utils.open_text_resource(datafile) as csv_file:
      sample = pd.read_csv(csv_file, header="infer", index_col=0)

    return sample.reindex(np.random.permutation(sample.index))
Esempio n. 3
0
 def _load_readme(
     self, readmefile: typing.Union[str, os.PathLike,
                                    file_utils.PackageResource]
 ) -> str:
   with file_utils.open_text_resource(readmefile) as text_file:
     return " ".join(text_file)
Esempio n. 4
0
 def test_path_resource(self, tmpdir):
     test_file = pathlib.Path(self._create_test_file(tmpdir))
     with file_utils.open_text_resource(test_file) as f:
         test_contents = f.read()
         assert test_contents == self._FILE_CONTENTS