|
1 |
| -# from click.testing import CliRunner |
2 |
| -# import meorg_client.cli as cli |
3 |
| -# import os |
4 |
| -# import meorg_client.utilities as mu |
5 |
| -# from conftest import store |
6 |
| -# import pytest |
7 |
| -# import time |
8 |
| - |
9 |
| - |
10 |
| -# @pytest.fixture |
11 |
| -# def runner() -> CliRunner: |
12 |
| -# """Get a runner object. |
13 |
| - |
14 |
| -# Returns |
15 |
| -# ------- |
16 |
| -# click.testing.CliRunner |
17 |
| -# Runner object. |
18 |
| -# """ |
19 |
| -# return CliRunner() |
20 |
| - |
21 |
| - |
22 |
| -# @pytest.fixture |
23 |
| -# def test_filepath() -> str: |
24 |
| -# """Get a test filepath from the installation. |
25 |
| - |
26 |
| -# Returns |
27 |
| -# ------- |
28 |
| -# str |
29 |
| -# Path to the test filepath. |
30 |
| -# """ |
31 |
| -# return os.path.join(mu.get_installed_data_root(), "test/test.txt") |
32 |
| - |
33 |
| - |
34 |
| -# def test_list_endpoints(runner: CliRunner): |
35 |
| -# """Test list-endpoints via CLI.""" |
36 |
| -# result = runner.invoke(cli.list_endpoints) |
37 |
| -# assert result.exit_code == 0 |
38 |
| - |
39 |
| - |
40 |
| -# def test_file_upload(runner: CliRunner, test_filepath: str): |
41 |
| -# """Test file-upload via CLI.""" |
42 |
| - |
43 |
| -# # Upload a tiny test file |
44 |
| -# result = runner.invoke(cli.file_upload, [test_filepath, store.get("model_output_id")]) |
45 |
| -# assert result.exit_code == 0 |
46 |
| - |
47 |
| -# # Add the job_id to the store for the next test |
48 |
| -# store.set("file_id", result.stdout.split()[-1].strip()) |
49 |
| - |
50 |
| -# # Let it wait for a short while, allow the server to transfer to object store. |
51 |
| -# time.sleep(5) |
52 |
| - |
53 |
| - |
54 |
| -# def test_file_multiple(runner: CliRunner, test_filepath: str): |
55 |
| -# """Test file-upload via CLI.""" |
56 |
| - |
57 |
| -# # Upload a tiny test file |
58 |
| -# result = runner.invoke(cli.file_upload, [test_filepath, test_filepath, store.get("model_output_id")]) |
59 |
| -# assert result.exit_code == 0 |
60 |
| - |
61 |
| -# # Add the job_id to the store for the next test |
62 |
| -# store.set("file_ids", result.output.strip()) |
63 |
| - |
64 |
| -# # Let it wait for a short while, allow the server to transfer to object store. |
65 |
| -# time.sleep(5) |
66 |
| - |
67 |
| - |
68 |
| -# def test_file_list(runner): |
69 |
| -# """Test file-list via CLI.""" |
70 |
| -# result = runner.invoke(cli.file_list, [store.get("model_output_id")]) |
71 |
| -# assert result.exit_code == 0 |
72 |
| - |
73 |
| - |
74 |
| -# # def test_file_attach(runner): |
75 |
| -# # """Test file-attach via CLI.""" |
76 |
| - |
77 |
| -# # result = runner.invoke( |
78 |
| -# # cli.file_attach, [store.get("file_id"), store.get("model_output_id")] |
79 |
| -# # ) |
80 |
| - |
81 |
| -# # assert result.exit_code == 0 |
82 |
| - |
83 |
| - |
84 |
| -# # def test_file_upload_with_attach(runner, test_filepath): |
85 |
| -# # """Test file upload with attachment via CLI.""" |
86 |
| -# # model_output_id = store.get("model_output_id") |
87 |
| -# # result = runner.invoke( |
88 |
| -# # cli.file_upload, [test_filepath, test_filepath, "--attach_to", model_output_id] |
89 |
| -# # ) |
90 |
| -# # assert result.exit_code == 0 |
91 |
| - |
92 |
| - |
93 |
| -# def test_file_upload_parallel(runner: CliRunner, test_filepath: str): |
94 |
| -# """Test file-upload via CLI.""" |
95 |
| - |
96 |
| -# # Upload a tiny test file |
97 |
| -# result = runner.invoke(cli.file_upload, [test_filepath, test_filepath, store.get("model_output_id"), "-n", "2"]) |
98 |
| -# assert result.exit_code == 0 |
99 |
| - |
100 |
| - |
101 |
| -# # def test_file_upload_parallel_with_attach(runner, test_filepath): |
102 |
| -# # """Test file upload with attachment via CLI.""" |
103 |
| -# # model_output_id = store.get("model_output_id") |
104 |
| -# # result = runner.invoke( |
105 |
| -# # cli.file_upload, |
106 |
| -# # [test_filepath, test_filepath, "-n", "2", "--attach_to", model_output_id], |
107 |
| -# # ) |
108 |
| -# # assert result.exit_code == 0 |
109 |
| - |
110 |
| - |
111 |
| -# # def test_detach_all(runner): |
112 |
| -# # """Test detaching all files from a model output.""" |
113 |
| -# # model_output_id = store.get("model_output_id") |
114 |
| -# # result = runner.invoke( |
115 |
| -# # cli.file_detach_all, |
116 |
| -# # [model_output_id], |
117 |
| -# # ) |
118 |
| -# # assert result.exit_code == 0 |
| 1 | +"""Test the CLI actions.""" |
| 2 | + |
| 3 | +from click.testing import CliRunner |
| 4 | +import meorg_client.cli as cli |
| 5 | +import os |
| 6 | +import meorg_client.utilities as mu |
| 7 | +from conftest import store |
| 8 | +import pytest |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +def runner() -> CliRunner: |
| 13 | + """Get a runner object. |
| 14 | +
|
| 15 | + Returns |
| 16 | + ------- |
| 17 | + click.testing.CliRunner |
| 18 | + Runner object. |
| 19 | + """ |
| 20 | + return CliRunner() |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +def test_filepath() -> str: |
| 25 | + """Get a test filepath from the installation. |
| 26 | +
|
| 27 | + Returns |
| 28 | + ------- |
| 29 | + str |
| 30 | + Path to the test filepath. |
| 31 | + """ |
| 32 | + return os.path.join(mu.get_installed_data_root(), "test/test.txt") |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture |
| 36 | +def model_output_id() -> str: |
| 37 | + """Get the model output ID out of the environment. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + str |
| 42 | + Model output ID. |
| 43 | + """ |
| 44 | + return os.getenv("MEORG_MODEL_OUTPUT_ID") |
| 45 | + |
| 46 | + |
| 47 | +def test_list_endpoints(runner: CliRunner): |
| 48 | + """Test list-endpoints via CLI. |
| 49 | +
|
| 50 | + Parameters |
| 51 | + ---------- |
| 52 | + runner : CliRunner |
| 53 | + Runner object |
| 54 | + """ |
| 55 | + result = runner.invoke(cli.list_endpoints) |
| 56 | + assert result.exit_code == 0 |
| 57 | + |
| 58 | + |
| 59 | +def test_file_upload(runner: CliRunner, test_filepath: str, model_output_id: str): |
| 60 | + """Test file-upload via CLI. |
| 61 | +
|
| 62 | + Parameters |
| 63 | + ---------- |
| 64 | + runner : CliRunner |
| 65 | + Runner. |
| 66 | + test_filepath : str |
| 67 | + Test filepath. |
| 68 | + model_output_id : str |
| 69 | + Model output ID. |
| 70 | + """ |
| 71 | + # Upload a tiny test file |
| 72 | + result = runner.invoke(cli.file_upload, [test_filepath, model_output_id]) |
| 73 | + assert result.exit_code == 0 |
| 74 | + |
| 75 | + # Add the job_id to the store for the next test |
| 76 | + store.set("file_id", result.stdout.split()[-1].strip()) |
| 77 | + |
| 78 | + |
| 79 | +def test_file_multiple(runner: CliRunner, test_filepath: str, model_output_id: str): |
| 80 | + """Test file-upload via CLI. |
| 81 | +
|
| 82 | + Parameters |
| 83 | + ---------- |
| 84 | + runner : CliRunner |
| 85 | + Runner. |
| 86 | + test_filepath : str |
| 87 | + Test filepath. |
| 88 | + """ |
| 89 | + # Upload multiple files |
| 90 | + result = runner.invoke( |
| 91 | + cli.file_upload, [test_filepath, test_filepath, model_output_id] |
| 92 | + ) |
| 93 | + assert result.exit_code == 0 |
| 94 | + |
| 95 | + # Add the job_id to the store for the next test |
| 96 | + store.set("file_ids", result.stdout.strip()) |
| 97 | + |
| 98 | + |
| 99 | +def test_file_upload_parallel( |
| 100 | + runner: CliRunner, test_filepath: str, model_output_id: str |
| 101 | +): |
| 102 | + """Test file-upload via CLI. |
| 103 | +
|
| 104 | + Parameters |
| 105 | + ---------- |
| 106 | + runner : _type_ |
| 107 | + Runner. |
| 108 | + model_output_id : str |
| 109 | + Model output ID. |
| 110 | + """ |
| 111 | + # Upload multiple files in parallel. |
| 112 | + result = runner.invoke( |
| 113 | + cli.file_upload, [test_filepath, test_filepath, model_output_id, "-n", "2"] |
| 114 | + ) |
| 115 | + assert result.exit_code == 0 |
| 116 | + |
| 117 | + |
| 118 | +def test_file_list(runner: CliRunner): |
| 119 | + """Test file-list via CLI. |
| 120 | +
|
| 121 | + Parameters |
| 122 | + ---------- |
| 123 | + runner : CliRunner |
| 124 | + Runner. |
| 125 | + """ |
| 126 | + result = runner.invoke(cli.file_list, [store.get("model_output_id")]) |
| 127 | + assert result.exit_code == 0 |
| 128 | + |
| 129 | + |
| 130 | +def test_delete_file_from_output(runner: CliRunner, model_output_id: str): |
| 131 | + """Test deleting a file from a model output. |
| 132 | +
|
| 133 | + Parameters |
| 134 | + ---------- |
| 135 | + runner : CliRunner |
| 136 | + Runner. |
| 137 | + model_output_id : str |
| 138 | + Model output ID. |
| 139 | + """ |
| 140 | + # Get the last file added |
| 141 | + file_id = store.get("file_ids").splitlines()[-1] |
| 142 | + |
| 143 | + # Delete it |
| 144 | + result = runner.invoke(cli.file_delete, [store.get("model_output_id"), file_id]) |
| 145 | + assert result.exit_code == 0 |
| 146 | + |
| 147 | + |
| 148 | +def test_delete_all_files_from_output(runner: CliRunner, model_output_id: str): |
| 149 | + """Test deleting all files from a model output. |
| 150 | +
|
| 151 | + Parameters |
| 152 | + ---------- |
| 153 | + runner : CliRunner |
| 154 | + Runner. |
| 155 | + model_output_id : str |
| 156 | + Model output ID. |
| 157 | + """ |
| 158 | + |
| 159 | + result = runner.invoke(cli.file_delete_all, [model_output_id]) |
| 160 | + assert result.exit_code == 0 |
0 commit comments