conftest.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import os
  2. import shutil
  3. import pytest
  4. def create_file(path: str, content: str):
  5. """Create txt file with specific content"""
  6. with open(f"{path}", "w") as file:
  7. file.write(content)
  8. @pytest.fixture
  9. def create_files():
  10. """Create files with equal or non-equal content"""
  11. create_file("tests/file1.txt", "hello, world")
  12. create_file("tests/file2.txt", "hello, world!")
  13. create_file("tests/file3.txt", "hello, world")
  14. yield
  15. os.remove("tests/file1.txt")
  16. os.remove("tests/file2.txt")
  17. os.remove("tests/file3.txt")
  18. @pytest.fixture
  19. def create_dirs_and_files():
  20. os.makedirs("tests/dir1/dir2")
  21. os.makedirs("tests/dir3/dir4")
  22. create_file("tests/dir1/file1.txt", "aaa")
  23. create_file("tests/dir3/file2.txt", "bbb")
  24. yield
  25. shutil.rmtree("tests/dir1")
  26. shutil.rmtree("tests/dir3")
  27. @pytest.fixture
  28. def create_nested_dirs_and_files_first_case():
  29. """Create common case for synch function"""
  30. os.makedirs("tests/source/dir1")
  31. os.mkdir("tests/source/dir2")
  32. os.mkdir("tests/source/dir3")
  33. create_file("tests/source/dir1/file1.txt", "abacaba")
  34. os.makedirs("tests/replica/dir1")
  35. os.mkdir("tests/replica/dir4")
  36. yield
  37. shutil.rmtree("tests/source")
  38. shutil.rmtree("tests/replica")
  39. @pytest.fixture
  40. def create_nested_dirs_and_files_second_case():
  41. """Create common case for synch function"""
  42. os.makedirs("tests/source/dir1/dir2")
  43. create_file("tests/source/dir1/dir2/file1.txt", "hello")
  44. os.makedirs("tests/replica/dir1")
  45. os.mkdir("tests/replica/dir4")
  46. create_file("tests/replica/dir4/file2.txt", "hello")
  47. yield
  48. shutil.rmtree("tests/source")
  49. shutil.rmtree("tests/replica")
  50. @pytest.fixture
  51. def create_two_different_files():
  52. """Create two different files"""
  53. os.mkdir("tests/source")
  54. os.mkdir("tests/replica")
  55. create_file("tests/source/file1.txt", "aaa")
  56. create_file("tests/replica/file1.txt", "bbb")
  57. yield
  58. shutil.rmtree("tests/source")
  59. shutil.rmtree("tests/replica")
  60. @pytest.fixture
  61. def create_empty_source_dir():
  62. """Create empty source dir and non-empty replic's one"""
  63. os.mkdir("tests/source")
  64. os.makedirs("tests/replica/dir1")
  65. yield
  66. shutil.rmtree("tests/source")
  67. shutil.rmtree("tests/replica")
  68. @pytest.fixture
  69. def create_empty_replica_dir():
  70. """Create empty replica dir and non-empty source one"""
  71. os.makedirs("tests/source/dir1/dir2")
  72. os.mkdir("tests/replica")
  73. yield
  74. shutil.rmtree("tests/source")
  75. shutil.rmtree("tests/replica")