11import contextlib
22from io import StringIO
3+ import pytest
4+ import sys
35
46from django .core .management import call_command
57from django .test import SimpleTestCase
1820]
1921
2022
23+ @pytest .mark .skipif (sys .version_info < (3 , 9 ), reason = "requires python 3.9+" )
2124class TestPollExample (SimpleTestCase ):
2225 q1 = None
2326 q2 = None
2427 q3 = None
2528
2629 databases = {"default" }
2730
31+ typer = ""
32+
2833 def setUp (self ):
2934 self .q1 = Question .objects .create (
3035 question_text = "Is Putin a war criminal?" ,
@@ -51,15 +56,18 @@ def test_poll_complete(self):
5156 result1 = StringIO ()
5257 with contextlib .redirect_stdout (result1 ):
5358 call_command (
54- "shellcompletion" , "complete" , shell = shell , cmd_str = "closepoll "
59+ "shellcompletion" ,
60+ "complete" ,
61+ shell = shell ,
62+ cmd_str = f"closepoll{ self .typer } " ,
5563 )
5664 result2 = StringIO ()
5765 with contextlib .redirect_stdout (result2 ):
5866 call_command (
5967 "shellcompletion" ,
6068 "complete" ,
6169 shell = shell ,
62- cmd_str = "./manage.py closepoll " ,
70+ cmd_str = f "./manage.py closepoll{ self . typer } " ,
6371 )
6472
6573 result = result1 .getvalue ()
@@ -70,23 +78,23 @@ def test_poll_complete(self):
7078 self .assertTrue (q .question_text in result )
7179
7280 def test_tutorial1 (self ):
73- result = run_command ("closepoll_t1" , str (self .q2 .id ))
81+ result = run_command (f "closepoll_t1{ self . typer } " , str (self .q2 .id ))
7482 self .assertFalse (result [1 ])
7583 self .assertTrue ("Successfully closed poll" in result [0 ])
7684
7785 def test_tutorial2 (self ):
78- result = run_command ("closepoll_t2" , str (self .q2 .id ))
86+ result = run_command (f "closepoll_t2{ self . typer } " , str (self .q2 .id ))
7987 self .assertFalse (result [1 ])
8088 self .assertTrue ("Successfully closed poll" in result [0 ])
8189
8290 def test_tutorial_parser (self ):
83- result = run_command ("closepoll_t3" , str (self .q1 .id ))
91+ result = run_command (f "closepoll_t3{ self . typer } " , str (self .q1 .id ))
8492 self .assertFalse (result [1 ])
8593
8694 def test_tutorial_parser_cmd (self ):
8795 log = StringIO ()
88- call_command ("closepoll_t3" , str (self .q1 .id ), stdout = log )
89- cmd = get_command ("closepoll_t3" , stdout = log )
96+ call_command (f "closepoll_t3{ self . typer } " , str (self .q1 .id ), stdout = log )
97+ cmd = get_command (f "closepoll_t3{ self . typer } " , stdout = log )
9098 cmd ([self .q1 ])
9199 cmd (polls = [self .q1 ])
92100 # these don't work, maybe revisit in future?
@@ -96,13 +104,18 @@ def test_tutorial_parser_cmd(self):
96104
97105 def test_tutorial_modelobjparser_cmd (self ):
98106 log = StringIO ()
99- call_command ("closepoll_t6" , str (self .q1 .id ), stdout = log )
100- cmd = get_command ("closepoll_t6" , stdout = log )
107+ call_command (f "closepoll_t6{ self . typer } " , str (self .q1 .id ), stdout = log )
108+ cmd = get_command (f "closepoll_t6{ self . typer } " , stdout = log )
101109 cmd ([self .q1 ])
102110 cmd (polls = [self .q1 ])
103111 self .assertEqual (log .getvalue ().count ("Successfully" ), 3 )
104112
105113 def test_poll_ex (self ):
106- result = run_command ("closepoll" , str (self .q2 .id ))
114+ result = run_command (f "closepoll{ self . typer } " , str (self .q2 .id ))
107115 self .assertFalse (result [1 ])
108116 self .assertTrue ("Successfully closed poll" in result [0 ])
117+
118+
119+ @pytest .mark .skipif (sys .version_info < (3 , 9 ), reason = "requires python 3.9+" )
120+ class TestPollExampleTyper (SimpleTestCase ):
121+ typer = "_typer"
0 commit comments