def test_truncate_fails(research_object: ResearchObject) -> None: with research_object.write_bag_file("file.txt") as fh: fh.write("Hello there") fh.truncate() # OK as we're always at end # Will fail because the checksum can't rewind with pytest.raises(OSError): fh.truncate(0)
def test_writable_string(research_object: ResearchObject) -> None: with research_object.write_bag_file("file.txt") as fh: assert fh.writable() fh.write("Hello\n") sha1 = os.path.join(research_object.folder, "tagmanifest-sha1.txt") assert os.path.isfile(sha1) with open(sha1, encoding="UTF-8") as sha_file: stripped_sha = sha_file.readline().strip() assert stripped_sha.endswith("file.txt") # stain@biggie:~/src/cwltool$ echo Hello | sha1sum # 1d229271928d3f9e2bb0375bd6ce5db6c6d348d9 - assert stripped_sha.startswith("1d229271928d3f9e2bb0375bd6ce5db6c6d348d9") sha256 = os.path.join(research_object.folder, "tagmanifest-sha256.txt") assert os.path.isfile(sha256) with open(sha256, encoding="UTF-8") as sha_file: stripped_sha = sha_file.readline().strip() assert stripped_sha.endswith("file.txt") # stain@biggie:~/src/cwltool$ echo Hello | sha256sum # 66a045b452102c59d840ec097d59d9467e13a3f34f6494e539ffd32c1bb35f18 - assert stripped_sha.startswith( "66a045b452102c59d840ec097d59d9467e13a3f34f6494e539ffd32c1bb35f18") sha512 = os.path.join(research_object.folder, "tagmanifest-sha512.txt") assert os.path.isfile(sha512)
def test_data(research_object: ResearchObject) -> None: with research_object.write_bag_file("data/file.txt") as fh: assert fh.writable() fh.write("Hello\n") # Because this is under data/ it should add to manifest # rather than tagmanifest sha1 = os.path.join(research_object.folder, "manifest-sha1.txt") assert os.path.isfile(sha1) with open(sha1, encoding="UTF-8") as fh2: stripped_sha = fh2.readline().strip() assert stripped_sha.endswith("data/file.txt")
def __init__(self, workflow_uri_path: str, root_directory: str, stove_provenance_directory: str, executor: Optional[JobExecutor] = None, loading_context: Optional[LoadingContext] = None, runtime_context: Optional[RuntimeContext] = None) -> None: """Easy way to load a CWL document for execution.""" super().__init__(root_directory=root_directory, executor=executor, loading_context=loading_context, runtime_context=runtime_context) self.store_provenance_directory = stove_provenance_directory self.loading_context, self.workflow_object, self.uri = fetch_document( workflow_uri_path, self.loading_context) make_fs_access = self.runtime_context.make_fs_access \ if self.runtime_context.make_fs_access is not None else StdFsAccess ro = ResearchObject(make_fs_access(""), ) self.runtime_context.research_obj = ro log_file_io = ro.open_log_file_for_activity(ro.engine_uuid) prov_log_handler = logging.StreamHandler(cast(IO[str], log_file_io)) prov_log_handler.setFormatter(ProvLogFormatter()) _logger.addHandler(prov_log_handler) _logger.debug("[provenance] Logging to %s", log_file_io)
def test_not_readable(research_object: ResearchObject) -> None: with research_object.write_bag_file("file.txt") as fh: assert not fh.readable() with pytest.raises(OSError): fh.read()
def test_writable_bytes(research_object: ResearchObject) -> None: string = "Here is a snowman: \u2603 \n".encode() with research_object.write_bag_file("file.txt", encoding=None) as fh: fh.write(string) # type: ignore
def test_writable_unicode_string(research_object: ResearchObject) -> None: with research_object.write_bag_file("file.txt") as fh: assert fh.writable() fh.write("Here is a snowman: \u2603 \n")
def test_climboutfails(research_object: ResearchObject) -> None: with pytest.raises(ValueError): research_object.write_bag_file("../../outside-ro")
def test_absolute_path_fails(research_object: ResearchObject) -> None: with pytest.raises(ValueError): research_object.write_bag_file("/absolute/path/fails")
def research_object() -> Generator[ResearchObject, None, None]: re_ob = ResearchObject(StdFsAccess("")) yield re_ob re_ob.close()
def test_not_seekable(research_object: ResearchObject) -> None: with research_object.write_bag_file("file.txt") as fh: assert not fh.seekable() with pytest.raises(IOError): fh.seek(0)