mirror of
https://github.com/Shu-Ying/main_plugin_farm.git
synced 2026-11-02 18:50:08 +08:00
fixed # 修复CI问题
This commit is contained in:
@@ -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'}
|
||||||
|
|
||||||
@@ -202,6 +210,10 @@ 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.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):
|
||||||
|
|||||||
Reference in New Issue
Block a user