Skip to content

Commit

Permalink
Fixup ruff config and inclusions (#495)
Browse files Browse the repository at this point in the history
* add tests to ruff for core

* fmt

* lint

* lint fixes

* fixup more dirs

* dont include non python

* lint fixes

* lint fixes

* fix dir name

* dont relative include
  • Loading branch information
jackgerrits authored Sep 13, 2024
1 parent e25bd2c commit 306541e
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 290 deletions.
3 changes: 1 addition & 2 deletions python/packages/agbench/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ agbench = "agbench.cli:main"
extend = "../../pyproject.toml"
exclude = ["build", "dist", "page_script.js", "src/agbench/res/Dockerfile", "src/agbench/template/global_init.sh"]
include = [
"src/**",
"examples/*.py",
"src/**"
]

[tool.pyright]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"from dataclasses import dataclass\n",
"\n",
"from autogen_core.application import SingleThreadedAgentRuntime\n",
"from autogen_core.base import AgentRuntime, AgentId, MessageContext\n",
"from autogen_core.base import AgentId, AgentRuntime, MessageContext\n",
"from autogen_core.components import ClosureAgent, DefaultSubscription, DefaultTopicId"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"from typing import Any\n",
"\n",
"from autogen_core.application import SingleThreadedAgentRuntime\n",
"from autogen_core.components import RoutedAgent, message_handler, DefaultSubscription, DefaultTopicId\n",
"from autogen_core.base import AgentId, MessageContext\n",
"from autogen_core.base.intervention import DefaultInterventionHandler"
"from autogen_core.base.intervention import DefaultInterventionHandler\n",
"from autogen_core.components import DefaultSubscription, DefaultTopicId, RoutedAgent, message_handler"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion python/packages/autogen-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dev-dependencies = [
[tool.ruff]
extend = "../../pyproject.toml"
exclude = ["build", "dist", "src/autogen_core/application/protos"]
include = ["src/**", "samples/*.py", "docs/**/*.ipynb"]
include = ["src/**", "samples/*.py", "docs/**/*.ipynb", "tests/**"]

[tool.pyright]
extend = "../../pyproject.toml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import os
import sys
import tempfile
from anyio import open_file

import pytest
from azure.identity import DefaultAzureCredential
from autogen_core.components.code_executor import CodeBlock, AzureContainerCodeExecutor
from anyio import open_file
from autogen_core.base import CancellationToken
from autogen_core.components.code_executor import AzureContainerCodeExecutor, CodeBlock
from azure.identity import DefaultAzureCredential

UNIX_SHELLS = ["bash", "sh", "shell"]
WINDOWS_SHELLS = ["ps1", "pwsh", "powershell"]
Expand All @@ -20,6 +20,7 @@

POOL_ENDPOINT = os.getenv(ENVIRON_KEY_AZURE_POOL_ENDPOINT)


@pytest.mark.skipif(
not POOL_ENDPOINT,
reason="do not run if pool endpoint is not defined",
Expand All @@ -41,11 +42,7 @@ async def test_execute_code() -> None:
CodeBlock(code="a = 100 + 100; print(a)", language="python"),
]
code_result = await executor.execute_code_blocks(code_blocks, cancellation_token)
assert (
code_result.exit_code == 0
and "hello world!" in code_result.output
and "200" in code_result.output
)
assert code_result.exit_code == 0 and "hello world!" in code_result.output and "200" in code_result.output

# Test bash script.
if sys.platform not in ["win32"]:
Expand All @@ -58,11 +55,8 @@ async def test_execute_code() -> None:
file_lines = ["import sys", "print('hello world!')", "a = 100 + 100", "print(a)"]
code_blocks = [CodeBlock(code="\n".join(file_lines), language="python")]
code_result = await executor.execute_code_blocks(code_blocks, cancellation_token)
assert (
code_result.exit_code == 0
and "hello world!" in code_result.output
and "200" in code_result.output
)
assert code_result.exit_code == 0 and "hello world!" in code_result.output and "200" in code_result.output


@pytest.mark.skipif(
not POOL_ENDPOINT,
Expand All @@ -72,11 +66,14 @@ async def test_execute_code() -> None:
async def test_azure_container_code_executor_timeout() -> None:
assert POOL_ENDPOINT is not None
cancellation_token = CancellationToken()
executor = AzureContainerCodeExecutor(pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), timeout=1)
executor = AzureContainerCodeExecutor(
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), timeout=1
)
code_blocks = [CodeBlock(code="import time; time.sleep(10); print('hello world!')", language="python")]
with pytest.raises(asyncio.TimeoutError):
await executor.execute_code_blocks(code_blocks, cancellation_token)


@pytest.mark.skipif(
not POOL_ENDPOINT,
reason="do not run if pool endpoint is not defined",
Expand Down Expand Up @@ -111,7 +108,9 @@ async def test_upload_files() -> None:
cancellation_token = CancellationToken()

with tempfile.TemporaryDirectory() as temp_dir:
executor = AzureContainerCodeExecutor(pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), work_dir=temp_dir)
executor = AzureContainerCodeExecutor(
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), work_dir=temp_dir
)

