|
1 | 1 | import os |
| 2 | +import subprocess |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from ellar.app import App |
|
11 | 12 | ) |
12 | 13 | from ellar_cli.service.pyproject import PY_PROJECT_TOML |
13 | 14 |
|
| 15 | +good_app_info = ( |
| 16 | + b"Usage: good_app.py [OPTIONS] COMMAND [ARGS]...\n\n " |
| 17 | + b"Ellar, ASGI Python Web framework\n\nOptions:\n " |
| 18 | + b" --project TEXT Run Specific Command on a specific project [default:\n " |
| 19 | + b" default]\n -v, --version Show the version and exit.\n --help " |
| 20 | + b"Show this message and exit.\n\nCommands:\n create-module - Scaffolds Ellar Application Module -\n " |
| 21 | + b"runserver - Starts Uvicorn Server -\n working\n" |
| 22 | +) |
| 23 | + |
14 | 24 |
|
15 | 25 | def test_import_project_meta_returns_default_when_py_project_is_none(tmp_path): |
16 | 26 | os.chdir(tmp_path) |
@@ -180,3 +190,31 @@ def test_version_works(write_empty_py_project, process_runner): |
180 | 190 | assert "Ellar CLI Version:" in str(result.stdout) and "Ellar Version:" in str( |
181 | 191 | result.stdout |
182 | 192 | ) |
| 193 | + |
| 194 | + |
| 195 | +def test_apps_good_app_cli_works(change_os_dir): |
| 196 | + result = subprocess.run(["python", "apps/good_app.py"], stdout=subprocess.PIPE) |
| 197 | + assert result.returncode == 0 |
| 198 | + assert result.stdout == good_app_info |
| 199 | + |
| 200 | + |
| 201 | +def test_apps_bad_app_fails(change_os_dir): |
| 202 | + result = subprocess.run( |
| 203 | + ["python", "apps/bad_app.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 204 | + ) |
| 205 | + assert result.returncode == 1 |
| 206 | + assert ( |
| 207 | + result.stderr |
| 208 | + == b"Error: Coroutine Application Bootstrapping is not supported.\n" |
| 209 | + ) |
| 210 | + |
| 211 | + |
| 212 | +def test_apps_bad_app_2_fails(change_os_dir): |
| 213 | + result = subprocess.run( |
| 214 | + ["python", "apps/bad_app_2.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 215 | + ) |
| 216 | + assert result.returncode == 1 |
| 217 | + assert ( |
| 218 | + b'Error: Attribute "bootstrap_unknown" not found in python module' |
| 219 | + in result.stderr |
| 220 | + ) |
0 commit comments