Skip to content

Commit 0d12f7d

Browse files
committed
Workaround a problem with uppercase lua filenames in pandoc
1 parent f6aa426 commit 0d12f7d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

‎tests.py‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616

1717

1818
@contextlib.contextmanager
19-
def closed_tempfile(suffix, text=None, dir_name=None):
20-
if dir_name:
21-
dir_name = tempfile.mkdtemp(suffix=dir_name)
22-
with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file:
23-
file_name = test_file.name
24-
if text:
25-
test_file.write(text)
26-
test_file.flush()
27-
yield file_name
28-
if dir_name:
29-
shutil.rmtree(dir_name, ignore_errors=True)
30-
else:
31-
os.remove(file_name)
19+
def closed_tempfile(suffix, text=None, dir_name=None, check_case=False):
20+
file_name = None
21+
try:
22+
if dir_name:
23+
dir_name = tempfile.mkdtemp(suffix=dir_name)
24+
25+
with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file:
26+
file_name = test_file.name
27+
if text:
28+
test_file.write(text)
29+
test_file.flush()
30+
if check_case and file_name != file_name.lower():
31+
# there is a bug in pandoc which can't work with uppercase lua files
32+
# https://github.com/jgm/pandoc/issues/4610
33+
raise unittest.SkipTest("pandoc has problems with uppercase filenames, got %s" % file_name)
34+
yield file_name
35+
finally:
36+
if dir_name:
37+
shutil.rmtree(dir_name, ignore_errors=True)
38+
elif file_name:
39+
os.remove(file_name)
3240

3341

3442
# Stolen from pandas
@@ -179,7 +187,8 @@ def test_basic_conversion_from_http_url(self):
179187
def test_convert_with_custom_writer(self):
180188
lua_file_content = self.create_sample_lua()
181189
with closed_tempfile('.md', text='# title\n') as file_name:
182-
with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz") as lua_file_name:
190+
with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz",
191+
check_case=True) as lua_file_name:
183192
expected = u'<h1 id="title">title</h1>{0}'.format(os.linesep)
184193
received = pypandoc.convert_file(file_name, lua_file_name)
185194
self.assertEqualExceptForNewlineEnd(expected, received)
@@ -397,7 +406,7 @@ def create_sample_lua(self):
397406
out, err = p.communicate()
398407
return out.decode('utf-8')
399408

400-
def assertEqualExceptForNewlineEnd(self, expected, received): # noqa
409+
def assertEqualExceptForNewlineEnd(self, expected, received): # noqa
401410
# output written to a file does not seem to have os.linesep
402411
# handle everything here by replacing the os linesep by a simple \n
403412
expected = expected.replace(os.linesep, "\n")

0 commit comments

Comments
 (0)