Skip to content

Update test for support/os_helper.py (second attempt) #3476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 28, 2021
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
from test import support
from test.support import os_helper


USAGE = """\
Expand Down Expand Up @@ -280,7 +281,7 @@ def _create_parser():
def relative_filename(string):
# CWD is replaced with a temporary dir before calling main(), so we
# join it with the saved CWD so it ends up where the user expects.
return os.path.join(support.SAVEDCWD, string)
return os.path.join(os_helper.SAVEDCWD, string)


def huntrleaks(string):
Expand Down
9 changes: 5 additions & 4 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from test.libregrtest.setup import setup_tests
from test.libregrtest.utils import removepy, count, format_duration, printlist
from test import support
from test.support import os_helper


# When tests are run from the Python build directory, it is best practice
Expand Down Expand Up @@ -199,7 +200,7 @@ def find_tests(self, tests):
# regex to match 'test_builtin' in line:
# '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec'
regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
with open(os.path.join(os_helper.SAVEDCWD, self.ns.fromfile)) as fp:
for line in fp:
line = line.split('#', 1)[0]
line = line.strip()
Expand Down Expand Up @@ -542,7 +543,7 @@ def save_xml_result(self):
for k, v in totals.items():
root.set(k, str(v))

xmlpath = os.path.join(support.SAVEDCWD, self.ns.xmlpath)
xmlpath = os.path.join(os_helper.SAVEDCWD, self.ns.xmlpath)
with open(xmlpath, 'wb') as f:
for s in ET.tostringlist(root):
f.write(s)
Expand All @@ -568,8 +569,8 @@ def main(self, tests=None, **kwargs):
# Run the tests in a context manager that temporarily changes the CWD to a
# temporary and writable directory. If it's not possible to create or
# change the CWD, the original CWD will be used. The original CWD is
# available from support.SAVEDCWD.
with support.temp_cwd(test_cwd, quiet=True):
# available from os_helper.SAVEDCWD.
with os_helper.temp_cwd(test_cwd, quiet=True):
self._main(tests, kwargs)

def getloadavg(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/refleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_pooled_int(value):
return int_pool.setdefault(value, value)

nwarmup, ntracked, fname = ns.huntrleaks
fname = os.path.join(support.SAVEDCWD, fname)
fname = os.path.join(os_helper.SAVEDCWD, fname)
repcount = nwarmup + ntracked

# Pre-allocate to ensure that the loop doesn't allocate anything new
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import unittest

from test import support
from test.support import os_helper
from test.libregrtest.refleak import dash_R, clear_caches
from test.libregrtest.save_env import saved_test_environment
from test.libregrtest.utils import print_warning
Expand Down Expand Up @@ -298,7 +299,7 @@ def cleanup_test_droppings(test_name, verbose):
# since if a test leaves a file open, it cannot be deleted by name (while
# there's nothing we can do about that here either, we can display the
# name of the offending test, which is a real help).
for name in (support.TESTFN,
for name in (os_helper.TESTFN,
"db_home",
):
if not os.path.exists(name):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/runtest_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run_test_in_subprocess(testname, ns):
stderr=subprocess.PIPE,
universal_newlines=True,
close_fds=(os.name != 'nt'),
cwd=support.SAVEDCWD)
cwd=os_helper.SAVEDCWD)


def run_tests_worker(worker_args):
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/libregrtest/save_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import threading
import warnings
from test import support
from test.support import os_helper
from test.libregrtest.utils import print_warning
try:
import _multiprocessing, multiprocessing.process
Expand Down Expand Up @@ -228,12 +229,12 @@ def get_files(self):
return sorted(fn + ('/' if os.path.isdir(fn) else '')
for fn in os.listdir())
def restore_files(self, saved_value):
fn = support.TESTFN
fn = os_helper.TESTFN
if fn not in saved_value and (fn + '/') not in saved_value:
if os.path.isfile(fn):
support.unlink(fn)
os_helper.unlink(fn)
elif os.path.isdir(fn):
support.rmtree(fn)
os_helper.rmtree(fn)

_lc = [getattr(locale, lc) for lc in dir(locale)
if lc.startswith('LC_')]
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/win_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def start(self):

# Spawn off the load monitor
command = ['typeperf', COUNTER_NAME, '-si', str(SAMPLING_INTERVAL)]
self.p = subprocess.Popen(command, stdout=command_stdout, cwd=support.SAVEDCWD)
self.p = subprocess.Popen(command, stdout=command_stdout, cwd=os_helper.SAVEDCWD)

# Close our copy of the write end of the pipe
os.close(command_stdout)
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/list_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functools import cmp_to_key

from test import support, seq_tests
from test.support import os_helper


class CommonTest(seq_tests.CommonTest):
Expand Down Expand Up @@ -73,12 +74,12 @@ def test_print(self):
d.append(d)
d.append(400)
try:
with open(support.TESTFN, "w") as fo:
with open(os_helper.TESTFN, "w") as fo:
fo.write(str(d))
with open(support.TESTFN, "r") as fo:
with open(os_helper.TESTFN, "r") as fo:
self.assertEqual(fo.read(), repr(d))
finally:
os.remove(support.TESTFN)
os.remove(os_helper.TESTFN)

def test_set_subscript(self):
a = self.type2test(range(20))
Expand Down
Loading