MCPcopy
hub / github.com/pex-tool/pex / test_directory_hasher

Function test_directory_hasher

tests/test_util.py:70–107  ·  view source on GitHub ↗
(hasher, includes_hidden_expected)

Source from the content-addressed store, hash-verified

68 [(CacheHelper.dir_hash, True), (CacheHelper.pex_code_hash, False)],
69)
70def test_directory_hasher(hasher, includes_hidden_expected):
71 # type: (Callable[[str], str], bool) -> None
72 with temporary_dir() as tmp_dir:
73 safe_mkdir(os.path.join(tmp_dir, "a", "b"))
74 with safe_open(os.path.join(tmp_dir, "c", "d", "e.py"), "w") as fp:
75 fp.write("contents1")
76 with safe_open(os.path.join(tmp_dir, "f.py"), "w") as fp:
77 fp.write("contents2")
78 hash1 = hasher(tmp_dir)
79
80 safe_rename(os.path.join(tmp_dir, "c"), os.path.join(tmp_dir, "c-renamed"))
81 assert hash1 != hasher(tmp_dir)
82
83 safe_rename(os.path.join(tmp_dir, "c-renamed"), os.path.join(tmp_dir, "c"))
84 assert hash1 == hasher(tmp_dir)
85
86 touch(os.path.join(tmp_dir, "c", "d", "e.pyc"))
87 assert hash1 == hasher(tmp_dir)
88 touch(os.path.join(tmp_dir, "c", "d", "e.pyc.123456789"))
89 assert hash1 == hasher(tmp_dir)
90
91 pycache_dir = os.path.join(tmp_dir, "__pycache__")
92 safe_mkdir(pycache_dir)
93 touch(os.path.join(pycache_dir, "f.pyc"))
94 assert hash1 == hasher(tmp_dir)
95 touch(os.path.join(pycache_dir, "f.pyc.123456789"))
96 assert hash1 == hasher(tmp_dir)
97
98 touch(os.path.join(pycache_dir, "f.py"))
99 assert hash1 == hasher(
100 tmp_dir
101 ), "All content under __pycache__ directories should be ignored."
102
103 with safe_open(os.path.join(tmp_dir, ".hidden"), "w") as fp:
104 fp.write("contents3")
105
106 includes_hidden = hash1 != hasher(tmp_dir)
107 assert includes_hidden == includes_hidden_expected
108
109
110try:

Callers

nothing calls this directly

Calls 7

temporary_dirFunction · 0.90
safe_mkdirFunction · 0.90
safe_openFunction · 0.90
safe_renameFunction · 0.90
touchFunction · 0.90
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected