From 70c9c693076cb67ca74439231136837f11f1caf9 Mon Sep 17 00:00:00 2001 From: Brian Kohan Date: Thu, 10 Oct 2024 15:21:17 -0700 Subject: [PATCH] fix no rich test for #129 --- tests/test_basics.py | 131 ++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 59 deletions(-) diff --git a/tests/test_basics.py b/tests/test_basics.py index f15e1c6f..8eb00641 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -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 @@ -133,18 +133,23 @@ 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() @@ -152,16 +157,15 @@ def test_cmd_help_order(self): 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) @@ -171,20 +175,27 @@ 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() @@ -192,19 +203,25 @@ def test_cmd_help_order(self): 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() @@ -212,12 +229,8 @@ def test_cmd_help_order(self): 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))