-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_helpers.py
68 lines (45 loc) · 1.66 KB
/
test_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pytest
import os
import shutil
from helpers import (
get_notebook_cmd,
get_python_cmd,
install_dependencies,
archive_directory,
)
# Define test data or fixtures if needed
@pytest.fixture
def test_data_dir(tmpdir):
# Create a temporary directory for testing
test_dir = tmpdir.mkdir("test_data")
yield str(test_dir)
# Test get_notebook_cmd function
# Test get_python_cmd function
def test_get_python_cmd():
cmd = get_python_cmd("starter_script.py", "python3")
assert cmd == ["python3", "starter_script.py"]
# Test install_dependencies function
def test_install_dependencies():
# Provide a requirements.txt file for testing
requirements_path = "samples/sample_v3_2/requirements.txt"
result = install_dependencies("python3", requirements_path)
assert result.returncode == 0 # Check that the installation was successful
# Test archive_directory function
def test_archive_directory(test_data_dir):
# Create a temporary directory with some test files
test_files_dir = os.path.join(test_data_dir, "test_files")
os.makedirs(test_files_dir)
with open(os.path.join(test_files_dir, "file1.txt"), "w") as f:
f.write("Test file 1 content")
with open(os.path.join(test_files_dir, "file2.txt"), "w") as f:
f.write("Test file 2 content")
# Archive the directory
archive_path = os.path.join(test_data_dir, "test_archive")
created_archive = archive_directory(
archive_path, test_files_dir, test_data_dir
)
# Check that the archive file was created
assert os.path.exists(created_archive)
# Add more test cases as needed
if __name__ == "__main__":
pytest.main()