|
16 | 16 |
|
17 | 17 |
|
18 | 18 | @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) |
32 | 40 |
|
33 | 41 |
|
34 | 42 | # Stolen from pandas |
@@ -179,7 +187,8 @@ def test_basic_conversion_from_http_url(self): |
179 | 187 | def test_convert_with_custom_writer(self): |
180 | 188 | lua_file_content = self.create_sample_lua() |
181 | 189 | 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: |
183 | 192 | expected = u'<h1 id="title">title</h1>{0}'.format(os.linesep) |
184 | 193 | received = pypandoc.convert_file(file_name, lua_file_name) |
185 | 194 | self.assertEqualExceptForNewlineEnd(expected, received) |
@@ -397,7 +406,7 @@ def create_sample_lua(self): |
397 | 406 | out, err = p.communicate() |
398 | 407 | return out.decode('utf-8') |
399 | 408 |
|
400 | | - def assertEqualExceptForNewlineEnd(self, expected, received): # noqa |
| 409 | + def assertEqualExceptForNewlineEnd(self, expected, received): # noqa |
401 | 410 | # output written to a file does not seem to have os.linesep |
402 | 411 | # handle everything here by replacing the os linesep by a simple \n |
403 | 412 | expected = expected.replace(os.linesep, "\n") |
|
0 commit comments