Skip to content

Commit 613166e

Browse files
committed
Flush NamedTemporaryFile before reading
We have to flush the file to make sure that wirte is complete before we re-open it and read from it. Otherwise, we are not guaranteed to read the data back. This can lead to test failures on certain systems.
1 parent 34f74f9 commit 613166e

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

sympy/parsing/c/c_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def parse_str(self, source, flags):
180180
"""
181181
file = tempfile.NamedTemporaryFile(mode = 'w+', suffix = '.cpp')
182182
file.write(source)
183+
file.flush()
183184
file.seek(0)
184185
self.tu = self.index.parse(
185186
file.name,

sympy/parsing/tests/test_custom_latex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def init_custom_parser(modification, transformer=None):
3030

3131
with tempfile.NamedTemporaryFile() as f:
3232
f.write(bytes(latex_grammar, encoding="utf8"))
33+
f.flush()
3334

3435
parser = LarkLaTeXParser(grammar_file=f.name, transformer=transformer)
3536

0 commit comments

Comments
 (0)