diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-11-13 19:10:12 (GMT) |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-11-16 20:58:43 (GMT) |
commit | 3829f4551edebee3e42864b19e6332b24af3eb93 (patch) | |
tree | 6ca07b12f8a14e705c00a198739d43cb46d6666e /testing | |
parent | d1d5355b716644be649d99b16c6f2bf64e9f64e4 (diff) | |
download | SCons-3829f4551edebee3e42864b19e6332b24af3eb93.zip SCons-3829f4551edebee3e42864b19e6332b24af3eb93.tar.gz SCons-3829f4551edebee3e42864b19e6332b24af3eb93.tar.bz2 |
Integrate `from __future__ import annotations`
Diffstat (limited to 'testing')
-rw-r--r-- | testing/framework/TestCmd.py | 24 | ||||
-rw-r--r-- | testing/framework/TestCommon.py | 44 | ||||
-rw-r--r-- | testing/framework/TestSCons.py | 7 |
3 files changed, 40 insertions, 35 deletions
diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 243745d..7307078 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -295,6 +295,8 @@ version. TestCmd.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4') """ +from __future__ import annotations + __author__ = "Steven Knight <knight at baldmt dot com>" __revision__ = "TestCmd.py 1.3.D001 2010/06/03 12:58:27 knight" __version__ = "1.3" @@ -323,7 +325,7 @@ import traceback from collections import UserList, UserString from pathlib import Path from subprocess import PIPE, STDOUT -from typing import Callable, Dict, Optional, Union +from typing import Callable IS_WINDOWS = sys.platform == 'win32' IS_MACOS = sys.platform == 'darwin' @@ -437,7 +439,7 @@ def clean_up_ninja_daemon(self, result_type) -> None: def fail_test( self=None, condition: bool = True, - function: Optional[Callable] = None, + function: Callable | None = None, skip: int = 0, message: str = "", ) -> None: @@ -1044,8 +1046,8 @@ class TestCmd: diff_stdout=None, diff_stderr=None, combine: bool = False, - universal_newlines: Optional[bool] = True, - timeout: Optional[float] = None, + universal_newlines: bool | None = True, + timeout: float | None = None, ) -> None: self.external = os.environ.get('SCONS_EXTERNAL_TEST', 0) self._cwd = os.getcwd() @@ -1060,7 +1062,7 @@ class TestCmd: self.verbose_set(verbose) self.combine = combine self.universal_newlines = universal_newlines - self.process: Optional[Popen] = None + self.process: Popen | None = None # Two layers of timeout: one at the test class instance level, # one set on an individual start() call (usually via a run() call) self.timeout = timeout @@ -1068,7 +1070,7 @@ class TestCmd: self.set_match_function(match, match_stdout, match_stderr) self.set_diff_function(diff, diff_stdout, diff_stderr) self._dirlist = [] - self._preserve: Dict[str, Union[str, bool]] = { + self._preserve: dict[str, str | bool] = { 'pass_test': False, 'fail_test': False, 'no_result': False, @@ -1084,9 +1086,9 @@ class TestCmd: self._preserve['no_result'] = os.environ.get('PRESERVE_NO_RESULT', False) self._stdout = [] self._stderr = [] - self.status: Optional[int] = None + self.status: int | None = None self.condition = 'no_result' - self.workdir: Optional[str] + self.workdir: str | None self.workdir_set(workdir) self.subdir(subdir) @@ -1254,7 +1256,7 @@ class TestCmd: def fail_test( self, condition: bool = True, - function: Optional[Callable] = None, + function: Callable | None = None, skip: int = 0, message: str = "", )-> None: @@ -1738,7 +1740,7 @@ class TestCmd: """ time.sleep(seconds) - def stderr(self, run=None) -> Optional[str]: + def stderr(self, run=None) -> str | None: """Returns the stored standard error output from a given run. Args: @@ -1760,7 +1762,7 @@ class TestCmd: except IndexError: return None - def stdout(self, run=None) -> Optional[str]: + def stdout(self, run=None) -> str | None: """Returns the stored standard output from a given run. Args: diff --git a/testing/framework/TestCommon.py b/testing/framework/TestCommon.py index f5bb084..470dbcb 100644 --- a/testing/framework/TestCommon.py +++ b/testing/framework/TestCommon.py @@ -110,6 +110,8 @@ The TestCommon module also provides the following variables """ +from __future__ import annotations + __author__ = "Steven Knight <knight at baldmt dot com>" __revision__ = "TestCommon.py 1.3.D001 2010/06/03 12:58:27 knight" __version__ = "1.3" @@ -121,7 +123,7 @@ import sys import sysconfig from collections import UserList -from typing import Callable, List, Optional, Union +from typing import Callable from TestCmd import * from TestCmd import __all__ @@ -226,14 +228,14 @@ def separate_files(flist): missing.append(f) return existing, missing -def contains(seq, subseq, find: Optional[Callable] = None) -> bool: +def contains(seq, subseq, find: Callable | None = None) -> bool: if find is None: return subseq in seq else: f = find(seq, subseq) return f not in (None, -1) and f is not False -def find_index(seq, subseq, find: Optional[Callable] = None) -> Optional[int]: +def find_index(seq, subseq, find: Callable | None = None) -> int | None: # Returns either an index of the subseq within the seq, or None. # Accepts a function find(seq, subseq), which returns an integer on success # and either: None, False, or -1, on failure. @@ -280,8 +282,8 @@ class TestCommon(TestCmd): def options_arguments( self, - options: Union[str, List[str]], - arguments: Union[str, List[str]], + options: str | list[str], + arguments: str | list[str], ): """Merges the "options" keyword argument with the arguments.""" # TODO: this *doesn't* split unless both are non-empty strings. @@ -323,7 +325,7 @@ class TestCommon(TestCmd): file: str, required: str, mode: str = 'rb', - find: Optional[Callable] = None, + find: Callable | None = None, ) -> None: """Ensures specified file contains the required text. @@ -353,7 +355,7 @@ class TestCommon(TestCmd): print(file_contents) self.fail_test() - def must_contain_all(self, output, input, title: str = "", find: Optional[Callable] = None)-> None: + def must_contain_all(self, output, input, title: str = "", find: Callable | None = None)-> None: """Ensures that the specified output string (first argument) contains all of the specified input as a block (second argument). @@ -376,7 +378,7 @@ class TestCommon(TestCmd): print(output) self.fail_test() - def must_contain_all_lines(self, output, lines, title: str = "", find: Optional[Callable] = None) -> None: + def must_contain_all_lines(self, output, lines, title: str = "", find: Callable | None = None) -> None: """Ensures that the specified output string (first argument) contains all of the specified lines (second argument). @@ -427,7 +429,7 @@ class TestCommon(TestCmd): sys.stdout.write(output) self.fail_test() - def must_contain_any_line(self, output, lines, title: str = "", find: Optional[Callable] = None) -> None: + def must_contain_any_line(self, output, lines, title: str = "", find: Callable | None = None) -> None: """Ensures that the specified output string (first argument) contains at least one of the specified lines (second argument). @@ -451,7 +453,7 @@ class TestCommon(TestCmd): sys.stdout.write(output) self.fail_test() - def must_contain_exactly_lines(self, output, expect, title: str = "", find: Optional[Callable] = None) -> None: + def must_contain_exactly_lines(self, output, expect, title: str = "", find: Callable | None = None) -> None: """Ensures that the specified output string (first argument) contains all of the lines in the expected string (second argument) with none left over. @@ -499,7 +501,7 @@ class TestCommon(TestCmd): sys.stdout.flush() self.fail_test() - def must_contain_lines(self, lines, output, title: str = "", find: Optional[Callable] = None) -> None: + def must_contain_lines(self, lines, output, title: str = "", find: Callable | None = None) -> None: # Deprecated; retain for backwards compatibility. self.must_contain_all_lines(output, lines, title, find) @@ -540,7 +542,7 @@ class TestCommon(TestCmd): file, expect, mode: str = 'rb', - match: Optional[Callable] = None, + match: Callable | None = None, message: str = "", newline=None, ): @@ -569,7 +571,7 @@ class TestCommon(TestCmd): file, golden_file, mode: str = 'rb', - match: Optional[Callable] = None, + match: Callable | None = None, message: str = "", newline=None, ) -> None: @@ -609,7 +611,7 @@ class TestCommon(TestCmd): print(file_contents) self.fail_test() - def must_not_contain_any_line(self, output, lines, title: str = "", find: Optional[Callable] = None) -> None: + def must_not_contain_any_line(self, output, lines, title: str = "", find: Callable | None = None) -> None: """Ensures that the specified output string (first argument) does not contain any of the specified lines (second argument). @@ -635,7 +637,7 @@ class TestCommon(TestCmd): sys.stdout.write(output) self.fail_test() - def must_not_contain_lines(self, lines, output, title: str = "", find: Optional[Callable] = None) -> None: + def must_not_contain_lines(self, lines, output, title: str = "", find: Callable | None = None) -> None: self.must_not_contain_any_line(output, lines, title, find) def must_not_exist(self, *files) -> None: @@ -768,9 +770,9 @@ class TestCommon(TestCmd): def finish( self, popen, - stdout: Optional[str] = None, - stderr: Optional[str] = '', - status: Optional[int] = 0, + stdout: str | None = None, + stderr: str | None = '', + status: int | None = 0, **kw, ) -> None: """Finish and wait for the process being run. @@ -800,9 +802,9 @@ class TestCommon(TestCmd): self, options=None, arguments=None, - stdout: Optional[str] = None, - stderr: Optional[str] = '', - status: Optional[int] = 0, + stdout: str | None = None, + stderr: str | None = '', + status: int | None = 0, **kw, ) -> None: """Runs the program under test, checking that the test succeeded. diff --git a/testing/framework/TestSCons.py b/testing/framework/TestSCons.py index 243be75..806b596 100644 --- a/testing/framework/TestSCons.py +++ b/testing/framework/TestSCons.py @@ -34,6 +34,8 @@ from those classes, as well as any overridden or additional methods or attributes defined in this subclass. """ +from __future__ import annotations + import os import re import shutil @@ -42,7 +44,6 @@ import time import subprocess as sp import zipfile from collections import namedtuple -from typing import Optional, Tuple from TestCommon import * from TestCommon import __all__, _python_ @@ -865,7 +866,7 @@ class TestSCons(TestCommon): result.append(os.path.join(d, 'linux')) return result - def java_where_java_home(self, version=None) -> Optional[str]: + def java_where_java_home(self, version=None) -> str | None: """ Find path to what would be JAVA_HOME. SCons does not read JAVA_HOME from the environment, so deduce it. @@ -980,7 +981,7 @@ class TestSCons(TestCommon): return where_java - def java_where_javac(self, version=None) -> Tuple[str, str]: + def java_where_javac(self, version=None) -> tuple[str, str]: """ Find java compiler. Args: |