@@ -177,15 +177,19 @@ class ExternalTestMixin(_Base):
177
177
"""A cmd2 plugin (mixin class) that exposes an interface to execute application commands from python"""
178
178
179
179
def __init__ (self , * args , ** kwargs ):
180
- """
180
+ """Initializes the ExternalTestMixin.
181
+
182
+ This class is intended to be used in multiple inheritance alongside `cmd2.Cmd` for an application class.
183
+ When doing this multiple inheritance, it is imperative that this mixin class come first.
181
184
182
185
:type self: cmd2.Cmd
183
- :param args:
184
- :param kwargs:
186
+ :param args: arguments to pass to the superclass
187
+ :param kwargs: keyword arguments to pass to the superclass
185
188
"""
186
189
# code placed here runs before cmd2 initializes
187
190
super ().__init__ (* args , ** kwargs )
188
- assert isinstance (self , cmd2 .Cmd )
191
+ if not isinstance (self , cmd2 .Cmd ):
192
+ raise TypeError ('The ExternalTestMixin class is intended to be used in multiple inhertance with cmd2.Cmd' )
189
193
# code placed here runs after cmd2 initializes
190
194
self ._pybridge = cmd2 .py_bridge .PyBridge (self )
191
195
@@ -197,19 +201,19 @@ def app_cmd(self, command: str, echo: bool | None = None) -> cmd2.CommandResult:
197
201
:param echo: Flag whether the command's output should be echoed to stdout/stderr
198
202
:return: A CommandResult object that captures stdout, stderr, and the command's result object
199
203
"""
200
- assert isinstance (self , cmd2 .Cmd )
201
- assert isinstance (self , ExternalTestMixin )
202
204
try :
203
205
self ._in_py = True
204
-
205
206
return self ._pybridge (command , echo = echo )
206
207
207
208
finally :
208
209
self ._in_py = False
209
210
210
211
def fixture_setup (self ):
211
- """
212
- Replicates the behavior of `cmdloop()` preparing the state of the application
212
+ """Replicates the behavior of `cmdloop()` to prepare the application state for testing.
213
+
214
+ This method runs all preloop hooks and the preloop method to ensure the
215
+ application is in the correct state before running a test.
216
+
213
217
:type self: cmd2.Cmd
214
218
"""
215
219
@@ -218,8 +222,10 @@ def fixture_setup(self):
218
222
self .preloop ()
219
223
220
224
def fixture_teardown (self ):
221
- """
222
- Replicates the behavior of `cmdloop()` tearing down the application
225
+ """Replicates the behavior of `cmdloop()` to tear down the application after a test.
226
+
227
+ This method runs all postloop hooks and the postloop method to clean up
228
+ the application state and ensure test isolation.
223
229
224
230
:type self: cmd2.Cmd
225
231
"""
0 commit comments