Skip to content

Commit

Permalink
📄 Move and rename stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
asim-shrestha committed Oct 20, 2024
1 parent d373e00 commit 096398b
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 33 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ Separately, there are specific `tags` that can be used further filter test inten
```python
import asyncio
from playwright.async_api import BrowserContext
from bananalyzer.data.schemas import Example
from bananalyzer.runner.agent_runner import AgentResult, AgentRunner
from bananalyzer import AgentResult, AgentRunner, Example


class NullAgentRunner(AgentRunner):
Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bananalyzer.__version import VERSION
from bananalyzer.data.examples import get_all_examples
from bananalyzer.data.schemas import Example, ExampleType
from bananalyzer.data.example_fetching import get_all_examples
from bananalyzer.data.example_schemas import ExampleType, Example
from bananalyzer.runner.agent_runner import AgentRunner, AgentResult
from bananalyzer.runner.evals import check_match, AllowedJSON

Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from urllib.parse import urlparse

from bananalyzer import AgentRunner
from bananalyzer.data.banana_seeds import download_har, download_mhtml
from bananalyzer.data.examples import (
from bananalyzer.data.example_fetching import (
download_examples,
get_examples_path,
get_test_examples,
get_training_examples,
)
from bananalyzer.data.example_s3 import download_har, download_mhtml
from bananalyzer.runner.generator import PytestTestGenerator
from bananalyzer.runner.runner import run_tests
from bananalyzer.schema import AgentRunnerClass, Args, PytestArgs, XDistArgs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
from typing import Dict, Any

from bananalyzer.data.schemas import SchemaName
from bananalyzer.data.examples import get_examples_path
from bananalyzer.data.example_fetching import get_examples_path

"""
This file maps a schema_name to a JSON schema or goal string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pathlib import Path
from typing import List, Optional

from bananalyzer.data.banana_seeds import download_examples_from_s3
from bananalyzer.data.schemas import Example
from bananalyzer.data.example_s3 import download_examples_from_s3
from bananalyzer.data.example_schemas import Example

local_examples_path: Path = Path(__file__).resolve().parent.parent.parent / "static"
downloaded_examples_path = Path.home() / ".bananalyzer_data"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def handle_json_match(self, result: AllowedJSON, field: Optional[str]) -> None:

class Example(BaseModel):
id: str
url: str | None
url: str
resource_path: Optional[str] = Field(
description="Local path of a HAR, S3 URL of a HAR directory's tar.gz, or remote URL of MHTML",
default=None,
Expand All @@ -142,7 +142,7 @@ def get_static_url(self) -> str:

@property
def har_file_path(self) -> Path:
from bananalyzer.data.examples import get_examples_path
from bananalyzer.data.example_fetching import get_examples_path

if self.source != "har":
raise ValueError("This example is not a HAR file")
Expand All @@ -166,7 +166,7 @@ def har_file_path(self) -> Path:

@model_validator(mode="before")
def set_schema_and_goal(cls, values: Dict[str, Any]) -> Dict[str, Any]:
from bananalyzer.data.fetch_schemas import get_fetch_schema, get_goal
from bananalyzer.data.example_detail_schemas import get_fetch_schema, get_goal

if values.get("schema_") is None:
print(f"Warning: Schema not found for Example {values['id']}")
Expand Down
2 changes: 1 addition & 1 deletion bananalyzer/runner/agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from playwright.async_api import Page

from bananalyzer.data.schemas import Example
from bananalyzer import Example
from bananalyzer.runner.evals import AllowedJSON

AgentResult = AllowedJSON
Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/runner/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import urlparse

from bananalyzer import Example
from bananalyzer.data.schemas import Eval
from bananalyzer.data.example_schemas import Eval
from bananalyzer.runner.runner import BananalyzerTest
from bananalyzer.schema import MARKER_PREFIX

Expand Down Expand Up @@ -89,7 +89,7 @@ async def test_{eval_.type}(self, page, result) -> None:
"""

def _generate_class_name(self, example: Example) -> str:
domain = urlparse(example.url).hostname
domain: str | None = urlparse(example.url).hostname
if not domain:
raise ValueError(f"Invalid URL (no domain name): {example.url}")
domain = domain.replace(".", "_")
Expand Down
3 changes: 2 additions & 1 deletion bananalyzer/runner/null_agent_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio

from playwright.async_api import Page

from bananalyzer.data.schemas import Example
from bananalyzer import Example
from bananalyzer.runner.agent_runner import AgentResult, AgentRunner


Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from pydantic import BaseModel

from bananalyzer.data.schemas import Example
from bananalyzer.data.example_schemas import Example
from bananalyzer.hooks import BananalyzerPytestPlugin
from bananalyzer.junit import enrich_report
from bananalyzer.schema import AgentRunnerClass, PytestArgs, XDistArgs
Expand Down Expand Up @@ -43,7 +43,7 @@ def create_test_file(
import pytest_asyncio
import asyncio
from bananalyzer.data.examples import get_example_by_url
from bananalyzer.data.example_fetching import get_example_by_url
from playwright.async_api import async_playwright
@pytest.fixture(scope="session")
Expand Down
4 changes: 2 additions & 2 deletions bananalyzer/runner/website_responder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from abc import ABC, abstractmethod
from pathlib import Path

from bananalyzer.data.examples import get_examples_path
from bananalyzer.data.schemas import Example
from bananalyzer.data.example_fetching import get_examples_path
from bananalyzer.data.example_schemas import Example


class WebsiteResponder(ABC):
Expand Down
5 changes: 3 additions & 2 deletions bananalyzer/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pydantic import BaseModel, Field
from typing import List, Literal, Optional, Union

from bananalyzer.data.schemas import ExampleType
from pydantic import BaseModel, Field

from bananalyzer.data.example_schemas import ExampleType

XDistDistributionMode = Literal[
"load", "loadscope", "loadfile", "loadgroup", "worksteal", "no"
Expand Down
8 changes: 7 additions & 1 deletion static/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -37206,12 +37206,18 @@
"evals": [
{
"type": "json_match",
"expected": [
"options": [
{
"name": "Sunshine Valley Medical Center",
"address": "Sunshine Valley Hospital\n5678 Healing Lane\n3rd Floor\nMeadowbrook, CA 90210",
"phone": "555.123.4567",
"fax": "555.987.6543"
},
{
"name": "Sunshine Valley Medical Center",
"address": "Sunshine Valley Hospital, 5678 Healing Lane, 3rd Floor, Meadowbrook, CA 90210",
"phone": "555.123.4567",
"fax": "555.987.6543"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions static/re-sync-mhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from playwright.async_api import async_playwright

from bananalyzer.data.examples import get_all_examples
from bananalyzer.data.schemas import Example
from bananalyzer.data.example_fetching import get_all_examples
from bananalyzer.data.example_schemas import Example

"""
Test script to re-load websites and save them as MHTML files.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_example_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from _pytest.outcomes import Failed
from pytest_mock import MockFixture

from bananalyzer.data.schemas import Eval, Example
from bananalyzer.data.example_schemas import Eval, Example
from bananalyzer.runner.evals import format_new_lines


Expand Down
8 changes: 4 additions & 4 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import pytest
from pytest_mock import MockFixture

from bananalyzer.data.banana_seeds import download_har
from bananalyzer.data.examples import (
from bananalyzer.data.example_detail_schemas import get_fetch_schema, get_goal
from bananalyzer.data.example_fetching import (
download_examples,
downloaded_examples_path,
get_all_examples,
Expand All @@ -22,8 +22,8 @@
load_examples_at_path,
local_examples_path,
)
from bananalyzer.data.fetch_schemas import get_fetch_schema, get_goal
from bananalyzer.data.schemas import Example
from bananalyzer.data.example_s3 import download_har
from bananalyzer.data.example_schemas import Example


def test_load_examples_at_path_success(mocker: MockFixture) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from bananalyzer import Example
from bananalyzer.data.schemas import Eval
from bananalyzer.data.example_schemas import Eval
from bananalyzer.runner.generator import PytestTestGenerator


Expand Down
2 changes: 1 addition & 1 deletion tests/test_website_responder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from pytest_mock import MockFixture

from bananalyzer.data.schemas import Example
from bananalyzer.data.example_schemas import Example
from bananalyzer.runner.website_responder import (
HostedWebsiteResponder,
StaticFileResponder,
Expand Down

0 comments on commit 096398b

Please sign in to comment.