Replace os.system() in clear_screen() with ANSI escape codes
- Eliminates shell injection risk from os.system('clear'/'cls')
- Uses ANSI escape sequence \033[H\033[2J instead
- Removed unused os import
- Added test verifying ANSI codes are used
This commit is contained in:
+7
-1
@@ -4,7 +4,7 @@ import unittest
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
|
||||
from whisper_live.utils import format_time, create_srt_file, print_transcript
|
||||
from whisper_live.utils import format_time, create_srt_file, print_transcript, clear_screen
|
||||
|
||||
|
||||
class TestFormatTime(unittest.TestCase):
|
||||
@@ -97,6 +97,12 @@ class TestCreateSrtFile(unittest.TestCase):
|
||||
|
||||
|
||||
class TestPrintTranscript(unittest.TestCase):
|
||||
@patch("sys.stdout", new_callable=StringIO)
|
||||
def test_clear_screen_uses_ansi(self, mock_stdout):
|
||||
clear_screen()
|
||||
output = mock_stdout.getvalue()
|
||||
self.assertIn("\033[H\033[2J", output)
|
||||
|
||||
@patch("sys.stdout", new_callable=StringIO)
|
||||
def test_print_plain_text(self, mock_stdout):
|
||||
text = ["Hello", " world"]
|
||||
|
||||
Reference in New Issue
Block a user