Skip to content

Commit

Permalink
fix 94c61e6
Browse files Browse the repository at this point in the history
  • Loading branch information
ocrd committed Mar 6, 2024
1 parent 94c61e6 commit a593a9c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 45 deletions.
3 changes: 1 addition & 2 deletions ocrdmonitor/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
SubProcessOcrdBrowserFactory,
)
from ocrdmonitor import database
from ocrdmonitor.protocols import RemoteServer, Repositories
from ocrdmonitor.protocols import Repositories
from ocrdmonitor.server.settings import Settings
from ocrdmonitor.sshremote import SSHRemote

BrowserType = Type[SubProcessOcrdBrowser] | Type[DockerOcrdBrowser]
CreatingFactories: dict[str, Callable[[set[int]], OcrdBrowserFactory]] = {
Expand Down
1 change: 0 additions & 1 deletion ocrdmonitor/server/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from fastapi.responses import JSONResponse
from fastapi.templating import Jinja2Templates

from ocrdmonitor.processstatus import ProcessStatus
from ocrdmonitor.protocols import Environment, OcrdJob, Repositories

import httpx
Expand Down
9 changes: 0 additions & 9 deletions tests/ocrdmonitor/server/fixtures/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
from fastapi.testclient import TestClient

from ocrdbrowser import OcrdBrowserFactory
from ocrdmonitor.processstatus import ProcessStatus
from ocrdmonitor.protocols import (
BrowserProcessRepository,
BrowserRestoringFactory,
RemoteServer,
Repositories,
)
from ocrdmonitor.server.app import create_app
Expand All @@ -34,13 +32,6 @@
)


class RemoteDummy:
async def read_file(self, path: str) -> str:
return ""

async def process_status(self, process_group: int) -> list[ProcessStatus]:
return []


@dataclass
class DevEnvironment:
Expand Down
35 changes: 2 additions & 33 deletions tests/ocrdmonitor/server/test_job_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pytest
from pytest_httpx import HTTPXMock

from ocrdmonitor.processstatus import ProcessState, ProcessStatus
from ocrdmonitor.protocols import OcrdJob
from tests.ocrdmonitor.server import scraping
from tests.ocrdmonitor.server.fixtures.environment import Fixture
Expand Down Expand Up @@ -58,8 +57,6 @@ async def test__given_a_running_ocrd_job__the_job_endpoint_lists_it_with_resourc
repository_fixture: Fixture,
) -> None:
pid = 1234
expected_status = make_status(pid)
remote_stub = RemoteServerStub(expected_status)

async with fixture as env:
app = env.app
Expand All @@ -69,7 +66,7 @@ async def test__given_a_running_ocrd_job__the_job_endpoint_lists_it_with_resourc
response = app.get("/jobs/")

assert response.is_success
assert_lists_running_job(job, expected_status, response)
assert_lists_running_job(job, response)


@pytest.mark.asyncio
Expand Down Expand Up @@ -108,29 +105,6 @@ def non_mocked_hosts() -> list[str]:
return ["testserver"]


def make_status(pid: int) -> ProcessStatus:
expected_status = ProcessStatus(
pid=pid,
state=ProcessState.RUNNING,
percent_cpu=0.25,
memory=1024,
cpu_time=timedelta(seconds=10, minutes=5, hours=1),
)

return expected_status


class RemoteServerStub:
def __init__(self, expected_status: ProcessStatus) -> None:
self.expected_status = expected_status

async def read_file(self, path: str) -> str:
return str(self.expected_status.pid)

async def process_status(self, process_group: int) -> list[ProcessStatus]:
return [self.expected_status]


def running_ocrd_job(pid: int) -> OcrdJob:
running_job = replace(job_template(), pid=pid)
return running_job
Expand All @@ -154,7 +128,6 @@ def assert_lists_completed_job(

def assert_lists_running_job(
running_job: OcrdJob,
process_status: ProcessStatus,
response: Response,
) -> None:
texts = collect_texts_from_job_table(response.content, "running-jobs")
Expand All @@ -164,11 +137,7 @@ def assert_lists_running_job(
str(running_job.task_id),
str(running_job.process_id),
running_job.workflow_file.name,
str(process_status.pid),
str(process_status.state),
str(process_status.percent_cpu),
str(process_status.memory),
str(process_status.cpu_time),
str(running_job.pid),
]


Expand Down

0 comments on commit a593a9c

Please sign in to comment.