Skip to content

Commit 5d13f30

Browse files
committed
Add TestKit protocol messages for subtests
1 parent 1e797af commit 5d13f30

File tree

4 files changed

+114
-79
lines changed

4 files changed

+114
-79
lines changed

testkitbackend/_async/requests.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
import re
2222
import warnings
2323

24-
import pytz
25-
2624
import neo4j
2725
from neo4j._async_compat.util import AsyncUtil
2826

2927
from .. import (
3028
fromtestkit,
29+
test_subtest_skips,
3130
totestkit,
3231
)
3332
from ..exceptions import MarkdAsDriverException
@@ -52,54 +51,44 @@ def load_config():
5251
SKIPPED_TESTS, FEATURES = load_config()
5352

5453

55-
async def StartTest(backend, data):
54+
def _get_skip_reason(test_name):
5655
for skip_pattern, reason in SKIPPED_TESTS.items():
5756
if skip_pattern[0] == skip_pattern[-1] == "'":
58-
match = skip_pattern[1:-1] == data["testName"]
57+
match = skip_pattern[1:-1] == test_name
5958
else:
60-
match = re.match(skip_pattern, data["testName"])
59+
match = re.match(skip_pattern, test_name)
6160
if match:
61+
return reason
62+
63+
64+
async def StartTest(backend, data):
65+
test_name = data["testName"]
66+
reason = _get_skip_reason(test_name)
67+
if reason is not None:
68+
if reason.startswith("test_subtest_skips."):
69+
await backend.send_response("RunSubTests", {})
70+
else:
6271
await backend.send_response("SkipTest", {"reason": reason})
63-
break
6472
else:
6573
await backend.send_response("RunTest", {})
6674

6775

68-
async def GetFeatures(backend, data):
69-
await backend.send_response("FeatureList", {"features": FEATURES})
76+
async def StartSubTest(backend, data):
77+
test_name = data["testName"]
78+
subtest_args = data["subtestArguments"]
79+
subtest_args.mark_all_as_read(recursive=True)
80+
reason = _get_skip_reason(test_name)
81+
assert reason and reason.startswith("test_subtest_skips.") or print(reason)
82+
func = getattr(test_subtest_skips, reason[19:])
83+
reason = func(**subtest_args)
84+
if reason is not None:
85+
await backend.send_response("SkipTest", {"reason": reason})
86+
else:
87+
await backend.send_response("RunTest", {})
7088

7189

72-
async def CheckSystemSupport(backend, data):
73-
type_ = data["type"]
74-
meta = data["meta"]
75-
if type_ == "Timezone":
76-
timezone = meta["timezone"]
77-
# We could do this automatically, but with an explicit black list we
78-
# make sure we know what we test and what we don't.
79-
80-
# await backend.send_response("SystemSupport", {
81-
# "supported": timezone in pytz.common_timezones_set
82-
# })
83-
84-
await backend.send_response("SystemSupport", {
85-
"supported": timezone not in {
86-
"SystemV/AST4",
87-
"SystemV/AST4ADT",
88-
"SystemV/CST6",
89-
"SystemV/CST6CDT",
90-
"SystemV/EST5",
91-
"SystemV/EST5EDT",
92-
"SystemV/HST10",
93-
"SystemV/MST7",
94-
"SystemV/MST7MDT",
95-
"SystemV/PST8",
96-
"SystemV/PST8PDT",
97-
"SystemV/YST9",
98-
"SystemV/YST9YDT",
99-
}
100-
})
101-
else:
102-
raise NotImplementedError("Unknown SystemSupportType: %s" % type_)
90+
async def GetFeatures(backend, data):
91+
await backend.send_response("FeatureList", {"features": FEATURES})
10392

10493

10594
async def NewDriver(backend, data):

testkitbackend/_sync/requests.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
import re
2222
import warnings
2323

24-
import pytz
25-
2624
import neo4j
2725
from neo4j._async_compat.util import Util
2826

2927
from .. import (
3028
fromtestkit,
29+
test_subtest_skips,
3130
totestkit,
3231
)
3332
from ..exceptions import MarkdAsDriverException
@@ -52,54 +51,44 @@ def load_config():
5251
SKIPPED_TESTS, FEATURES = load_config()
5352

5453

55-
def StartTest(backend, data):
54+
def _get_skip_reason(test_name):
5655
for skip_pattern, reason in SKIPPED_TESTS.items():
5756
if skip_pattern[0] == skip_pattern[-1] == "'":
58-
match = skip_pattern[1:-1] == data["testName"]
57+
match = skip_pattern[1:-1] == test_name
5958
else:
60-
match = re.match(skip_pattern, data["testName"])
59+
match = re.match(skip_pattern, test_name)
6160
if match:
61+
return reason
62+
63+
64+
def StartTest(backend, data):
65+
test_name = data["testName"]
66+
reason = _get_skip_reason(test_name)
67+
if reason is not None:
68+
if reason.startswith("test_subtest_skips."):
69+
backend.send_response("RunSubTests", {})
70+
else:
6271
backend.send_response("SkipTest", {"reason": reason})
63-
break
6472
else:
6573
backend.send_response("RunTest", {})
6674

