def test_run(mocker, func, result): load = mocker.patch("arca._runner.EntryPoint.load") load.return_value = func _, file = tempfile.mkstemp() file = Path(file) file.write_text( json.dumps({ "entry_point": { "module_name": "library.mod", "object_name": "sum" }, "args": [1, 2, 3], "kwargs": { "x": 4, "y": 5 } })) output = runner.run(str(file)) assert isinstance(output, dict) if result is True: assert output["success"] is True assert output["result"] == 15 else: assert output["success"] is False assert result.__name__ in output["error"] file.unlink()
def test_definition_corruption(definition): _, file = tempfile.mkstemp() file = Path(file) if isinstance(definition, dict): file.write_text(json.dumps(definition)) else: file.write_text(definition) output = runner.run(str(file)) assert isinstance(output, dict) assert not output["success"] assert output["error"] assert output["reason"] == "corrupted_definition" file.unlink()
def test_unicode(mocker, args, kwargs, result): load = mocker.patch("arca._runner.EntryPoint.load") def func(カ): return カ * 2 load.return_value = func _, file = tempfile.mkstemp() file = Path(file) file.write_text(Task("library.mod:func", args=args, kwargs=kwargs).json) output = runner.run(str(file)) assert Result(output).output == result file.unlink()
def test_import_error(module_name, object_name): _, file = tempfile.mkstemp() file = Path(file) file.write_text( json.dumps({ "entry_point": { "module_name": module_name, "object_name": object_name }, "args": [1, 2, 3], "kwargs": { "x": 4, "y": 5 } })) output = runner.run(str(file)) assert isinstance(output, dict) assert not output["success"] assert output["error"] assert output["reason"] == "import" file.unlink()