From 2bee1b6a85d786b5000ab891c68d394e35154733 Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 1 Feb 2024 13:03:27 +0000 Subject: [PATCH] Fix tests for LaTeX to MathML converters. Strip trailing underscore from generated output file names. Move test setup out of the "with self.subTest(...) block. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@9532 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- ...s_mathml_.html => math_experiments_mathml.html} | 0 ...matics_mathml_.html => mathematics_mathml.html} | 0 .../test_utils/test_math/test_tex2mathml_extern.py | 58 +++++++++++----------- 3 files changed, 29 insertions(+), 29 deletions(-) rename docutils/test/functional/expected/{math_experiments_mathml_.html => math_experiments_mathml.html} (100%) rename docutils/test/functional/expected/{mathematics_mathml_.html => mathematics_mathml.html} (100%) diff --git a/docutils/test/functional/expected/math_experiments_mathml_.html b/docutils/test/functional/expected/math_experiments_mathml.html similarity index 100% rename from docutils/test/functional/expected/math_experiments_mathml_.html rename to docutils/test/functional/expected/math_experiments_mathml.html diff --git a/docutils/test/functional/expected/mathematics_mathml_.html b/docutils/test/functional/expected/mathematics_mathml.html similarity index 100% rename from docutils/test/functional/expected/mathematics_mathml_.html rename to docutils/test/functional/expected/mathematics_mathml.html diff --git a/docutils/test/test_utils/test_math/test_tex2mathml_extern.py b/docutils/test/test_utils/test_math/test_tex2mathml_extern.py index fc0cdba12..9e9510b6d 100644 --- a/docutils/test/test_utils/test_math/test_tex2mathml_extern.py +++ b/docutils/test/test_utils/test_math/test_tex2mathml_extern.py @@ -103,17 +103,17 @@ class MathMLConverterTestCase(unittest.TestCase): source_path = DOCS / 'ref' / 'rst' / 'mathematics.txt' for math_output in math_options: + settings = {'math_output': math_output, + 'stylesheet_path': 'minimal.css,responsive.css', + **self.settings} + out_file = f'mathematics_{"_".join(math_output).strip("_")}.html' + out_path = OUTPUT / out_file + expected_path = EXPECTED / out_file + output = publish_file(source_path=str(source_path), + destination_path=out_path.as_posix(), + writer_name='html5', + settings_overrides=settings) with self.subTest(converter=math_output[1] or 'latex2mathml()'): - settings = {'math_output': math_output, - 'stylesheet_path': 'minimal.css,responsive.css', - **self.settings} - out_file = '_'.join(('mathematics', *math_output)) + '.html' - out_path = OUTPUT / out_file - expected_path = EXPECTED / out_file - output = publish_file(source_path=str(source_path), - destination_path=out_path.as_posix(), - writer_name='html5', - settings_overrides=settings) compare_output(output, out_path, expected_path) def test_math_experiments(self): @@ -122,33 +122,33 @@ class MathMLConverterTestCase(unittest.TestCase): source_path = INPUT / 'data' / 'math_experiments.txt' for math_output in math_options: + settings = {'math_output': math_output, **self.settings} + out_file = f'math_experiments_{"_".join(math_output).strip("_")}.html' # noqa: E501 + out_path = OUTPUT / out_file + expected_path = EXPECTED / out_file + output = publish_file(source_path=str(source_path), + destination_path=out_path.as_posix(), + writer_name='html5', + settings_overrides=settings) with self.subTest(converter=math_output[1] or 'latex2mathml()'): - settings = {'math_output': math_output, **self.settings} - out_file = '_'.join(('math_experiments', *math_output)) + '.html' # noqa - out_path = OUTPUT / out_file - expected_path = EXPECTED / out_file - output = publish_file(source_path=str(source_path), - destination_path=out_path.as_posix(), - writer_name='html5', - settings_overrides=settings) compare_output(output, out_path, expected_path) def test_buggy_math(self): """Test reporting conversion failure due to TeX-syntax errors.""" for math_output in math_options: + settings = {'math_output': math_output, **self.settings} + out_file = f'buggy_{"_".join(math_output).strip("_")}.html' + out_path = OUTPUT / out_file + expected_path = EXPECTED / out_file + preface = f'Test "math-output: {" ".join(math_output)}".\n\n' + parts = publish_parts(preface + buggy_sample, + 'buggy-maths', + writer_name='html5', + settings_overrides=settings) + with open(out_path, "w") as fd: + fd.write(parts['whole']) with self.subTest(converter=math_output[1] or 'latex2mathml()'): - settings = {'math_output': math_output, **self.settings} - out_file = f'buggy_{"_".join(math_output).strip("_")}.html' - out_path = OUTPUT / out_file - expected_path = EXPECTED / out_file - preface = f'Test "math-output: {" ".join(math_output)}".\n\n' - parts = publish_parts(preface + buggy_sample, - 'buggy-maths', - writer_name='html5', - settings_overrides=settings) - with open(out_path, "w") as fd: - fd.write(parts['whole']) compare_output(parts['whole'], out_path, expected_path) -- 2.11.4.GIT