Skip to content

Commit

Permalink
pythongh-109162: libregrtest: use relative imports
Browse files Browse the repository at this point in the history
libregrtest.__init__ no longer exposes any symbol, so
"python -m test.libregrtest.worker" imports less modules.
  • Loading branch information
vstinner committed Sep 11, 2023
1 parent 0c139b5 commit 948146a
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Lib/test/__main__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from test.libregrtest import main
from test.libregrtest.main import main
main()
2 changes: 1 addition & 1 deletion Lib/test/autotest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This should be equivalent to running regrtest.py from the cmdline.
# It can be especially handy if you're in an interactive shell, e.g.,
# from test import autotest.
from test.libregrtest import main
from test.libregrtest.main import main
main()
2 changes: 0 additions & 2 deletions Lib/test/libregrtest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from test.libregrtest.cmdline import _parse_args, RESOURCE_NAMES, ALL_RESOURCES
from test.libregrtest.main import main
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/findtests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from test.libregrtest.utils import StrPath, TestName, TestList
from .utils import StrPath, TestName, TestList


# If these test directories are encountered recurse into them and treat each
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/libregrtest/logger.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import time

from test.libregrtest.results import TestResults
from test.libregrtest.runtests import RunTests
from test.libregrtest.utils import print_warning, MS_WINDOWS
from .results import TestResults
from .runtests import RunTests
from .utils import print_warning, MS_WINDOWS

if MS_WINDOWS:
from test.libregrtest.win_utils import WindowsLoadTracker
from .win_utils import WindowsLoadTracker


class Logger:
Expand Down
22 changes: 11 additions & 11 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
from test import support
from test.support import os_helper

from test.libregrtest.cmdline import _parse_args, Namespace
from test.libregrtest.findtests import findtests, split_test_packages
from test.libregrtest.logger import Logger
from test.libregrtest.result import State
from test.libregrtest.runtests import RunTests, HuntRefleak
from test.libregrtest.setup import setup_process, setup_test_dir
from test.libregrtest.single import run_single_test, PROGRESS_MIN_TIME
from test.libregrtest.pgo import setup_pgo_tests
from test.libregrtest.results import TestResults
from test.libregrtest.utils import (
from .cmdline import _parse_args, Namespace
from .findtests import findtests, split_test_packages
from .logger import Logger
from .result import State
from .runtests import RunTests, HuntRefleak
from .setup import setup_process, setup_test_dir
from .single import run_single_test, PROGRESS_MIN_TIME
from .pgo import setup_pgo_tests
from .results import TestResults
from .utils import (
StrPath, StrJSON, TestName, TestList, TestTuple, FilterTuple,
strip_py_suffix, count, format_duration,
printlist, get_build_info, get_temp_dir, get_work_dir, exit_timeout,
Expand Down Expand Up @@ -409,7 +409,7 @@ def get_state(self):
return state

def _run_tests_mp(self, runtests: RunTests, num_workers: int) -> None:
from test.libregrtest.run_workers import RunWorkers
from .run_workers import RunWorkers
RunWorkers(num_workers, runtests, self.logger, self.results).run()

def finalize_tests(self, tracer):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/libregrtest/refleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from test import support
from test.support import os_helper

from test.libregrtest.runtests import HuntRefleak
from test.libregrtest.utils import clear_caches
from .runtests import HuntRefleak
from .utils import clear_caches

try:
from _abc import _get_dump
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from test.support import TestStats

from test.libregrtest.utils import (
from .utils import (
StrJSON, TestName, FilterTuple,
format_duration, normalize_test_name, print_warning)

Expand Down
6 changes: 3 additions & 3 deletions Lib/test/libregrtest/results.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from test.support import TestStats

from test.libregrtest.runtests import RunTests
from test.libregrtest.result import State, TestResult
from test.libregrtest.utils import (
from .runtests import RunTests
from .result import State, TestResult
from .utils import (
StrPath, TestName, TestTuple, TestList, FilterDict,
printlist, count, format_duration)

Expand Down
14 changes: 7 additions & 7 deletions Lib/test/libregrtest/run_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
from test import support
from test.support import os_helper

from test.libregrtest.logger import Logger
from test.libregrtest.result import TestResult, State
from test.libregrtest.results import TestResults
from test.libregrtest.runtests import RunTests
from test.libregrtest.single import PROGRESS_MIN_TIME
from test.libregrtest.utils import (
from .logger import Logger
from .result import TestResult, State
from .results import TestResults
from .runtests import RunTests
from .single import PROGRESS_MIN_TIME
from .utils import (
StrPath, TestName,
format_duration, print_warning)
from test.libregrtest.worker import create_worker_process, USE_PROCESS_GROUP
from .worker import create_worker_process, USE_PROCESS_GROUP

if sys.platform == 'win32':
import locale
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from typing import Any

from test.libregrtest.utils import (
from .utils import (
StrPath, StrJSON, TestTuple, FilterTuple, FilterDict)


Expand Down
4 changes: 3 additions & 1 deletion Lib/test/libregrtest/save_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import os
import sys
import threading

from test import support
from test.support import os_helper
from test.libregrtest.utils import print_warning

from .utils import print_warning


class SkipTestEnvironment(Exception):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/libregrtest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
except ImportError:
gc = None

from test.libregrtest.runtests import RunTests
from test.libregrtest.utils import (
from .runtests import RunTests
from .utils import (
setup_unraisable_hook, setup_threading_excepthook, fix_umask,
replace_stdout, adjust_rlimit_nofile)

Expand Down
12 changes: 6 additions & 6 deletions Lib/test/libregrtest/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from test.support import TestStats
from test.support import threading_helper

from test.libregrtest.result import State, TestResult
from test.libregrtest.runtests import RunTests
from test.libregrtest.save_env import saved_test_environment
from test.libregrtest.setup import setup_tests
from test.libregrtest.utils import (
from .result import State, TestResult
from .runtests import RunTests
from .save_env import saved_test_environment
from .setup import setup_tests
from .utils import (
TestName,
clear_caches, remove_testfn, abs_module_name, print_warning)

Expand All @@ -40,7 +40,7 @@ def regrtest_runner(result: TestResult, test_func, runtests: RunTests) -> None:
# Run test_func(), collect statistics, and detect reference and memory
# leaks.
if runtests.hunt_refleak:
from test.libregrtest.refleak import runtest_refleak
from .refleak import runtest_refleak
refleak, test_result = runtest_refleak(result.test_name, test_func,
runtests.hunt_refleak,
runtests.quiet)
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/libregrtest/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from test import support
from test.support import os_helper

from test.libregrtest.setup import setup_process, setup_test_dir
from test.libregrtest.runtests import RunTests
from test.libregrtest.single import run_single_test
from test.libregrtest.utils import (
from .setup import setup_process, setup_test_dir
from .runtests import RunTests
from .single import run_single_test
from .utils import (
StrPath, StrJSON, FilterTuple,
get_work_dir, exit_timeout)

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import os
import sys
from test.libregrtest import main
from test.libregrtest.main import main


# Alias for backward compatibility (just in case)
Expand Down
Loading

0 comments on commit 948146a

Please sign in to comment.