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

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

Issue 21719: Returning Windows file attribute information via os.stat()
Patch Set: Created 5 years, 7 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
OLDNEW
1 # As a test suite for the os module, this is woefully inadequate, but this 1 # As a test suite for the os module, this is woefully inadequate, but this
2 # does add tests for a few functions which have been determined to be more 2 # does add tests for a few functions which have been determined to be more
3 # portable than they had been thought to be. 3 # portable than they had been thought to be.
4 4
5 import os 5 import os
6 import errno 6 import errno
7 import unittest 7 import unittest
8 import warnings 8 import warnings
9 import sys 9 import sys
10 import signal 10 import signal
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 # Verify that stat'ing a closed fd does not cause crash 522 # Verify that stat'ing a closed fd does not cause crash
523 r, w = os.pipe() 523 r, w = os.pipe()
524 try: 524 try:
525 os.stat(r) # should not raise error 525 os.stat(r) # should not raise error
526 finally: 526 finally:
527 os.close(r) 527 os.close(r)
528 os.close(w) 528 os.close(w)
529 with self.assertRaises(OSError) as ctx: 529 with self.assertRaises(OSError) as ctx:
530 os.stat(r) 530 os.stat(r)
531 self.assertEqual(ctx.exception.errno, errno.EBADF) 531 self.assertEqual(ctx.exception.errno, errno.EBADF)
532
533 def check_file_attributes(self, result):
534 self.assertTrue(hasattr(result, 'st_file_attributes'))
535 self.assertTrue(isinstance(result.st_file_attributes, int))
536 self.assertTrue(0 <= result.st_file_attributes <= 0xFFFFFFFF)
stoneleaf 2014/06/13 15:49:58 On non-Windows machines 'st_file_attributes' will
loewis 2014/06/13 21:41:01 No, the attribute will be absent. So the function
537
538 @unittest.skipUnless(sys.platform == "win32",
539 "st_file_attributes is Win32 specific")
540 def test_file_attributes(self):
541 # test st_file_attributes on a file (FILE_ATTRIBUTE_DIRECTORY not set)
542 result = os.stat(self.fname)
543 self.check_file_attributes(result)
544 self.assertTrue(result.st_file_attributes & 0x10 == 0)
haypo 2014/06/13 16:00:20 You should not hardcode constants here, reuse stat
545
546 # test st_file_attributes on a directory (FILE_ATTRIBUTE_DIRECTORY)
547 result = os.stat(support.TESTFN)
548 self.check_file_attributes(result)
549 self.assertTrue(result.st_file_attributes & 0x10 == 0x10)
532 550
533 from test import mapping_tests 551 from test import mapping_tests
534 552
535 class EnvironTests(mapping_tests.BasicTestMappingProtocol): 553 class EnvironTests(mapping_tests.BasicTestMappingProtocol):
536 """check that os.environ object conform to mapping protocol""" 554 """check that os.environ object conform to mapping protocol"""
537 type2test = None 555 type2test = None
538 556
539 def setUp(self): 557 def setUp(self):
540 self.__save = dict(os.environ) 558 self.__save = dict(os.environ)
541 if os.supports_bytes_environ: 559 if os.supports_bytes_environ:
(...skipping 2035 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 TermsizeTests, 2595 TermsizeTests,
2578 OSErrorTests, 2596 OSErrorTests,
2579 RemoveDirsTests, 2597 RemoveDirsTests,
2580 CPUCountTests, 2598 CPUCountTests,
2581 FDInheritanceTests, 2599 FDInheritanceTests,
2582 Win32JunctionTests, 2600 Win32JunctionTests,
2583 ) 2601 )
2584 2602
2585 if __name__ == "__main__": 2603 if __name__ == "__main__":
2586 test_main() 2604 test_main()
OLDNEW

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