Skip to content

Commit

Permalink
fix no rich test for #129
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Oct 10, 2024
1 parent e78bd75 commit 70c9c69
Showing 1 changed file with 72 additions and 59 deletions.
131 changes: 72 additions & 59 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.test import TestCase

from django_typer.management import TyperCommand, get_command
from tests.utils import run_command
from tests.utils import run_command, rich_installed
from django_typer.utils import get_current_command


Expand Down Expand Up @@ -133,35 +133,39 @@ def test_cmd_help_order(self):
cmd.print_help("./manage.py", "order")
hlp = buffer.getvalue()

self.assertTrue(
"""
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ order │
│ b │
│ a │
│ d │
│ c │
╰──────────────────────────────────────────────────────────────────────────────╯
""".strip()
in hlp
)
if rich_installed:
self.assertTrue(
hlp.index("│ order")
< hlp.index("│ b")
< hlp.index("│ a")
< hlp.index("│ d")
< hlp.index("│ c")
)
else:
cmd_idx = hlp.index("Commands")
self.assertTrue(
hlp.index(" order", cmd_idx)
< hlp.index(" b", cmd_idx)
< hlp.index(" a", cmd_idx)
< hlp.index(" d", cmd_idx)
< hlp.index(" c", cmd_idx)
)

buffer.seek(0)
buffer.truncate()

cmd.print_help("./manage.py", "order", "d")
hlp = buffer.getvalue()

self.assertTrue(
"""
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ g │
│ e │
│ f │
╰──────────────────────────────────────────────────────────────────────────────╯
""".strip()
in hlp
)
if rich_installed:
self.assertTrue(hlp.index("│ g") < hlp.index("│ e") < hlp.index("│ f"))
else:
cmd_idx = hlp.index("Commands")
self.assertTrue(
hlp.index(" g", cmd_idx)
< hlp.index(" e", cmd_idx)
< hlp.index(" f", cmd_idx)
)

cmd2 = get_command("order2", TyperCommand, stdout=buffer, no_color=True)

Expand All @@ -171,53 +175,62 @@ def test_cmd_help_order(self):
cmd2.print_help("./manage.py", "order2")
hlp = buffer.getvalue()

self.assertTrue(
"""
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ order2 Override handle │
│ b │
│ a │
│ d │
│ c │
│ bb │
│ aa │
╰──────────────────────────────────────────────────────────────────────────────╯
""".strip()
in hlp
)
if rich_installed:
self.assertTrue(
hlp.index("│ order2")
< hlp.index("│ b")
< hlp.index("│ a ")
< hlp.index("│ d")
< hlp.index("│ c")
< hlp.index("│ bb")
< hlp.index("│ aa")
)
else:
cmd_idx = hlp.index("Commands")
self.assertTrue(
hlp.index(" order2", cmd_idx)
< hlp.index(" b", cmd_idx)
< hlp.index(" a", cmd_idx)
< hlp.index(" d", cmd_idx)
< hlp.index(" c", cmd_idx)
< hlp.index(" bb", cmd_idx)
< hlp.index(" aa", cmd_idx)
)

buffer.seek(0)
buffer.truncate()

cmd2.print_help("./manage.py", "order2", "d")
hlp = buffer.getvalue()

self.assertTrue(
"""
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ g │
│ e │
│ f │
│ i │
│ h │
│ x │
╰──────────────────────────────────────────────────────────────────────────────╯
""".strip()
in hlp
)
if rich_installed:
self.assertTrue(
hlp.index("│ g")
< hlp.index("│ e")
< hlp.index("│ f")
< hlp.index("│ i")
< hlp.index("│ h")
< hlp.index("│ x")
)
else:
cmd_idx = hlp.index("Commands")
self.assertTrue(
hlp.index(" g", cmd_idx)
< hlp.index(" e", cmd_idx)
< hlp.index(" f", cmd_idx)
< hlp.index(" i", cmd_idx)
< hlp.index(" h", cmd_idx)
< hlp.index(" x", cmd_idx)
)

buffer.seek(0)
buffer.truncate()

cmd2.print_help("./manage.py", "order2", "d", "x")
hlp = buffer.getvalue()

self.assertTrue(
"""
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ z │
│ y │
╰──────────────────────────────────────────────────────────────────────────────╯
""".strip()
in hlp
)
if rich_installed:
self.assertTrue(hlp.index("│ z") < hlp.index("│ y"))
else:
cmd_idx = hlp.index("Commands")
self.assertTrue(hlp.index(" z", cmd_idx) < hlp.index(" y", cmd_idx))

0 comments on commit 70c9c69

Please sign in to comment.