Skip to content

Commit 435eaf8

Browse files
committed
Added more tests to improve test-coverage
1 parent 9b9573e commit 435eaf8

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

ellar_cli/service/cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def import_configuration(self) -> t.Type["Config"]:
214214
@_export_ellar_config_module
215215
def get_application_config(self) -> "Config":
216216
assert self._meta
217-
if not self._store.config_instance:
217+
if not self._store.config_instance: # pragma: no cover
218218
self._store.config_instance = Config(
219219
os.environ.get(ELLAR_CONFIG_MODULE, self._meta.config)
220220
)
@@ -302,11 +302,11 @@ def _import_from_string(self) -> t.Any:
302302
) from attr_ex
303303
return instance
304304

305-
def import_configuration(self) -> t.Type[Config]: # pragma: no cover
306-
raise Exception("Not Available")
305+
def import_configuration(self) -> t.Type[Config]:
306+
raise EllarCLIException("Not Available")
307307

308308
def get_application_config(self) -> Config:
309309
return self.import_application().config
310310

311-
def import_root_module(self) -> t.Type[ModuleBase]: # pragma: no cover
312-
raise Exception("Not Available")
311+
def import_root_module(self) -> t.Type[ModuleBase]:
312+
raise EllarCLIException("Not Available")

tests/sample_app/apps/good_app.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/env python
22
import click
33
from ellar.app import AppFactory
4+
from ellar.core import Config
45
from ellar.samples import HomeModule
56

7+
from ellar_cli.constants import ELLAR_META
68
from ellar_cli.main import create_ellar_cli
9+
from ellar_cli.service import EllarCLIService
710

811

912
def bootstrap():
@@ -15,9 +18,33 @@ def bootstrap():
1518

1619

1720
@cli.command()
18-
def working():
21+
@click.pass_context
22+
def working(ctx: click.Context):
23+
ellar_cli_service: EllarCLIService = ctx.meta.get(ELLAR_META)
24+
assert isinstance(ellar_cli_service.get_application_config(), Config)
1925
click.echo("Working")
2026

2127

28+
@cli.command()
29+
@click.pass_context
30+
def failing_1(ctx: click.Context):
31+
ellar_cli_service: EllarCLIService = ctx.meta.get(ELLAR_META)
32+
ellar_cli_service.import_configuration()
33+
34+
35+
@cli.command()
36+
@click.pass_context
37+
def failing_2(ctx: click.Context):
38+
ellar_cli_service: EllarCLIService = ctx.meta.get(ELLAR_META)
39+
ellar_cli_service.import_configuration()
40+
41+
42+
@cli.command()
43+
@click.pass_context
44+
def failing_3(ctx: click.Context):
45+
ellar_cli_service: EllarCLIService = ctx.meta.get(ELLAR_META)
46+
ellar_cli_service.import_root_module()
47+
48+
2249
if __name__ == "__main__":
2350
cli()

tests/test_ellar_cli_service.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,34 @@ def test_apps_good_app_cli_works(change_os_dir):
198198
assert result.stdout == good_app_info
199199

200200

201+
def test_apps_good_app_working_command(change_os_dir):
202+
result = subprocess.run(
203+
["python", "apps/good_app.py", "working"], stdout=subprocess.PIPE
204+
)
205+
assert result.returncode == 0
206+
assert result.stdout == b"Working\n"
207+
208+
209+
def test_apps_good_app_failing_commands(change_os_dir):
210+
result = subprocess.run(
211+
["python", "apps/good_app.py", "failing-1"], stderr=subprocess.PIPE
212+
)
213+
assert result.returncode == 1
214+
assert result.stderr == b"Error: Not Available\n"
215+
216+
result = subprocess.run(
217+
["python", "apps/good_app.py", "failing-2"], stderr=subprocess.PIPE
218+
)
219+
assert result.returncode == 1
220+
assert result.stderr == b"Error: Not Available\n"
221+
222+
result = subprocess.run(
223+
["python", "apps/good_app.py", "failing-3"], stderr=subprocess.PIPE
224+
)
225+
assert result.returncode == 1
226+
assert result.stderr == b"Error: Not Available\n"
227+
228+
201229
def test_apps_bad_app_fails(change_os_dir):
202230
result = subprocess.run(
203231
["python", "apps/bad_app.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE

0 commit comments

Comments
 (0)