Spaces:
Running
Running
File size: 1,207 Bytes
70f2179 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import annotations
import pytest
from opencode_env.task import OpenCodeTask
def test_coerce_from_string():
task = OpenCodeTask.coerce("write fizzbuzz")
assert task.instruction == "write fizzbuzz"
assert task.setup_shell is None
assert task.upload_files == {}
def test_coerce_from_dict():
task = OpenCodeTask.coerce(
{
"instruction": "run tests",
"setup_shell": "pip install pytest",
"upload_files": {"/home/user/workdir/hello.py": "print('hi')"},
"metadata": {"task_id": "hello_001"},
}
)
assert task.instruction == "run tests"
assert task.setup_shell == "pip install pytest"
assert task.metadata["task_id"] == "hello_001"
def test_coerce_passes_through_existing_task():
existing = OpenCodeTask(instruction="x")
assert OpenCodeTask.coerce(existing) is existing
def test_coerce_rejects_bad_type():
with pytest.raises(TypeError):
OpenCodeTask.coerce(42)
|