/unit_tests/test_ls_tree.rst
ReStructuredText | 50 lines | 43 code | 7 blank | 0 comment | 0 complexity | 512d3be7bf22d66c4ad9a9e71f9702b7 MD5 | raw file
1 >>> import os 2 >>> import tempfile 3 >>> import shutil 4 5 >>> from nose.util import ls_tree 6 7 >>> dir_path = tempfile.mkdtemp() 8 9 >>> def create_file(filename): 10 ... fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0666) 11 ... os.close(fd) 12 13 >>> os.mkdir(os.path.join(dir_path, "top")) 14 >>> os.mkdir(os.path.join(dir_path, "top/dir")) 15 >>> os.mkdir(os.path.join(dir_path, "top/dir2")) 16 >>> os.mkdir(os.path.join(dir_path, "top/dir3")) 17 >>> os.mkdir(os.path.join(dir_path, "top/dir/dir")) 18 >>> os.mkdir(os.path.join(dir_path, "top/dir/dir2")) 19 >>> os.mkdir(os.path.join(dir_path, "top/.svn")) 20 >>> os.mkdir(os.path.join(dir_path, "top/.notsvn")) 21 >>> os.mkdir(os.path.join(dir_path, "top/dir/.svn")) 22 >>> os.mkdir(os.path.join(dir_path, "top/dir/.notsvn")) 23 >>> create_file(os.path.join(dir_path, "top/file")) 24 >>> create_file(os.path.join(dir_path, "top/backup_file~")) 25 >>> create_file(os.path.join(dir_path, "top/file2")) 26 >>> create_file(os.path.join(dir_path, "top/dir/file")) 27 >>> create_file(os.path.join(dir_path, "top/dir/dir/file")) 28 >>> create_file(os.path.join(dir_path, "top/dir/dir/file2")) 29 >>> create_file(os.path.join(dir_path, "top/dir/backup_file~")) 30 >>> create_file(os.path.join(dir_path, "top/dir2/file")) 31 32 Note that files matching skip_pattern (by default SVN files, 33 backup files and compiled Python files) are ignored 34 35 >>> print ls_tree(os.path.join(dir_path, "top")) 36 |-- file 37 |-- file2 38 |-- .notsvn 39 |-- dir 40 | |-- file 41 | |-- .notsvn 42 | |-- dir 43 | | |-- file 44 | | `-- file2 45 | `-- dir2 46 |-- dir2 47 | `-- file 48 `-- dir3 49 50 >>> shutil.rmtree(dir_path)