Skip to content

Commit

Permalink
idempotency tests for parsers for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Feb 26, 2024
1 parent c460f65 commit a31b496
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ preserved, so that TyperCommand can be a drop in replacement.

**django-typer makes it easy to:**

* Define your command CLI interface in as clear, DRY, and safely as possible using type hints
* Define your command CLI interface in a clear, DRY and safe way using type hints
* Create subcommand and group command hierarchies.
* Use the full power of Typer's parameter types to validate and parse command line inputs.
* Create beautiful and information dense help outputs.
Expand Down
17 changes: 17 additions & 0 deletions django_typer/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,10 @@ def test_poll_ex(self):
class TestShellCompletersAndParsers(TestCase):
def setUp(self):
super().setUp()
self.q1 = Question.objects.create(
question_text="Is Putin a war criminal?",
pub_date=timezone.now(),
)
for field, values in {
"char_field": ["jon", "john", "jack", "jason"],
"text_field": [
Expand Down Expand Up @@ -1819,6 +1823,19 @@ def tearDown(self) -> None:
ShellCompleteTester.objects.all().delete()
return super().tearDown()

def test_model_object_parser_idempotency(self):
from django_typer.parsers import ModelObjectParser
from django_typer.tests.polls.models import Question

parser = ModelObjectParser(Question)
self.assertEqual(parser.convert(self.q1, None, None), self.q1)

def test_app_label_parser_idempotency(self):
from django_typer.parsers import parse_app_label

poll_app = apps.get_app_config("django_typer_tests_polls")
self.assertEqual(parse_app_label(poll_app), poll_app)

def test_app_label_parser_completers(self):
from django.apps import apps

Expand Down
2 changes: 1 addition & 1 deletion doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BaseCommand functionality is preserved, so that TyperCommand can be a drop in re

**django-typer makes it easy to:**

* Define your command CLI interface in as clear, DRY, and safely as possible using type hints
* Define your command CLI interface in a clear, DRY and safe way using type hints
* Create subcommand and group command hierarchies.
* Use the full power of Typer's parameter types to validate and parse command line inputs.
* Create beautiful and information dense help outputs.
Expand Down

0 comments on commit a31b496

Please sign in to comment.