Skip to content

Commit 70c9c69

Browse files
committed
fix no rich test for #129
1 parent e78bd75 commit 70c9c69

File tree

1 file changed

+72
-59
lines changed

1 file changed

+72
-59
lines changed

tests/test_basics.py

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.test import TestCase
77

88
from django_typer.management import TyperCommand, get_command
9-
from tests.utils import run_command
9+
from tests.utils import run_command, rich_installed
1010
from django_typer.utils import get_current_command
1111

1212

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

136-
self.assertTrue(
137-
"""
138-
╭─ Commands ───────────────────────────────────────────────────────────────────╮
139-
│ order │
140-
│ b │
141-
│ a │
142-
│ d │
143-
│ c │
144-
╰──────────────────────────────────────────────────────────────────────────────╯
145-
""".strip()
146-
in hlp
147-
)
136+
if rich_installed:
137+
self.assertTrue(
138+
hlp.index("│ order")
139+
< hlp.index("│ b")
140+
< hlp.index("│ a")
141+
< hlp.index("│ d")
142+
< hlp.index("│ c")
143+
)
144+
else:
145+
cmd_idx = hlp.index("Commands")
146+
self.assertTrue(
147+
hlp.index(" order", cmd_idx)
148+
< hlp.index(" b", cmd_idx)
149+
< hlp.index(" a", cmd_idx)
150+
< hlp.index(" d", cmd_idx)
151+
< hlp.index(" c", cmd_idx)
152+
)
148153

149154
buffer.seek(0)
150155
buffer.truncate()
151156

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

155-
self.assertTrue(
156-
"""
157-
╭─ Commands ───────────────────────────────────────────────────────────────────╮
158-
│ g │
159-
│ e │
160-
│ f │
161-
╰──────────────────────────────────────────────────────────────────────────────╯
162-
""".strip()
163-
in hlp
164-
)
160+
if rich_installed:
161+
self.assertTrue(hlp.index("│ g") < hlp.index("│ e") < hlp.index("│ f"))
162+
else:
163+
cmd_idx = hlp.index("Commands")
164+
self.assertTrue(
165+
hlp.index(" g", cmd_idx)
166+
< hlp.index(" e", cmd_idx)
167+
< hlp.index(" f", cmd_idx)
168+
)
165169

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

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

174-
self.assertTrue(
175-
"""
176-
╭─ Commands ───────────────────────────────────────────────────────────────────╮
177-
│ order2 Override handle │
178-
│ b │
179-
│ a │
180-
│ d │
181-
│ c │
182-
│ bb │
183-
│ aa │
184-
╰──────────────────────────────────────────────────────────────────────────────╯
185-
""".strip()
186-
in hlp
187-
)
178+
if rich_installed:
179+
self.assertTrue(
180+
hlp.index("│ order2")
181+
< hlp.index("│ b")
182+
< hlp.index("│ a ")
183+
< hlp.index("│ d")
184+
< hlp.index("│ c")
185+
< hlp.index("│ bb")
186+
< hlp.index("│ aa")
187+
)
188+
else:
189+
cmd_idx = hlp.index("Commands")
190+
self.assertTrue(
191+
hlp.index(" order2", cmd_idx)
192+
< hlp.index(" b", cmd_idx)
193+
< hlp.index(" a", cmd_idx)
194+
< hlp.index(" d", cmd_idx)
195+
< hlp.index(" c", cmd_idx)
196+
< hlp.index(" bb", cmd_idx)
197+
< hlp.index(" aa", cmd_idx)
198+
)
188199

189200
buffer.seek(0)
190201
buffer.truncate()
191202

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

195-
self.assertTrue(
196-
"""
197-
╭─ Commands ───────────────────────────────────────────────────────────────────╮
198-
│ g │
199-
│ e │
200-
│ f │
201-
│ i │
202-
│ h │
203-
│ x │
204-
╰──────────────────────────────────────────────────────────────────────────────╯
205-
""".strip()
206-
in hlp
207-
)
206+
if rich_installed:
207+
self.assertTrue(
208+
hlp.index("│ g")
209+
< hlp.index("│ e")
210+
< hlp.index("│ f")
211+
< hlp.index("│ i")
212+
< hlp.index("│ h")
213+
< hlp.index("│ x")
214+
)
215+
else:
216+
cmd_idx = hlp.index("Commands")
217+
self.assertTrue(
218+
hlp.index(" g", cmd_idx)
219+
< hlp.index(" e", cmd_idx)
220+
< hlp.index(" f", cmd_idx)
221+
< hlp.index(" i", cmd_idx)
222+
< hlp.index(" h", cmd_idx)
223+
< hlp.index(" x", cmd_idx)
224+
)
208225

209226
buffer.seek(0)
210227
buffer.truncate()
211228

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

215-
self.assertTrue(
216-
"""
217-
╭─ Commands ───────────────────────────────────────────────────────────────────╮
218-
│ z │
219-
│ y │
220-
╰──────────────────────────────────────────────────────────────────────────────╯
221-
""".strip()
222-
in hlp
223-
)
232+
if rich_installed:
233+
self.assertTrue(hlp.index("│ z") < hlp.index("│ y"))
234+
else:
235+
cmd_idx = hlp.index("Commands")
236+
self.assertTrue(hlp.index(" z", cmd_idx) < hlp.index(" y", cmd_idx))

0 commit comments

Comments
 (0)