Compare commits

...
2 Commits
Author SHA1 Message Date
Diuse e897bad506 fixed # 还是修复CI问题 2026-10-28 09:49:06 +08:00
Diuse b851e490be fixed # 修复CI问题 2026-10-28 09:28:33 +08:00
+18 -3
View File
@@ -1,5 +1,6 @@
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from io import BytesIO, StringIO from io import BytesIO, StringIO
from itertools import count
from pathlib import Path from pathlib import Path
import re import re
import subprocess import subprocess
@@ -107,6 +108,7 @@ class BundleTests(unittest.TestCase):
def test_download_refreshes_terminal_progress_on_same_line(self): def test_download_refreshes_terminal_progress_on_same_line(self):
from rich.console import Console from rich.console import Console
from rich.progress import Progress
class Response(BytesIO): class Response(BytesIO):
headers = {'Content-Length': '262144'} headers = {'Content-Length': '262144'}
@@ -114,12 +116,16 @@ class BundleTests(unittest.TestCase):
return 'https://farm.example/private/assets.zip' return 'https://farm.example/private/assets.zip'
terminal = StringIO() terminal = StringIO()
terminal.isatty = lambda: True terminal.isatty = lambda: True
progress_clock = count()
with patch.dict('os.environ', {'TERM': 'xterm-256color'}), \ with patch.dict('os.environ', {'TERM': 'xterm-256color'}), \
patch.object(bundle.sys, 'stderr', terminal), \ patch.object(bundle.sys, 'stderr', terminal), \
patch('rich.console.Console', side_effect=lambda **kwargs: patch('rich.console.Console', side_effect=lambda **kwargs:
Console(**kwargs, force_terminal=True, Console(**kwargs, force_terminal=True,
force_interactive=True, legacy_windows=False, force_interactive=True, legacy_windows=False,
color_system='standard', width=120)), \ color_system='standard', width=120)), \
patch('rich.progress.Progress', side_effect=lambda *args,
**kwargs: Progress(*args, **kwargs,
get_time=lambda: next(progress_clock))), \
patch.object(bundle, 'urlopen', return_value=Response( patch.object(bundle, 'urlopen', return_value=Response(
b'x' * 262144)), patch.object( b'x' * 262144)), patch.object(
bundle, 'time', SimpleNamespace(monotonic=Mock( bundle, 'time', SimpleNamespace(monotonic=Mock(
@@ -190,6 +196,8 @@ class BundleTests(unittest.TestCase):
display.stop.assert_called_once() display.stop.assert_called_once()
def test_download_failure_ends_progress_line(self): def test_download_failure_ends_progress_line(self):
from rich.console import Console
class Response(BytesIO): class Response(BytesIO):
headers = {'Content-Length': '10'} headers = {'Content-Length': '10'}
@@ -201,13 +209,20 @@ class BundleTests(unittest.TestCase):
terminal = StringIO() terminal = StringIO()
terminal.isatty = lambda: True terminal.isatty = lambda: True
with patch.object(bundle.sys, 'stderr', terminal), \ with patch.dict('os.environ', {'TERM': 'xterm-256color'}), \
patch.object(bundle.sys, 'stderr', terminal), \
patch('rich.console.Console', side_effect=lambda **kwargs:
Console(**kwargs, force_terminal=True,
force_interactive=True, legacy_windows=False,
color_system='standard', width=120)), \
patch.object(bundle, 'urlopen', return_value=Response()), \ patch.object(bundle, 'urlopen', return_value=Response()), \
self.assertLogs(bundle.logger, level='INFO') as captured: self.assertLogs(bundle.logger, level='INFO') as captured:
with self.assertRaises(OSError): with self.assertRaises(OSError):
bundle._copy_remote('https://farm.example/a', BytesIO(), 10) bundle._copy_remote('https://farm.example/a', BytesIO(), 10)
self.assertTrue(terminal.getvalue().endswith('\n')) raw = terminal.getvalue()
self.assertNotIn('100.0%', terminal.getvalue()) progress = re.sub(r'\x1b\[[0-9;?]*[a-zA-Z]', '', raw)
self.assertTrue(progress.endswith('\n'), repr(raw))
self.assertNotIn('100.0%', progress)
self.assertNotIn('下载完成', '\n'.join(captured.output)) self.assertNotIn('下载完成', '\n'.join(captured.output))
def test_progress_display_failure_does_not_abort_download(self): def test_progress_display_failure_does_not_abort_download(self):