Skip to content

Commit

Permalink
use dedicated formatting error codes #666
Browse files Browse the repository at this point in the history
  • Loading branch information
mam10eks committed Sep 24, 2024
1 parent fef5a28 commit 35ff580
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#docker build -t webis/tira:dev-container-0.0.1 -f .devcontainer/Dockerfile.dev .
FROM ubuntu:24.04

ENV TZ=Europe/Berlin
Expand All @@ -20,7 +21,11 @@ RUN <<EOF
useradd -ms /bin/bash dev
echo 'dev:1234' | chpasswd
usermod -aG sudo dev
usermod -aG docker dev
usermod -aG docker dev
# Sometimes, the ubuntu user is used in the dev container
echo 'ubuntu:1234' | chpasswd
usermod -aG sudo ubuntu
usermod -aG docker ubuntu
EOF


Expand Down Expand Up @@ -90,3 +95,4 @@ RUN mkdir -p /usr/share/umlet \
&& unzip download.zip
USER dev
RUN pip3 install sphinx furo myst-parser sphinx-toolbox sphinx-design sphinxcontrib-plantuml sphinxcontrib-umlet

6 changes: 6 additions & 0 deletions python-client/tests/format_check/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from pathlib import Path

from tira.check_format import FormatMsgType

_ERROR = FormatMsgType.ERROR
_OK = FormatMsgType.OK
_WARN = FormatMsgType.WARN

RESOURCES = Path(__file__).parent.parent / "resources"
VALID_RUN_OUTPUT = RESOURCES / "ranking-outputs"
EMPTY_OUTPUT = RESOURCES / "input-run-01" / "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

from tira.check_format import check_format

from . import EMPTY_OUTPUT, IR_QUERY_OUTPUT, VALID_RUN_OUTPUT
from . import _ERROR, _OK, EMPTY_OUTPUT, IR_QUERY_OUTPUT, VALID_RUN_OUTPUT


class TestCheckFormatForNonExistingFormats(unittest.TestCase):
def test_invalid_validator_on_empty_output(self):
expected = ["ERROR", "No file run.txt was found, only the files ['.gitkeep'] were available."]
expected = [_ERROR, "No file run.txt was found, only the files ['.gitkeep'] were available."]
actual = check_format(EMPTY_OUTPUT, "run.txt")
self.assertEqual(expected, actual)

def test_invalid_validator_on_query_output(self):
expected = ["ERROR", "No file run.txt was found, only the files ['queries.jsonl'] were available."]
expected = [_ERROR, "No file run.txt was found, only the files ['queries.jsonl'] were available."]
actual = check_format(IR_QUERY_OUTPUT, "run.txt")
self.assertEqual(expected, actual)

def test_invalid_validator_on_valid_run_output_output(self):
expected = ["OK", "The run.txt file has the correct format."]
expected = [_OK, "The run.txt file has the correct format."]
actual = check_format(VALID_RUN_OUTPUT, "run.txt")
self.assertEqual(expected, actual)
14 changes: 12 additions & 2 deletions python-client/tira/check_format.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import os
from enum import Enum
from pathlib import Path
from typing import Sequence, Union


class FormatMsgType(Enum):
OK = 0
WARN = 1
ERROR = 2


_fmt = FormatMsgType


class RunFormat:
"""Checks if a given output is a valid run file."""

def check_format(self, run_output: Path):
if not (run_output / "run.txt").exists():
msg = "No file run.txt was found, only the files "
msg += str(os.listdir(run_output)) + " were available."
return ["ERROR", msg]
return [_fmt.ERROR, msg]
else:
return ["OK", "The run.txt file has the correct format."]
return [_fmt.OK, "The run.txt file has the correct format."]


def check_format(run_output: Path, format: Union[str, Sequence[str]]):
Expand Down

0 comments on commit 35ff580

Please sign in to comment.