forked from balisujohn/localwriter
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_symbolic.py
More file actions
59 lines (44 loc) · 1.71 KB
/
Copy pathtest_symbolic.py
File metadata and controls
59 lines (44 loc) · 1.71 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# WriterAgent - AI Writing Assistant for LibreOffice
# Copyright (c) 2026 KeithCu (modifications and relicensing)
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Tests for trusted symbolic math helpers."""
from __future__ import annotations
from unittest.mock import patch
import pytest
from plugin.scripting.symbolic import run_symbolic
pytest.importorskip("sympy")
def test_run_symbolic_simplify():
result = run_symbolic(
{"helper": "symbolic_simplify", "params": {"expression": "(x + 1)**2 - x**2 - 2*x"}},
None,
{},
)
assert result["status"] == "ok"
assert result["helper"] == "symbolic_simplify"
assert result["text"] == "1"
def test_run_symbolic_solve_equation():
result = run_symbolic(
{"helper": "solve_equation", "params": {"equation": "x**2 - 4", "variable": "x"}},
None,
{},
)
assert result["status"] == "ok"
assert len(result.get("solutions", [])) == 2
def test_run_symbolic_integrate():
result = run_symbolic(
{"helper": "integrate", "params": {"expression": "x", "variable": "x"}},
None,
{},
)
assert result["status"] == "ok"
assert "x" in result["latex"].lower()
def test_run_symbolic_missing_package():
with patch("plugin.scripting.venv.symbolic._require_sympy", return_value=None):
result = run_symbolic({"helper": "symbolic_simplify", "params": {"expression": "x"}}, None, {})
assert result["status"] == "error"
assert result["code"] == "MISSING_PACKAGE"
def test_run_symbolic_parse_error():
result = run_symbolic({"helper": "symbolic_simplify", "params": {"expression": "((("}}, None, {})
assert result["status"] == "error"
assert result["code"] == "PARSE_ERROR"