Skip to content

Commit

Permalink
Tests fixes (#328)
Browse files Browse the repository at this point in the history
* 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: fix indentation

* tests: show diff if comparison fails
  • Loading branch information
keszybz authored Mar 9, 2023
1 parent 5348c62 commit e879cfa
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -389,28 +390,32 @@ 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()
expected = "<p>-0-1-2-3-4-</p>"
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 = "<p>-0-3-1-4-2-</p>"
self.assertTrue(output == expected)
self.assertEquals(output, expected)

def test_classify_pandoc_logging(self):

Expand Down

0 comments on commit e879cfa

Please sign in to comment.