async with await open_file(os.path.join(temp_dir, test_file_1), "w") as f:
await f.write(test_file_1_contents)
Expand All @@ -124,12 +123,17 @@ async def test_upload_files() -> None:
assert test_file_1 in file_list
assert test_file_2 in file_list

code_blocks = [CodeBlock(code=f"""
code_blocks = [
CodeBlock(
code=f"""
with open("{test_file_1}") as f:
print(f.read())
with open("{test_file_2}") as f:
print(f.read())
""", language="python")]
""",
language="python",
)
]
code_result = await executor.execute_code_blocks(code_blocks, cancellation_token)
assert code_result.exit_code == 0
assert test_file_1_contents in code_result.output
Expand All @@ -150,15 +154,20 @@ async def test_download_files() -> None:
cancellation_token = CancellationToken()

with tempfile.TemporaryDirectory() as temp_dir:
executor = AzureContainerCodeExecutor(pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), work_dir=temp_dir)
executor = AzureContainerCodeExecutor(
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), work_dir=temp_dir
)

code_blocks = [
CodeBlock(code=f"""
CodeBlock(
code=f"""
with open("{test_file_1}", "w") as f:
f.write("{test_file_1_contents}")
with open("{test_file_2}", "w") as f:
f.write("{test_file_2_contents}")
""", language="python"),
""",
language="python",
),
]
code_result = await executor.execute_code_blocks(code_blocks, cancellation_token)
assert code_result.exit_code == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import pytest
import pytest_asyncio
from aiofiles import open
from autogen_core.base import CancellationToken
from autogen_core.components.code_executor import CodeBlock, DockerCommandLineCodeExecutor, LocalCommandLineCodeExecutor

from aiofiles import open

def docker_tests_enabled() -> bool:
if os.environ.get("SKIP_DOCKER", "unset").lower() == "true":
Expand Down Expand Up @@ -190,5 +190,5 @@ async def test_docker_commandline_code_executor_start_stop_context_manager() ->
pytest.skip("Docker tests are disabled")

with tempfile.TemporaryDirectory() as temp_dir:
async with DockerCommandLineCodeExecutor(work_dir=temp_dir) as exec:
async with DockerCommandLineCodeExecutor(work_dir=temp_dir) as _exec:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


def test_extract_markdown_code_blocks() -> None:

text = """# This is a markdown text
```python
print("Hello World")
Expand All @@ -15,7 +14,6 @@ def test_extract_markdown_code_blocks() -> None:
assert code_blocks[0].language == "python"
assert code_blocks[0].code == 'print("Hello World")\n'


text = """More markdown text
```python
print("Hello World")
Expand Down
Loading

0 comments on commit 306541e

Please sign in to comment.