From b8664990bd194c681a355ea61dead4e1bf363681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 7 Mar 2023 11:09:34 +0100 Subject: [PATCH 1/3] tests: fix invocation with sys.executable The formatting to substitute sys.executable was not effective because the formatted string was discarded. But even when when the substitution is made, pandoc ignores the shebang line in the file when the file is not executable and invokes it using 'python'. This second issue was hiding the first. We need to fix both to actually execute code using the desired sys.executable. Finally, the first .format() was interfering with the second .format(). --- tests.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index eb791a8..8adaae7 100755 --- a/tests.py +++ b/tests.py @@ -347,9 +347,10 @@ def caps(key, value, format, meta): toJSONFilter(caps) ''' python_source = textwrap.dedent(python_source) - python_source.format(sys.executable) + python_source = python_source.format(sys.executable) with closed_tempfile(".py", python_source) as tempfile: + os.chmod(tempfile, 0o755) output = pypandoc.convert_text( markdown_source, to='html', format='md', outputfile=None, filters=tempfile ).strip() @@ -389,17 +390,21 @@ def test_conversion_with_mixed_filters(self): def func(key, value, format, meta): if key == "Para": - return Para(value + [Str("{0}-")]) + return Para(value + [Str("{{0}}-")]) if __name__ == "__main__": toJSONFilter(func) """ python = textwrap.dedent(python) - python.format(sys.executable) + python = python.format(sys.executable) with closed_tempfile(".lua", lua.format(1)) as temp1, closed_tempfile(".py", python.format(2)) as temp2: + os.chmod(temp2, 0o755) + with closed_tempfile(".lua", lua.format(3)) as temp3, closed_tempfile(".py", python.format(4)) as temp4: + os.chmod(temp4, 0o755) + output = pypandoc.convert_text( markdown_source, to="html", format="md", outputfile=None, filters=[temp1, temp2, temp3, temp4] ).strip() From 3edb6cc315eec3ae1154d320ac665eae0ded0379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 7 Mar 2023 12:14:28 +0100 Subject: [PATCH 2/3] tests: fix indentation --- tests.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests.py b/tests.py index 8adaae7..bcb2971 100755 --- a/tests.py +++ b/tests.py @@ -238,12 +238,12 @@ def test_conversion_with_data_files(self): if os.path.exists(test_docx_file): os.remove(test_docx_file) result = pypandoc.convert_file( - os.path.join(test_data_dir, 'index.html'), - to='docx', - format='html', - outputfile=test_docx_file, - sandbox=True, -) + os.path.join(test_data_dir, 'index.html'), + to='docx', + format='html', + outputfile=test_docx_file, + sandbox=True, + ) print(result) def test_convert_with_custom_writer(self): From 93670675f872fd5afa0d120bf45f571621064fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 7 Mar 2023 12:14:46 +0100 Subject: [PATCH 3/3] tests: show diff if comparison fails --- tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index bcb2971..fd952af 100755 --- a/tests.py +++ b/tests.py @@ -409,13 +409,13 @@ def func(key, value, format, meta): markdown_source, to="html", format="md", outputfile=None, filters=[temp1, temp2, temp3, temp4] ).strip() expected = "

-0-1-2-3-4-

" - self.assertTrue(output == expected) + self.assertEquals(output, expected) output = pypandoc.convert_text( markdown_source, to="html", format="md", outputfile=None, filters=[temp3, temp1, temp4, temp2] ).strip() expected = "

-0-3-1-4-2-

" - self.assertTrue(output == expected) + self.assertEquals(output, expected) def test_classify_pandoc_logging(self):