Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(153)

Side by Side Diff: Lib/test/test_stat.py

Issue 21719: Returning Windows file attribute information via os.stat()
Patch Set: Created 5 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_os.py ('k') | Modules/posixmodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 import os 2 import os
3 import sys
3 from test.support import TESTFN, import_fresh_module 4 from test.support import TESTFN, import_fresh_module
4 5
5 c_stat = import_fresh_module('stat', fresh=['_stat']) 6 c_stat = import_fresh_module('stat', fresh=['_stat'])
6 py_stat = import_fresh_module('stat', blocked=['_stat']) 7 py_stat = import_fresh_module('stat', blocked=['_stat'])
7 8
8 class TestFilemode: 9 class TestFilemode:
9 statmod = None 10 statmod = None
10 11
11 file_flags = {'SF_APPEND', 'SF_ARCHIVED', 'SF_IMMUTABLE', 'SF_NOUNLINK', 12 file_flags = {'SF_APPEND', 'SF_ARCHIVED', 'SF_IMMUTABLE', 'SF_NOUNLINK',
12 'SF_SNAPSHOT', 'UF_APPEND', 'UF_COMPRESSED', 'UF_HIDDEN', 13 'SF_SNAPSHOT', 'UF_APPEND', 'UF_COMPRESSED', 'UF_HIDDEN',
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 'S_IXUSR': 0o100, 45 'S_IXUSR': 0o100,
45 'S_IEXEC': 0o100, 46 'S_IEXEC': 0o100,
46 'S_IRWXG': 0o070, 47 'S_IRWXG': 0o070,
47 'S_IRGRP': 0o040, 48 'S_IRGRP': 0o040,
48 'S_IWGRP': 0o020, 49 'S_IWGRP': 0o020,
49 'S_IXGRP': 0o010, 50 'S_IXGRP': 0o010,
50 'S_IRWXO': 0o007, 51 'S_IRWXO': 0o007,
51 'S_IROTH': 0o004, 52 'S_IROTH': 0o004,
52 'S_IWOTH': 0o002, 53 'S_IWOTH': 0o002,
53 'S_IXOTH': 0o001} 54 'S_IXOTH': 0o001}
55
56 # defined by the Windows API documentation
57 file_attributes = {
58 'FILE_ATTRIBUTE_ARCHIVE': 32,
59 'FILE_ATTRIBUTE_COMPRESSED': 2048,
60 'FILE_ATTRIBUTE_DEVICE': 64,
61 'FILE_ATTRIBUTE_DIRECTORY': 16,
62 'FILE_ATTRIBUTE_ENCRYPTED': 16384,
63 'FILE_ATTRIBUTE_HIDDEN': 2,
64 'FILE_ATTRIBUTE_INTEGRITY_STREAM': 32768,
65 'FILE_ATTRIBUTE_NORMAL': 128,
66 'FILE_ATTRIBUTE_NOT_CONTENT_INDEXED': 8192,
67 'FILE_ATTRIBUTE_NO_SCRUB_DATA': 131072,
68 'FILE_ATTRIBUTE_OFFLINE': 4096,
69 'FILE_ATTRIBUTE_READONLY': 1,
70 'FILE_ATTRIBUTE_REPARSE_POINT': 1024,
71 'FILE_ATTRIBUTE_SPARSE_FILE': 512,
72 'FILE_ATTRIBUTE_SYSTEM': 4,
73 'FILE_ATTRIBUTE_TEMPORARY': 256,
74 'FILE_ATTRIBUTE_VIRTUAL': 65536}
54 75
55 def setUp(self): 76 def setUp(self):
56 try: 77 try:
57 os.remove(TESTFN) 78 os.remove(TESTFN)
58 except OSError: 79 except OSError:
59 try: 80 try:
60 os.rmdir(TESTFN) 81 os.rmdir(TESTFN)
61 except OSError: 82 except OSError:
62 pass 83 pass
63 tearDown = setUp 84 tearDown = setUp
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 for key in self.file_flags: 198 for key in self.file_flags:
178 modvalue = getattr(self.statmod, key) 199 modvalue = getattr(self.statmod, key)
179 self.assertIsInstance(modvalue, int) 200 self.assertIsInstance(modvalue, int)
180 for key in self.formats: 201 for key in self.formats:
181 modvalue = getattr(self.statmod, key) 202 modvalue = getattr(self.statmod, key)
182 self.assertIsInstance(modvalue, int) 203 self.assertIsInstance(modvalue, int)
183 for key in self.format_funcs: 204 for key in self.format_funcs:
184 func = getattr(self.statmod, key) 205 func = getattr(self.statmod, key)
185 self.assertTrue(callable(func)) 206 self.assertTrue(callable(func))
186 self.assertEqual(func(0), 0) 207 self.assertEqual(func(0), 0)
208
209 @unittest.skipUnless(sys.platform == "win32",
210 "FILE_ATTRIBUTE_* constants are Win32 specific")
211 def test_file_attribute_constants(self):
212 for key, value in sorted(self.file_attributes.items()):
213 self.assertTrue(hasattr(self.statmod, key), key)
214 modvalue = getattr(self.statmod, key)
215 self.assertEqual(value, modvalue, key)
187 216
188 217
189 class TestFilemodeCStat(TestFilemode, unittest.TestCase): 218 class TestFilemodeCStat(TestFilemode, unittest.TestCase):
190 statmod = c_stat 219 statmod = c_stat
191 220
192 formats = TestFilemode.formats | {'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'} 221 formats = TestFilemode.formats | {'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'}
193 format_funcs = TestFilemode.format_funcs | {'S_ISDOOR', 'S_ISPORT', 222 format_funcs = TestFilemode.format_funcs | {'S_ISDOOR', 'S_ISPORT',
194 'S_ISWHT'} 223 'S_ISWHT'}
195 224
196 225
197 class TestFilemodePyStat(TestFilemode, unittest.TestCase): 226 class TestFilemodePyStat(TestFilemode, unittest.TestCase):
198 statmod = py_stat 227 statmod = py_stat
199 228
200 229
201 if __name__ == '__main__': 230 if __name__ == '__main__':
202 unittest.main() 231 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_os.py ('k') | Modules/posixmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+