modified: pyproject.toml modified: requirements.txt modified: swarms/models/kosmos_two.py deleted: swarms/models/multion.py modified: swarms/utils/code_interpreter.py new file: tests/__init__.py deleted: tests/models/test_multion.py modified: tests/models/test_ssd_1b.py modified: tests/utils/test_class_args_wrapper.py modified: tests/utils/test_subprocess_code_interpreter.pypull/334/head
parent
1e0d6c103e
commit
33e0f9f110
@ -0,0 +1,397 @@
|
|||||||
|
============================= test session starts ==============================
|
||||||
|
platform linux -- Python 3.10.12, pytest-7.4.2, pluggy-1.3.0
|
||||||
|
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
|
||||||
|
rootdir: /home/v/vswarms
|
||||||
|
plugins: benchmark-4.0.0, anyio-3.7.1
|
||||||
|
collected 812 items / 11 errors
|
||||||
|
|
||||||
|
==================================== ERRORS ====================================
|
||||||
|
_________________ ERROR collecting tests/memory/test_pq_db.py __________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/memory/test_pq_db.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/memory/test_pq_db.py:6: in <module>
|
||||||
|
from swarms.memory.pg import PostgresDB
|
||||||
|
../.local/lib/python3.10/site-packages/swarms/memory/pg.py:6: in <module>
|
||||||
|
from swarms.memory.base import BaseVectorStore
|
||||||
|
E ModuleNotFoundError: No module named 'swarms.memory.base'
|
||||||
|
________________ ERROR collecting tests/memory/test_weaviate.py ________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/memory/test_weaviate.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/memory/test_weaviate.py:3: in <module>
|
||||||
|
from swarms.memory import WeaviateDB
|
||||||
|
E ImportError: cannot import name 'WeaviateDB' from 'swarms.memory' (/home/v/.local/lib/python3.10/site-packages/swarms/memory/__init__.py)
|
||||||
|
________________ ERROR collecting tests/models/test_kosmos2.py _________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/models/test_kosmos2.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/models/test_kosmos2.py:4: in <module>
|
||||||
|
from swarms.models.kosmos2 import Kosmos2, Detections
|
||||||
|
../.local/lib/python3.10/site-packages/swarms/models/kosmos2.py:4: in <module>
|
||||||
|
from pydantic import BaseModel, model_validator, validator
|
||||||
|
E ImportError: cannot import name 'model_validator' from 'pydantic' (/home/v/.local/lib/python3.10/site-packages/pydantic/__init__.cpython-310-x86_64-linux-gnu.so)
|
||||||
|
________________ ERROR collecting tests/models/test_multion.py _________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/models/test_multion.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
../.local/lib/python3.10/site-packages/swarms/models/multion.py:5: in <module>
|
||||||
|
import multion
|
||||||
|
E ModuleNotFoundError: No module named 'multion'
|
||||||
|
|
||||||
|
During handling of the above exception, another exception occurred:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/models/test_multion.py:3: in <module>
|
||||||
|
from swarms.models.multion import MultiOn
|
||||||
|
../.local/lib/python3.10/site-packages/swarms/models/multion.py:8: in <module>
|
||||||
|
raise ImportError(
|
||||||
|
E ImportError: Cannot import multion, please install 'pip install'
|
||||||
|
_________________ ERROR collecting tests/models/test_ssd_1b.py _________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/models/test_ssd_1b.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/models/test_ssd_1b.py:2: in <module>
|
||||||
|
from swarms.models.ssd_1b import SSD1B
|
||||||
|
../.local/lib/python3.10/site-packages/swarms/models/ssd_1b.py:10: in <module>
|
||||||
|
from diffusers import StableDiffusionXLPipeline
|
||||||
|
E ImportError: cannot import name 'StableDiffusionXLPipeline' from 'diffusers' (/home/v/.local/lib/python3.10/site-packages/diffusers/__init__.py)
|
||||||
|
________________ ERROR collecting tests/models/test_whisperx.py ________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/models/test_whisperx.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/models/test_whisperx.py:7: in <module>
|
||||||
|
import whisperx
|
||||||
|
E ModuleNotFoundError: No module named 'whisperx'
|
||||||
|
______________ ERROR collecting tests/structs/test_autoscaler.py _______________
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
|
||||||
|
result: Optional[TResult] = func()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
|
||||||
|
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:531: in collect
|
||||||
|
self._inject_setup_module_fixture()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
|
||||||
|
self.obj, ("setUpModule", "setup_module")
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:310: in obj
|
||||||
|
self._obj = obj = self._getobj()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:528: in _getobj
|
||||||
|
return self._importtestmodule()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:617: in _importtestmodule
|
||||||
|
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/pathlib.py:567: in import_path
|
||||||
|
importlib.import_module(module_name)
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
<frozen importlib._bootstrap>:1050: in _gcd_import
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:1027: in _find_and_load
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:688: in _load_unlocked
|
||||||
|
???
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
|
||||||
|
exec(co, module.__dict__)
|
||||||
|
tests/structs/test_autoscaler.py:15: in <module>
|
||||||
|
llm = OpenAIChat(
|
||||||
|
../.local/lib/python3.10/site-packages/langchain/load/serializable.py:97: in __init__
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
pydantic/main.py:341: in pydantic.main.BaseModel.__init__
|
||||||
|
???
|
||||||
|
E pydantic.error_wrappers.ValidationError: 1 validation error for OpenAIChat
|
||||||
|
E __root__
|
||||||
|
E Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error)
|
||||||
|
_______________ ERROR collecting tests/swarms/test_groupchat.py ________________
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
|
||||||
|
result: Optional[TResult] = func()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
|
||||||
|
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:531: in collect
|
||||||
|
self._inject_setup_module_fixture()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
|
||||||
|
self.obj, ("setUpModule", "setup_module")
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:310: in obj
|
||||||
|
self._obj = obj = self._getobj()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:528: in _getobj
|
||||||
|
return self._importtestmodule()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:617: in _importtestmodule
|
||||||
|
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/pathlib.py:567: in import_path
|
||||||
|
importlib.import_module(module_name)
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
<frozen importlib._bootstrap>:1050: in _gcd_import
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:1027: in _find_and_load
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:688: in _load_unlocked
|
||||||
|
???
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
|
||||||
|
exec(co, module.__dict__)
|
||||||
|
tests/swarms/test_groupchat.py:9: in <module>
|
||||||
|
llm2 = Anthropic()
|
||||||
|
../.local/lib/python3.10/site-packages/langchain/load/serializable.py:97: in __init__
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
pydantic/main.py:341: in pydantic.main.BaseModel.__init__
|
||||||
|
???
|
||||||
|
E pydantic.error_wrappers.ValidationError: 1 validation error for Anthropic
|
||||||
|
E __root__
|
||||||
|
E Did not find anthropic_api_key, please add an environment variable `ANTHROPIC_API_KEY` which contains it, or pass `anthropic_api_key` as a named parameter. (type=value_error)
|
||||||
|
____________ ERROR collecting tests/telemetry/test_posthog_utils.py ____________
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
|
||||||
|
result: Optional[TResult] = func()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
|
||||||
|
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:531: in collect
|
||||||
|
self._inject_setup_module_fixture()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
|
||||||
|
self.obj, ("setUpModule", "setup_module")
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:310: in obj
|
||||||
|
self._obj = obj = self._getobj()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:528: in _getobj
|
||||||
|
return self._importtestmodule()
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/python.py:617: in _importtestmodule
|
||||||
|
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/pathlib.py:567: in import_path
|
||||||
|
importlib.import_module(module_name)
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
<frozen importlib._bootstrap>:1050: in _gcd_import
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:1027: in _find_and_load
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
|
||||||
|
???
|
||||||
|
<frozen importlib._bootstrap>:688: in _load_unlocked
|
||||||
|
???
|
||||||
|
../.local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
|
||||||
|
exec(co, module.__dict__)
|
||||||
|
tests/telemetry/test_posthog_utils.py:5: in <module>
|
||||||
|
from swarms.telemetry.posthog_utils import (
|
||||||
|
../.local/lib/python3.10/site-packages/swarms/telemetry/posthog_utils.py:15: in <module>
|
||||||
|
posthog = Posthog(api_key, host=host)
|
||||||
|
../.local/lib/python3.10/site-packages/posthog/client.py:58: in __init__
|
||||||
|
require("api_key", self.api_key, string_types)
|
||||||
|
../.local/lib/python3.10/site-packages/posthog/client.py:751: in require
|
||||||
|
raise AssertionError(msg)
|
||||||
|
E AssertionError: api_key must have (<class 'str'>,), got: None
|
||||||
|
__________________ ERROR collecting tests/tools/test_base.py ___________________
|
||||||
|
import file mismatch:
|
||||||
|
imported module 'test_base' has this __file__ attribute:
|
||||||
|
/home/v/vswarms/tests/structs/test_base.py
|
||||||
|
which is not the same as the test file we want to collect:
|
||||||
|
/home/v/vswarms/tests/tools/test_base.py
|
||||||
|
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
|
||||||
|
_________________ ERROR collecting tests/utils/test_device.py __________________
|
||||||
|
ImportError while importing test module '/home/v/vswarms/tests/utils/test_device.py'.
|
||||||
|
Hint: make sure your test modules/packages have valid Python names.
|
||||||
|
Traceback:
|
||||||
|
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
|
||||||
|
return _bootstrap._gcd_import(name[level:], package, level)
|
||||||
|
tests/utils/test_device.py:4: in <module>
|
||||||
|
from swarms.utils.device_checker_cuda import check_device
|
||||||
|
E ModuleNotFoundError: No module named 'swarms.utils.device_checker_cuda'
|
||||||
|
=============================== warnings summary ===============================
|
||||||
|
../.local/lib/python3.10/site-packages/PyPDF2/__init__.py:21
|
||||||
|
/home/v/.local/lib/python3.10/site-packages/PyPDF2/__init__.py:21: DeprecationWarning: PyPDF2 is deprecated. Please move to the pypdf library instead.
|
||||||
|
warnings.warn(
|
||||||
|
|
||||||
|
../.local/lib/python3.10/site-packages/tensorflow/__init__.py:29
|
||||||
|
/home/v/.local/lib/python3.10/site-packages/tensorflow/__init__.py:29: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
|
||||||
|
import distutils as _distutils
|
||||||
|
|
||||||
|
../.local/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:35
|
||||||
|
/home/v/.local/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:35: DeprecationWarning: ml_dtypes.float8_e4m3b11 is deprecated. Use ml_dtypes.float8_e4m3b11fnuz
|
||||||
|
from tensorflow.tsl.python.lib.core import pywrap_ml_dtypes
|
||||||
|
|
||||||
|
../.local/lib/python3.10/site-packages/timm/models/layers/__init__.py:49
|
||||||
|
/home/v/.local/lib/python3.10/site-packages/timm/models/layers/__init__.py:49: DeprecationWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
|
||||||
|
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", DeprecationWarning)
|
||||||
|
|
||||||
|
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
|
||||||
|
=========================== short test summary info ============================
|
||||||
|
ERROR tests/memory/test_pq_db.py
|
||||||
|
ERROR tests/memory/test_weaviate.py
|
||||||
|
ERROR tests/models/test_kosmos2.py
|
||||||
|
ERROR tests/models/test_multion.py
|
||||||
|
ERROR tests/models/test_ssd_1b.py
|
||||||
|
ERROR tests/models/test_whisperx.py
|
||||||
|
ERROR tests/structs/test_autoscaler.py - pydantic.error_wrappers.ValidationEr...
|
||||||
|
ERROR tests/swarms/test_groupchat.py - pydantic.error_wrappers.ValidationErro...
|
||||||
|
ERROR tests/telemetry/test_posthog_utils.py - AssertionError: api_key must ha...
|
||||||
|
ERROR tests/tools/test_base.py
|
||||||
|
ERROR tests/utils/test_device.py
|
||||||
|
!!!!!!!!!!!!!!!!!!! Interrupted: 11 errors during collection !!!!!!!!!!!!!!!!!!!
|
||||||
|
======================== 4 warnings, 11 errors in 6.22s ========================
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 421, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_2d_kernel", __class__._2d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 262, in __enter__
|
||||||
|
self.acquire()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 219, in acquire
|
||||||
|
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Attempting to acquire lock %s on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_2d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 421, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_2d_kernel", __class__._2d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 262, in __enter__
|
||||||
|
self.acquire()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 222, in acquire
|
||||||
|
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Lock %s acquired on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_2d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 421, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_2d_kernel", __class__._2d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 278, in __exit__
|
||||||
|
self.release()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 251, in release
|
||||||
|
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Attempting to release lock %s on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_2d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 421, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_2d_kernel", __class__._2d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 278, in __exit__
|
||||||
|
self.release()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 254, in release
|
||||||
|
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Lock %s released on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_2d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 422, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_4d_kernel", __class__._4d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 262, in __enter__
|
||||||
|
self.acquire()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 219, in acquire
|
||||||
|
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Attempting to acquire lock %s on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_4d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 422, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_4d_kernel", __class__._4d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 262, in __enter__
|
||||||
|
self.acquire()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 222, in acquire
|
||||||
|
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Lock %s acquired on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_4d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 422, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_4d_kernel", __class__._4d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 278, in __exit__
|
||||||
|
self.release()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 251, in release
|
||||||
|
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Attempting to release lock %s on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_4d_kernel.pickle.lock')
|
||||||
|
--- Logging error ---
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
|
||||||
|
stream.write(msg + self.terminator)
|
||||||
|
ValueError: I/O operation on closed file.
|
||||||
|
Call stack:
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 444, in matmul_ext_update_autotune_table
|
||||||
|
fp16_matmul._update_autotune_table()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 422, in _update_autotune_table
|
||||||
|
TritonMatmul._update_autotune_table(__class__.__name__ + "_4d_kernel", __class__._4d_kernel)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 150, in _update_autotune_table
|
||||||
|
cache_manager.put(autotune_table)
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 66, in put
|
||||||
|
with FileLock(self.lock_path):
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 278, in __exit__
|
||||||
|
self.release()
|
||||||
|
File "/home/v/.local/lib/python3.10/site-packages/filelock/_api.py", line 254, in release
|
||||||
|
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
||||||
|
Message: 'Lock %s released on %s'
|
||||||
|
Arguments: (140110562667408, '/home/v/.triton/autotune/Fp16Matmul_4d_kernel.pickle.lock')
|
@ -1,60 +0,0 @@
|
|||||||
from swarms.models.base_llm import AbstractLLM
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
import multion
|
|
||||||
|
|
||||||
except ImportError:
|
|
||||||
raise ImportError(
|
|
||||||
"Cannot import multion, please install 'pip install'"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class MultiOn(AbstractLLM):
|
|
||||||
"""
|
|
||||||
MultiOn is a wrapper for the Multion API.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
**kwargs:
|
|
||||||
|
|
||||||
Methods:
|
|
||||||
run(self, task: str, url: str, *args, **kwargs)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
>>> from swarms.models.multion import MultiOn
|
|
||||||
>>> multion = MultiOn()
|
|
||||||
>>> multion.run("Order chicken tendies", "https://www.google.com/")
|
|
||||||
"Order chicken tendies. https://www.google.com/"
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super(MultiOn, self).__init__(**kwargs)
|
|
||||||
|
|
||||||
def run(self, task: str, url: str, *args, **kwargs) -> str:
|
|
||||||
"""Run the multion model
|
|
||||||
|
|
||||||
Args:
|
|
||||||
task (str): _description_
|
|
||||||
url (str): _description_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: _description_
|
|
||||||
"""
|
|
||||||
response = multion.new_session({"input": task, "url": url})
|
|
||||||
return response
|
|
||||||
|
|
||||||
def generate_summary(
|
|
||||||
self, task: str, url: str, *args, **kwargs
|
|
||||||
) -> str:
|
|
||||||
"""Generate a summary from the multion model
|
|
||||||
|
|
||||||
Args:
|
|
||||||
task (str): _description_
|
|
||||||
url (str): _description_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: _description_
|
|
||||||
"""
|
|
||||||
response = multion.new_session({"input": task, "url": url})
|
|
||||||
return response
|
|
@ -1,54 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
from swarms.models.multion import MultiOn
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def multion_instance():
|
|
||||||
return MultiOn()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_multion():
|
|
||||||
return Mock()
|
|
||||||
|
|
||||||
|
|
||||||
def test_multion_import():
|
|
||||||
with pytest.raises(ImportError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def test_multion_init():
|
|
||||||
multion = MultiOn()
|
|
||||||
assert isinstance(multion, MultiOn)
|
|
||||||
|
|
||||||
|
|
||||||
def test_multion_run_with_valid_input(multion_instance, mock_multion):
|
|
||||||
task = "Order chicken tendies"
|
|
||||||
url = "https://www.google.com/"
|
|
||||||
mock_multion.new_session.return_value = (
|
|
||||||
"Order chicken tendies. https://www.google.com/"
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch("swarms.models.multion.multion", mock_multion):
|
|
||||||
response = multion_instance.run(task, url)
|
|
||||||
|
|
||||||
assert (
|
|
||||||
response == "Order chicken tendies. https://www.google.com/"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_multion_run_with_invalid_input(
|
|
||||||
multion_instance, mock_multion
|
|
||||||
):
|
|
||||||
task = ""
|
|
||||||
url = "https://www.google.com/"
|
|
||||||
mock_multion.new_session.return_value = None
|
|
||||||
|
|
||||||
with patch("swarms.models.multion.multion", mock_multion):
|
|
||||||
response = multion_instance.run(task, url)
|
|
||||||
|
|
||||||
assert response is None
|
|
||||||
|
|
||||||
|
|
||||||
# Add more test cases to cover different scenarios, edge cases, and error handling as needed.
|
|
@ -1,307 +1,80 @@
|
|||||||
|
import pytest
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
import time
|
import queue
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from swarms.utils.code_interpreter import (
|
from swarms.utils.code_interpreter import (
|
||||||
BaseCodeInterpreter,
|
|
||||||
SubprocessCodeInterpreter,
|
SubprocessCodeInterpreter,
|
||||||
)
|
) # Adjust the import according to your project structure
|
||||||
|
|
||||||
|
|
||||||
|
# Fixture for the SubprocessCodeInterpreter instance
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def subprocess_code_interpreter():
|
def interpreter():
|
||||||
interpreter = SubprocessCodeInterpreter()
|
return SubprocessCodeInterpreter()
|
||||||
interpreter.start_cmd = "python -c"
|
|
||||||
yield interpreter
|
|
||||||
interpreter.terminate()
|
|
||||||
|
|
||||||
|
|
||||||
def test_base_code_interpreter_init():
|
|
||||||
interpreter = BaseCodeInterpreter()
|
|
||||||
assert isinstance(interpreter, BaseCodeInterpreter)
|
|
||||||
|
|
||||||
|
|
||||||
def test_base_code_interpreter_run_not_implemented():
|
# Test for correct initialization
|
||||||
interpreter = BaseCodeInterpreter()
|
def test_initialization(interpreter):
|
||||||
with pytest.raises(NotImplementedError):
|
assert interpreter.start_cmd == ""
|
||||||
interpreter.run("code")
|
assert interpreter.process is None
|
||||||
|
assert not interpreter.debug_mode
|
||||||
|
assert isinstance(interpreter.output_queue, queue.Queue)
|
||||||
|
assert isinstance(interpreter.done, threading.Event)
|
||||||
|
|
||||||
|
|
||||||
def test_base_code_interpreter_terminate_not_implemented():
|
# Test for starting and terminating process
|
||||||
interpreter = BaseCodeInterpreter()
|
def test_start_and_terminate_process(interpreter):
|
||||||
with pytest.raises(NotImplementedError):
|
interpreter.start_cmd = "echo Hello"
|
||||||
|
interpreter.start_process()
|
||||||
|
assert isinstance(interpreter.process, subprocess.Popen)
|
||||||
interpreter.terminate()
|
interpreter.terminate()
|
||||||
|
assert (
|
||||||
|
interpreter.process.poll() is not None
|
||||||
|
) # Process should be terminated
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_init(
|
# Test preprocess_code method
|
||||||
subprocess_code_interpreter,
|
def test_preprocess_code(interpreter):
|
||||||
):
|
code = "print('Hello, World!')"
|
||||||
assert isinstance(
|
processed_code = interpreter.preprocess_code(code)
|
||||||
subprocess_code_interpreter, SubprocessCodeInterpreter
|
# Add assertions based on expected behavior of preprocess_code
|
||||||
)
|
assert processed_code == code # Example assertion
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_start_process(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
subprocess_code_interpreter.start_process()
|
|
||||||
assert subprocess_code_interpreter.process is not None
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_terminate(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
subprocess_code_interpreter.start_process()
|
|
||||||
subprocess_code_interpreter.terminate()
|
|
||||||
assert subprocess_code_interpreter.process.poll() is not None
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_success(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"Hello, World!" in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_error(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
code = 'print("Hello, World")\nraise ValueError("Error!")'
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"Error!" in output.get("output", "") for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_keyboard_interrupt(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
code = (
|
|
||||||
'import time\ntime.sleep(2)\nprint("Hello, World")\nraise'
|
|
||||||
" KeyboardInterrupt"
|
|
||||||
)
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"KeyboardInterrupt" in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_max_retries(
|
|
||||||
subprocess_code_interpreter, monkeypatch
|
|
||||||
):
|
|
||||||
def mock_subprocess_popen(*args, **kwargs):
|
|
||||||
raise subprocess.CalledProcessError(1, "mocked_cmd")
|
|
||||||
|
|
||||||
monkeypatch.setattr(subprocess, "Popen", mock_subprocess_popen)
|
|
||||||
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"Maximum retries reached. Could not execute code."
|
|
||||||
in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_retry_on_error(
|
|
||||||
subprocess_code_interpreter, monkeypatch
|
|
||||||
):
|
|
||||||
def mock_subprocess_popen(*args, **kwargs):
|
|
||||||
nonlocal popen_count
|
|
||||||
if popen_count == 0:
|
|
||||||
popen_count += 1
|
|
||||||
raise subprocess.CalledProcessError(1, "mocked_cmd")
|
|
||||||
else:
|
|
||||||
return subprocess.Popen(
|
|
||||||
"echo 'Hello, World!'",
|
|
||||||
shell=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
)
|
|
||||||
|
|
||||||
monkeypatch.setattr(subprocess, "Popen", mock_subprocess_popen)
|
|
||||||
popen_count = 0
|
|
||||||
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"Hello, World!" in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Add more tests to cover other aspects of the code and edge cases as needed
|
|
||||||
|
|
||||||
# Import statements and fixtures from the previous code block
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_line_postprocessor(
|
# Test detect_active_line method
|
||||||
subprocess_code_interpreter,
|
def test_detect_active_line(interpreter):
|
||||||
):
|
line = "Some line of code"
|
||||||
line = "This is a test line"
|
|
||||||
processed_line = subprocess_code_interpreter.line_postprocessor(
|
|
||||||
line
|
|
||||||
)
|
|
||||||
assert (
|
assert (
|
||||||
processed_line == line
|
interpreter.detect_active_line(line) is None
|
||||||
) # No processing, should remain the same
|
) # Adjust assertion based on implementation
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_preprocess_code(
|
# Test detect_end_of_execution method
|
||||||
subprocess_code_interpreter,
|
def test_detect_end_of_execution(interpreter):
|
||||||
):
|
line = "End of execution line"
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
preprocessed_code = subprocess_code_interpreter.preprocess_code(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
assert (
|
assert (
|
||||||
preprocessed_code == code
|
interpreter.detect_end_of_execution(line) is None
|
||||||
) # No preprocessing, should remain the same
|
) # Adjust assertion based on implementation
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_detect_active_line(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
line = "Active line: 5"
|
|
||||||
active_line = subprocess_code_interpreter.detect_active_line(line)
|
|
||||||
assert active_line == 5
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_detect_end_of_execution(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
line = "Execution completed."
|
|
||||||
end_of_execution = (
|
|
||||||
subprocess_code_interpreter.detect_end_of_execution(line)
|
|
||||||
)
|
|
||||||
assert end_of_execution is True
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_debug_mode(
|
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
subprocess_code_interpreter.debug_mode = True
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
list(subprocess_code_interpreter.run(code))
|
|
||||||
captured = capsys.readouterr()
|
|
||||||
assert "Running code:\n" in captured.out
|
|
||||||
assert "Received output line:\n" in captured.out
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_no_debug_mode(
|
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
subprocess_code_interpreter.debug_mode = False
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
list(subprocess_code_interpreter.run(code))
|
|
||||||
captured = capsys.readouterr()
|
|
||||||
assert "Running code:\n" not in captured.out
|
|
||||||
assert "Received output line:\n" not in captured.out
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_empty_output_queue(
|
# Test line_postprocessor method
|
||||||
subprocess_code_interpreter,
|
def test_line_postprocessor(interpreter):
|
||||||
):
|
line = "Some output line"
|
||||||
code = 'print("Hello, World!")'
|
assert (
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
interpreter.line_postprocessor(line) == line
|
||||||
assert not any("active_line" in output for output in result)
|
) # Adjust assertion based on implementation
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_handle_stream_output_stdout(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
line = "This is a test line"
|
|
||||||
subprocess_code_interpreter.handle_stream_output(
|
|
||||||
threading.current_thread(), False
|
|
||||||
)
|
|
||||||
subprocess_code_interpreter.process.stdout.write(line + "\n")
|
|
||||||
subprocess_code_interpreter.process.stdout.flush()
|
|
||||||
time.sleep(0.1)
|
|
||||||
output = subprocess_code_interpreter.output_queue.get()
|
|
||||||
assert output["output"] == line
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_handle_stream_output_stderr(
|
|
||||||
subprocess_code_interpreter,
|
|
||||||
):
|
|
||||||
line = "This is an error line"
|
|
||||||
subprocess_code_interpreter.handle_stream_output(
|
|
||||||
threading.current_thread(), True
|
|
||||||
)
|
|
||||||
subprocess_code_interpreter.process.stderr.write(line + "\n")
|
|
||||||
subprocess_code_interpreter.process.stderr.flush()
|
|
||||||
time.sleep(0.1)
|
|
||||||
output = subprocess_code_interpreter.output_queue.get()
|
|
||||||
assert output["output"] == line
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_preprocess_code(
|
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
subprocess_code_interpreter.preprocess_code = (
|
|
||||||
lambda x: x.upper()
|
|
||||||
) # Modify code in preprocess_code
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"Hello, World!" in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_exception(
|
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
code = 'print("Hello, World!")'
|
|
||||||
subprocess_code_interpreter.start_cmd = ( # Force an exception during subprocess creation
|
|
||||||
"nonexistent_command"
|
|
||||||
)
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"Maximum retries reached" in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_active_line(
|
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
code = "a = 5\nprint(a)" # Contains an active line
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(output.get("active_line") == 5 for output in result)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_end_of_execution(
|
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
code = ( # Simple code without active line marker
|
|
||||||
'print("Hello, World!")'
|
|
||||||
)
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(output.get("active_line") is None for output in result)
|
|
||||||
|
|
||||||
|
# Test handle_stream_output method
|
||||||
|
def test_handle_stream_output(interpreter, monkeypatch):
|
||||||
|
# This requires more complex setup, including monkeypatching and simulating stream output
|
||||||
|
# Example setup
|
||||||
|
def mock_readline():
|
||||||
|
yield "output line"
|
||||||
|
yield ""
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_multiple_lines(
|
monkeypatch.setattr("sys.stdout", mock_readline())
|
||||||
subprocess_code_interpreter, capsys
|
# More test code needed here to simulate and assert the behavior of handle_stream_output
|
||||||
):
|
|
||||||
code = "a = 5\nb = 10\nprint(a + b)"
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any("15" in output.get("output", "") for output in result)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subprocess_code_interpreter_run_with_unicode_characters(
|
# More tests needed for run method, error handling, and edge cases.
|
||||||
subprocess_code_interpreter, capsys
|
|
||||||
):
|
|
||||||
code = 'print("こんにちは、世界")' # Contains unicode characters
|
|
||||||
result = list(subprocess_code_interpreter.run(code))
|
|
||||||
assert any(
|
|
||||||
"こんにちは、世界" in output.get("output", "")
|
|
||||||
for output in result
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in new issue