summaryrefslogtreecommitdiffstats
path: root/Lib/test/libregrtest/runtests.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/libregrtest/runtests.py')
-rw-r--r--Lib/test/libregrtest/runtests.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/Lib/test/libregrtest/runtests.py b/Lib/test/libregrtest/runtests.py
index b765ba5..edd7227 100644
--- a/Lib/test/libregrtest/runtests.py
+++ b/Lib/test/libregrtest/runtests.py
@@ -93,13 +93,17 @@ class RunTests:
python_cmd: tuple[str, ...] | None
randomize: bool
random_seed: int | str
- json_file: JsonFile | None
- def copy(self, **override):
+ def copy(self, **override) -> 'RunTests':
state = dataclasses.asdict(self)
state.update(override)
return RunTests(**state)
+ def create_worker_runtests(self, **override):
+ state = dataclasses.asdict(self)
+ state.update(override)
+ return WorkerRunTests(**state)
+
def get_match_tests(self, test_name) -> FilterTuple | None:
if self.match_tests_dict is not None:
return self.match_tests_dict.get(test_name, None)
@@ -120,13 +124,6 @@ class RunTests:
else:
yield from self.tests
- def as_json(self) -> StrJSON:
- return json.dumps(self, cls=_EncodeRunTests)
-
- @staticmethod
- def from_json(worker_json: StrJSON) -> 'RunTests':
- return json.loads(worker_json, object_hook=_decode_runtests)
-
def json_file_use_stdout(self) -> bool:
# Use STDOUT in two cases:
#
@@ -141,9 +138,21 @@ class RunTests:
)
+@dataclasses.dataclass(slots=True, frozen=True)
+class WorkerRunTests(RunTests):
+ json_file: JsonFile
+
+ def as_json(self) -> StrJSON:
+ return json.dumps(self, cls=_EncodeRunTests)
+
+ @staticmethod
+ def from_json(worker_json: StrJSON) -> 'WorkerRunTests':
+ return json.loads(worker_json, object_hook=_decode_runtests)
+
+
class _EncodeRunTests(json.JSONEncoder):
def default(self, o: Any) -> dict[str, Any]:
- if isinstance(o, RunTests):
+ if isinstance(o, WorkerRunTests):
result = dataclasses.asdict(o)
result["__runtests__"] = True
return result
@@ -158,6 +167,6 @@ def _decode_runtests(data: dict[str, Any]) -> RunTests | dict[str, Any]:
data['hunt_refleak'] = HuntRefleak(**data['hunt_refleak'])
if data['json_file']:
data['json_file'] = JsonFile(**data['json_file'])
- return RunTests(**data)
+ return WorkerRunTests(**data)
else:
return data