Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc doctest and pytrest fixes #1066

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions mathics/docpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ def __init__(self, data_path: Optional[str] = None, quiet: Optional[bool] = Fals
self.prev_key = []
self.quiet = quiet

def find_texdata_folder(self):
"""Generate a folder for texdata"""
return self.textdatafolder

def mark_as_failed(self, key):
"""Mark a key as failed"""
self.failed_sections.add(key)
Expand Down Expand Up @@ -200,7 +196,7 @@ def show_test(self, test, index, subindex):
def test_case(
test: DocTest,
test_pipeline: DocTestPipeline,
fail: Optional[Callable] = lambda x: False,
fail: Callable,
) -> bool:
"""
Run a single test cases ``test``. Return True if test succeeds and False if it
Expand Down Expand Up @@ -674,7 +670,7 @@ def show_report(test_pipeline):
test_pipeline.print_and_log(f" - {section} in {part} / {chapter}")

if test_parameters.data_path is not None and (
test_status.failed == 0 or test_parameters.doc_even_if_error
test_status.failed == 0 or test_parameters.keep_going
):
save_doctest_data(test_pipeline)
return
Expand Down Expand Up @@ -735,7 +731,7 @@ def save_doctest_data(doctest_pipeline: DocTestPipeline):
i = 0
for key in output_data:
i = i + 1
doctest_pipeline.print_and_log("{key}, {output_data[key]}")
doctest_pipeline.print_and_log(f"{key}, {output_data[key]}")
if i > 9:
break
with open(doctest_latex_data_path, "wb") as output_file:
Expand Down Expand Up @@ -913,6 +909,7 @@ def main():
test_pipeline = DocTestPipeline(args, output_format="latex", data_path=data_path)
test_status = test_pipeline.status

start_time = None
if args.sections:
include_sections = set(args.sections.split(","))
exclude_subsections = set(args.exclude.split(","))
Expand Down
12 changes: 9 additions & 3 deletions test/builtin/files_io/test_importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ def test_export():
"$Failed",
None,
),
## Empty elems
('Export["123.txt", 1+x, {}]', None, "123.txt", None),
## FORMATS
## ASCII text
('FileFormat["ExampleData/BloodToilTearsSweat.txt"]', None, "Text", None),
Expand Down Expand Up @@ -259,13 +257,21 @@ def test_inividually():
# Test Export where we cannot infer the export type from the file extension;
# here it is: ".jcp".
with tempfile.NamedTemporaryFile(mode="w", suffix=".jcp") as tmp:
filename = osp.join(tmp.name, "123.jcp")
filename = tmp.name
expr = f'Export["{filename}", 1+x,' + "{}]"
result = evaluate(expr)
outs = [out.text for out in session.evaluation.out]
assert result == SymbolFailed
assert outs == [f"Cannot infer format of file {filename}."]

# Check that exporting with an empty list of elements is okay.
with tempfile.NamedTemporaryFile(mode="w", suffix=".txt") as tmp:
filename = tmp.name
expr = f'Export["{filename}", 1+x' + "{}]"
result = evaluate(expr)
outs = [out.text for out in session.evaluation.out]
assert outs == []


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
Expand Down