fix code hash test
@@ -10,8 +10,7 @@ from azure.ai.ml._utils._asset_utils import get_content_hash
@pytest.mark.unittest
class TestGetContentHash:
- def test_get_content_hash_should_not_change(self):
- root = Path.cwd().joinpath("code")
+ def test_get_content_hash_should_not_change(self, tmp_path: Path):
content1 = b"test\n"
content2 = b"file2 content\n"
content3 = b"file3 content\n"
@@ -22,13 +21,13 @@ class TestGetContentHash:
("Folder2/folder1/file4.txt", content4),
("Folder2/file3.txt", content3),
]
- for test_file in test_files:
- file_path = root.joinpath(test_file[0])
- os.makedirs(file_path.parent, exist_ok=True)
- with open(file_path, "wb") as f:
- f.write(test_file[1])
+ for test_file_name, test_file_contents in test_files:
+ full_file_path = tmp_path / test_file_name
+ full_file_path.parent.mkdir(parents=True, exist_ok=True)
+ with open(full_file_path, "wb") as f:
+ f.write(test_file_contents)
- hash = get_content_hash(root)
+ hash = get_content_hash(tmp_path)
actual_hash = hashlib.sha256()
actual_hash.update(b"4")
actual_hash.update(b"#file1.txt#" + str(len(content1)).encode())
@@ -40,4 +39,3 @@ class TestGetContentHash:
actual_hash.update(content3)
actual_hash.update(content4)
assert actual_hash.hexdigest() == hash == "3f99429630ebd5882337eedef79dc029a9b406338cd6f466206aef2c951453be"
- shutil.rmtree(root)