6775

68-
def GetFeatures(backend, data):
69-
backend.send_response("FeatureList", {"features": FEATURES})
76+
def StartSubTest(backend, data):
77+
test_name = data["testName"]
78+
subtest_args = data["subtestArguments"]
79+
subtest_args.mark_all_as_read(recursive=True)
80+
reason = _get_skip_reason(test_name)
81+
assert reason and reason.startswith("test_subtest_skips.") or print(reason)
82+
func = getattr(test_subtest_skips, reason[19:])
83+
reason = func(**subtest_args)
84+
if reason is not None:
85+
backend.send_response("SkipTest", {"reason": reason})
86+
else:
87+
backend.send_response("RunTest", {})
7088

7189

72-
def CheckSystemSupport(backend, data):
73-
type_ = data["type"]
74-
meta = data["meta"]
75-
if type_ == "Timezone":
76-
timezone = meta["timezone"]
77-
# We could do this automatically, but with an explicit black list we
78-
# make sure we know what we test and what we don't.
79-
80-
# await backend.send_response("SystemSupport", {
81-
# "supported": timezone in pytz.common_timezones_set
82-
# })
83-
84-
backend.send_response("SystemSupport", {
85-
"supported": timezone not in {
86-
"SystemV/AST4",
87-
"SystemV/AST4ADT",
88-
"SystemV/CST6",
89-
"SystemV/CST6CDT",
90-
"SystemV/EST5",
91-
"SystemV/EST5EDT",
92-
"SystemV/HST10",
93-
"SystemV/MST7",
94-
"SystemV/MST7MDT",
95-
"SystemV/PST8",
96-
"SystemV/PST8PDT",
97-
"SystemV/YST9",
98-
"SystemV/YST9YDT",
99-
}
100-
})
101-
else:
102-
raise NotImplementedError("Unknown SystemSupportType: %s" % type_)
90+
def GetFeatures(backend, data):
91+
backend.send_response("FeatureList", {"features": FEATURES})
10392

10493

10594
def NewDriver(backend, data):

testkitbackend/test_config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
"'stub.session_run_parameters.test_session_run_parameters.TestSessionRunParameters.test_empty_query'":
1010
"Driver rejects empty queries before sending it to the server",
1111
"'stub.server_side_routing.test_server_side_routing.TestServerSideRouting.test_direct_connection_with_url_params'":
12-
"Driver emits deprecation warning. Behavior will be unified in 6.0."
12+
"Driver emits deprecation warning. Behavior will be unified in 6.0.",
13+
"neo4j.datatypes.test_temporal_types.TestDataTypes.test_should_echo_all_timezone_ids":
14+
"test_subtest_skips.tz_id",
15+
"neo4j.datatypes.test_temporal_types.TestDataTypes.test_date_time_cypher_created_tz_id":
16+
"test_subtest_skips.tz_id"
1317
},
1418
"features": {
1519
"Feature:API:ConnectionAcquisitionTimeout": true,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) "Neo4j"
2+
# Neo4j Sweden AB [http://neo4j.com]
3+
#
4+
# This file is part of Neo4j.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
19+
"""
20+
Functions to decide whether to run a subtest or not.
21+
22+
They take the subtest parameters as arguments and return
23+
- a string with describing the reason why the subtest should be skipped
24+
- None if the subtest should be run
25+
"""
26+
27+
28+
def tz_id(**params):
29+
# We could do this automatically, but with an explicit black list we
30+
# make sure we know what we test and what we don't.
31+
# if params["tz_id"] not in pytz.common_timezones_set:
32+
# return (
33+
# "timezone id %s is not supported by the system" % params["tz_id"]
34+
# )
35+
36+
if params["tz_id"] in {
37+
"SystemV/AST4",
38+
"SystemV/AST4ADT",
39+
"SystemV/CST6",
40+
"SystemV/CST6CDT",
41+
"SystemV/EST5",
42+
"SystemV/EST5EDT",
43+
"SystemV/HST10",
44+
"SystemV/MST7",
45+
"SystemV/MST7MDT",
46+
"SystemV/PST8",
47+
"SystemV/PST8PDT",
48+
"SystemV/YST9",
49+
"SystemV/YST9YDT",
50+
}:
51+
return (
52+
"timezone id %s is not supported by the system" % params["tz_id"]
53+
)

0 commit comments

Comments
 (0)