◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
12 changes: 6 additions & 6 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def _captured_script(script):
indented = script.replace('\n', '\n ')
wrapped = dedent(f"""
import contextlib
with open({w}, 'w') as spipe:
with contextlib.redirect_stdout(spipe):
{indented}
""")
return wrapped, open(r)


def _run_output(interp, request, shared=None):
Expand All @@ -45,7 +45,7 @@ def _running(interp):
def run():
interpreters.run_string(interp, dedent(f"""
# wait for "signal"
with open({r}) as rpipe:
rpipe.read()
"""))

Expand All @@ -54,7 +54,7 @@ def run():

yield

with open(w, 'w') as spipe:
spipe.write('done')
t.join()

Expand Up @@ -806,7 +806,7 @@ def f():
@unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
def test_fork(self):
import tempfile
with tempfile.NamedTemporaryFile('w+') as file:
file.write('')
file.flush()

Expand All @@ -816,7 +816,7 @@ def test_fork(self):
try:
os.fork()
except RuntimeError:
with open('{file.name}', 'w') as out:
out.write('{expected}')
""")
interpreters.run_string(self.id, script)
Expand Down
14 changes: 8 additions & 6 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def tearDown(self):

def create_readonly_file(self, filename):
file_path = os.path.join(self.temp_dir, filename)
with open(file_path, 'w') as file:
file.write(filename)
os.chmod(file_path, stat.S_IREAD)

Expand Down Expand Up @@ -1468,7 +1468,7 @@ def setUp(self):
('invalid', '@no-such-path\n'),
]
for path, text in file_texts:
with open(path, 'w') as file:
file.write(text)

parser_signature = Sig(fromfile_prefix_chars='@')
Expand Down Expand Up @@ -1498,7 +1498,7 @@ def setUp(self):
('hello', 'hello world!\n'),
]
for path, text in file_texts:
with open(path, 'w') as file:
file.write(text)

class FromFileConverterArgumentParser(ErrorRaisingArgumentParser):
Expand Up @@ -1580,7 +1580,8 @@ class TestFileTypeR(TempDirMixin, ParserTestCase):
def setUp(self):
super(TestFileTypeR, self).setUp()
for file_name in ['foo', 'bar']:
with open(os.path.join(self.temp_dir, file_name), 'w') as file:
file.write(file_name)
self.create_readonly_file('readonly')

Expand All @@ -1601,7 +1602,7 @@ class TestFileTypeDefaults(TempDirMixin, ParserTestCase):
"""Test that a file is not created unless the default is needed"""
def setUp(self):
super(TestFileTypeDefaults, self).setUp()
file = open(os.path.join(self.temp_dir, 'good'), 'w')
file.write('good')
file.close()

Expand All @@ -1620,7 +1621,8 @@ class TestFileTypeRB(TempDirMixin, ParserTestCase):
def setUp(self):
super(TestFileTypeRB, self).setUp()
for file_name in ['foo', 'bar']:
with open(os.path.join(self.temp_dir, file_name), 'w') as file:
file.write(file_name)

argument_signatures = [
5 changes: 3 additions & 2 deletions Lib/test/test_baseexception.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def test_inheritance(self):
except TypeError:
pass

inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
'exception_hierarchy.txt'))
try:
superclass_name = inheritance_tree.readline().rstrip()
try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_bdb.py
Original file line number Diff line number Diff line change
@@ -539,7 +539,7 @@ def create_modules(modules):
try:
for m in modules:
fname = m + '.py'
with open(fname, 'w') as f:
f.write(textwrap.dedent(modules[m]))
linecache.checkcache(fname)
importlib.invalidate_caches()
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_boolean(self):

def test_fileclosed(self):
try:
with open(os_helper.TESTFN, "w") as f:
self.assertIs(f.closed, False)
self.assertIs(f.closed, True)
finally:
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,7 @@ def test_CLI(): r"""
>>> from test.support.os_helper import temp_dir
>>> with temp_dir() as tmpdir:
... fn = os.path.join(tmpdir, 'myfile.doc')
... with open(fn, 'w') as f:
... _ = f.write('This is a very simple test file.\n')
... _ = f.write(' >>> 1 + 1\n')
... _ = f.write(' 2\n')
Expand Down Expand Up @@ -2898,7 +2898,7 @@ def test_CLI(): r"""
>>> from test.support.os_helper import temp_dir
>>> with temp_dir() as tmpdir:
... fn = os.path.join(tmpdir, 'myfile.doc')
... with open(fn, 'w') as f:
... _ = f.write('This is another simple test file.\n')
... _ = f.write(' >>> 1 + 1\n')
... _ = f.write(' 2\n')
Expand All @@ -2909,7 +2909,7 @@ def test_CLI(): r"""
... _ = f.write('\n')
... _ = f.write('And that is it.\n')
... fn2 = os.path.join(tmpdir, 'myfile2.py')
... with open(fn2, 'w') as f:
... _ = f.write('def test_func():\n')
... _ = f.write(' \"\"\"\n')
... _ = f.write(' This is simple python test function.\n')
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def testRaising(self):
self.assertRaises(AttributeError, getattr, sys, "undefined_attribute")

self.raise_catch(EOFError, "EOFError")
fp = open(TESTFN, 'w')
fp.close()
fp = open(TESTFN, 'r')
savestdin = sys.stdin
try:
try:
Expand Down
2 changes: 1 addition & 1 deletion Parser/asdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def check(mod):

def parse(filename):
"""Parse ASDL from the given file and return a Module node describing it."""
with open(filename) as f:
parser = ASDLParser()
return parser.parse(f.read())

Expand Down
Toggle all file notes Toggle all file annotations