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_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_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 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 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)