Skip to content

Commit dd6f6b1

Browse files
committed
Started refactoring transcript testing to have a better display of information to the user
1 parent a9ce49b commit dd6f6b1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cmd2/cmd2.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3708,7 +3708,10 @@ def _run_transcript_tests(self, transcript_paths: List[str]) -> None:
37083708
37093709
:param transcript_paths: list of transcript test file paths
37103710
"""
3711+
import time
37113712
import unittest
3713+
import cmd2
3714+
from colorama import Style
37123715
from .transcript import Cmd2TestCase
37133716

37143717
class TestMyAppCase(Cmd2TestCase):
@@ -3721,15 +3724,28 @@ class TestMyAppCase(Cmd2TestCase):
37213724
self.exit_code = -1
37223725
return
37233726

3727+
verinfo = ".".join(map(str, sys.version_info[:3]))
3728+
num_transcripts = len(transcripts_expanded)
3729+
plural = '' if len(transcripts_expanded) == 1 else 's'
3730+
self.poutput(Style.BRIGHT + utils.center_text('cmd2 transcript test', pad='=') + Style.RESET_ALL)
3731+
self.poutput('platform {} -- Python {}, cmd2-{}, readline-{}'.format(sys.platform, verinfo, cmd2.__version__,
3732+
rl_type))
3733+
self.poutput('cwd: {}'.format(os.getcwd()))
3734+
self.poutput('cmd2 app: {}'.format(sys.argv[0]))
3735+
self.poutput(Style.BRIGHT + 'collected {} transcript{}\n'.format(num_transcripts, plural) + Style.RESET_ALL)
3736+
37243737
self.__class__.testfiles = transcripts_expanded
37253738
sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main()
37263739
testcase = TestMyAppCase()
37273740
stream = utils.StdSim(sys.stderr)
37283741
runner = unittest.TextTestRunner(stream=stream)
3742+
start_time = time.time()
37293743
test_results = runner.run(testcase)
3744+
execution_time = time.time() - start_time
37303745
if test_results.wasSuccessful():
37313746
self._decolorized_write(sys.stderr, stream.read())
3732-
self.poutput('Tests passed', color=Fore.LIGHTGREEN_EX)
3747+
finish_msg = '{0} transcript{1} passed in {2:.3f} seconds'.format(num_transcripts, plural, execution_time)
3748+
self.poutput(Style.BRIGHT + utils.center_text(finish_msg, pad='=') + Style.RESET_ALL, color=Fore.GREEN)
37333749
else:
37343750
# Strip off the initial traceback which isn't particularly useful for end users
37353751
error_str = stream.read()

0 commit comments

Comments
 (0)