Skip to content

Commit

Permalink
Using tmp as pwd in pytests (#1068)
Browse files Browse the repository at this point in the history
As General Peron said, "Better than saying is doing". This is what I was
talking about in #1067.
Also, I improved some docstrings a little bit.

---------

Co-authored-by: rocky <[email protected]>
  • Loading branch information
mmatera and rocky authored Aug 13, 2024
1 parent e00f6e1 commit 114f4bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions test/builtin/files_io/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def test_close():
@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
(None, None, None, None), # Reset the session and set the working
# directory as the temporary directory
('Close["abc"]', ("abc is not open.",), "Close[abc]", ""),
(
"exp = Sin[1]; FilePrint[exp]",
Expand Down
23 changes: 18 additions & 5 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@


def reset_session(add_builtin=True, catch_interrupt=False):
"""
reset the session cleaning all the definitions.
"""
global session
session.reset()
session.evaluate("SetDirectory[$TemporaryDirectory];")


def evaluate_value(str_expr: str):
Expand All @@ -38,21 +42,30 @@ def check_evaluation(
):
"""
Helper function to test Mathics expression against
its results
its results.
Compares the expressions represented by ``str_expr`` and ``str_expected`` by
evaluating the first, and optionally, the second. If omitted, `str_expected`
is assumed to be `"Null"`.
to_string_expr: If ``True`` (default value) the result of the evaluation is
converted into a Python string. Otherwise, the expression is kept
as an Expression object.
If this argument is set to ``None``, the session is reset.
str_expr: The expression to be tested. If its value is ``None``, the session is
reset.
At the beginning of each set of pytests, it is important to call
``check_evaluation(None)`` to avoid that definitions introduced by
other tests affect the results.
str_expected: The expected result. The value ``None`` is equivalent to ``"Null"``.
failure_message: message shown in case of failure. Use "" for no failure message.
hold_expected: If ``False`` (default value) the ``str_expected`` is evaluated.
Otherwise, the expression is considered literally.
to_string_expr: If ``True`` (default value) the result of the evaluation is
converted into a Python string. Otherwise, the expression is kept
as an Expression object.
If this argument is set to ``None``, the session is reset.
to_string_expected: If ``True`` (default value) the expected expression is
evaluated and then converted to a Python string. result of the
evaluation is converted into a Python string.
Expand Down

0 comments on commit 114f4bb

Please sign in to comment.