diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2012-05-15 13:30:25 (GMT) |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2012-05-15 13:30:25 (GMT) |
commit | ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0 (patch) | |
tree | 2c5626573e004979e0c38b58ed9ce31a3c96dcb5 /Lib/test/test_stat.py | |
parent | 41829e82c1826dd71b64f8334959bcf7731f66fc (diff) | |
download | cpython-ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0.zip cpython-ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0.tar.gz cpython-ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0.tar.bz2 |
#14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Diffstat (limited to 'Lib/test/test_stat.py')
-rw-r--r-- | Lib/test/test_stat.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py new file mode 100644 index 0000000..f22d865 --- /dev/null +++ b/Lib/test/test_stat.py @@ -0,0 +1,55 @@ +import unittest +import os +import stat +from test.support import TESTFN, run_unittest + + +def get_mode(fname=TESTFN): + return stat.filemode(os.lstat(fname).st_mode) + + +class TestFilemode(unittest.TestCase): + + def setUp(self): + try: + os.remove(TESTFN) + except OSError: + try: + os.rmdir(TESTFN) + except OSError: + pass + tearDown = setUp + + def test_mode(self): + with open(TESTFN, 'w'): + pass + os.chmod(TESTFN, 0o700) + self.assertEqual(get_mode(), '-rwx------') + os.chmod(TESTFN, 0o070) + self.assertEqual(get_mode(), '----rwx---') + os.chmod(TESTFN, 0o007) + self.assertEqual(get_mode(), '-------rwx') + os.chmod(TESTFN, 0o444) + self.assertEqual(get_mode(), '-r--r--r--') + + def test_directory(self): + os.mkdir(TESTFN) + os.chmod(TESTFN, 0o700) + self.assertEqual(get_mode(), 'drwx------') + + @unittest.skipUnless(hasattr(os, 'symlink'), 'os.symlink not available') + def test_link(self): + os.symlink(os.getcwd(), TESTFN) + self.assertEqual(get_mode(), 'lrwxrwxrwx') + + @unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available') + def test_fifo(self): + os.mkfifo(TESTFN, 0o700) + self.assertEqual(get_mode(), 'prwx------') + + +def test_main(): + run_unittest(TestFilemode) + +if __name__ == '__main__': + test_main() |