/unit_tests/test_ls_tree.rst

https://bitbucket.org/jpellerin/nose/ · 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. >>> from nose.util import ls_tree
  5. >>> dir_path = tempfile.mkdtemp()
  6. >>> def create_file(filename):
  7. ... fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0666)
  8. ... os.close(fd)
  9. >>> os.mkdir(os.path.join(dir_path, "top"))
  10. >>> os.mkdir(os.path.join(dir_path, "top/dir"))
  11. >>> os.mkdir(os.path.join(dir_path, "top/dir2"))
  12. >>> os.mkdir(os.path.join(dir_path, "top/dir3"))
  13. >>> os.mkdir(os.path.join(dir_path, "top/dir/dir"))
  14. >>> os.mkdir(os.path.join(dir_path, "top/dir/dir2"))
  15. >>> os.mkdir(os.path.join(dir_path, "top/.svn"))
  16. >>> os.mkdir(os.path.join(dir_path, "top/.notsvn"))
  17. >>> os.mkdir(os.path.join(dir_path, "top/dir/.svn"))
  18. >>> os.mkdir(os.path.join(dir_path, "top/dir/.notsvn"))
  19. >>> create_file(os.path.join(dir_path, "top/file"))
  20. >>> create_file(os.path.join(dir_path, "top/backup_file~"))
  21. >>> create_file(os.path.join(dir_path, "top/file2"))
  22. >>> create_file(os.path.join(dir_path, "top/dir/file"))
  23. >>> create_file(os.path.join(dir_path, "top/dir/dir/file"))
  24. >>> create_file(os.path.join(dir_path, "top/dir/dir/file2"))
  25. >>> create_file(os.path.join(dir_path, "top/dir/backup_file~"))
  26. >>> create_file(os.path.join(dir_path, "top/dir2/file"))
  27. Note that files matching skip_pattern (by default SVN files,
  28. backup files and compiled Python files) are ignored
  29. >>> print ls_tree(os.path.join(dir_path, "top"))
  30. |-- file
  31. |-- file2
  32. |-- .notsvn
  33. |-- dir
  34. | |-- file
  35. | |-- .notsvn
  36. | |-- dir
  37. | | |-- file
  38. | | `-- file2
  39. | `-- dir2
  40. |-- dir2
  41. | `-- file
  42. `-- dir3
  43. >>> shutil.rmtree(dir_path)