1
0

test_append_to_name.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import pytest
  2. import osex
  3. import os
  4. def test_single_file(tmpdir):
  5. os.chdir(tmpdir.strpath)
  6. os.mknod("file")
  7. assert os.path.exists("file")
  8. osex.append_to_name("file", "-")
  9. assert not os.path.exists("file")
  10. assert os.path.exists("file-")
  11. def test_single_dir(tmpdir):
  12. os.chdir(tmpdir.strpath)
  13. os.mkdir("dir")
  14. assert os.path.exists("dir")
  15. osex.append_to_name("dir", "+")
  16. assert not os.path.exists("dir")
  17. assert os.path.exists("dir+")
  18. def test_multiple_files(tmpdir):
  19. os.chdir(tmpdir.strpath)
  20. # file 1
  21. os.mknod("file")
  22. assert os.path.exists("file")
  23. osex.append_to_name("file", "-")
  24. assert not os.path.exists("file")
  25. assert os.path.exists("file-")
  26. # file 2
  27. os.mknod("file")
  28. assert os.path.exists("file")
  29. osex.append_to_name("file", "-")
  30. assert not os.path.exists("file")
  31. assert os.path.exists("file-")
  32. assert os.path.exists("file-1")
  33. # file 3
  34. os.mknod("file")
  35. assert os.path.exists("file")
  36. osex.append_to_name("file", "-")
  37. assert not os.path.exists("file")
  38. assert os.path.exists("file-")
  39. assert os.path.exists("file-1")
  40. assert os.path.exists("file-2")
  41. def test_empty_suffix(tmpdir):
  42. os.chdir(tmpdir.strpath)
  43. # file 1
  44. os.mknod("file")
  45. assert os.path.exists("file")
  46. osex.append_to_name("file", "")
  47. assert not os.path.exists("file")
  48. assert os.path.exists("file1")
  49. # file 2
  50. os.mknod("file")
  51. assert os.path.exists("file")
  52. osex.append_to_name("file", "")
  53. assert not os.path.exists("file")
  54. assert os.path.exists("file1")
  55. assert os.path.exists("file2")
  56. # file 3
  57. os.mknod("file")
  58. assert os.path.exists("file")
  59. osex.append_to_name("file", "")
  60. assert not os.path.exists("file")
  61. assert os.path.exists("file1")
  62. assert os.path.exists("file2")
  63. assert os.path.exists("file3")