Skip to content

Commit 12cdb5d

Browse files
Wanbinyuhugovkvstinner
authored andcommitted
gh-126253: Ignore unknown Windows file attributes in test_os (GH-156305)
(cherry picked from commit 2087658) Co-authored-by: 万彬宇 <3431359639@qq.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 5a869d5 commit 12cdb5d

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎Lib/test/test_os.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@
8989
HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0
9090

9191

92+
def _get_file_attribute_mask():
93+
mask = 0
94+
for name in dir(stat):
95+
if name.startswith("FILE_ATTRIBUTE_"):
96+
mask |= getattr(stat, name)
97+
return mask
98+
99+
100+
# gh-126253: Ignore unknown attributes, such as 0x1_000_0000
101+
# (Directory flag of DOS file attribute in NTFS)
102+
FILE_ATTRIBUTE_MASK = _get_file_attribute_mask()
103+
104+
92105
def requires_os_func(name):
93106
return unittest.skipUnless(hasattr(os, name), 'requires os.%s' % name)
94107

@@ -5098,8 +5111,15 @@ def assert_stat_equal(self, stat1, stat2, skip_fields):
50985111
if attr in ("st_dev", "st_ino", "st_nlink", "st_ctime",
50995112
"st_ctime_ns"):
51005113
continue
5101-
self.assertEqual(getattr(stat1, attr),
5102-
getattr(stat2, attr),
5114+
value1 = getattr(stat1, attr)
5115+
value2 = getattr(stat2, attr)
5116+
if attr == "st_file_attributes":
5117+
# Filesystems may report attribute bits that aren't
5118+
# exposed by the stat module.
5119+
value1 &= FILE_ATTRIBUTE_MASK
5120+
value2 &= FILE_ATTRIBUTE_MASK
5121+
self.assertEqual(value1,
5122+
value2,
51035123
(stat1, stat2, attr))
51045124
else:
51055125
self.assertEqual(stat1, stat2)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``test_os.test_attributes()`` on Windows NTFS: ignore unknown file attributes.

0 commit comments

Comments
 (0)