Skip to content

Commit 7b78bd7

Browse files
update test to support multiple write queries
1 parent 43fd0e3 commit 7b78bd7

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

test/code/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Text.
1919

2020
[,typeql]
2121
----
22-
#!test[<TYPE>[, reset] [, rollback] [, fail_at=<FAILURE>] [, count=<NUM>] [, jump=<LABEL>] [, name=<LABEL>]]
22+
#!test[<TYPE>[, reset] [, rollback] [, fail_at=<FAILURE>] [, documents] [, count=<NUM>] [, jump=<LABEL>] [, name=<LABEL>]]
2323
#{{
2424
<HIDDEN-QUERY>
2525
#}}
@@ -46,6 +46,7 @@ where
4646
* `reset` resets the database before running the test
4747
* `rollback` rolls backs the transaction instead of committing it
4848
* `fail_at=<FAILURE>` can be `runtime, commit`
49+
* `documents` specifies that the query is a fetch query, and the results are documents
4950
* `count=<NUM>` is an integer representing expected answer count
5051
* `name=<LABEL>` names the test
5152
* `jump=<LABEL>` is a label for the test (used for entrypoints and jumping around)

test/code/parser/parser.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import re
33
from dataclasses import dataclass
4-
from typing import List, Dict
4+
from typing import List, Dict, Tuple
55
import logging
66
logger = logging.getLogger('main')
77
# To see debug log, set logging level to debug in main.py
@@ -114,9 +114,17 @@ def retrieve_antora_include(self, include_str: str):
114114
if tags_match.startswith('tags='):
115115
tags = tags_match.split('=')[1].split(';')
116116

117+
line_nrs: Tuple[str, str] = (None, None)
118+
if tags_match.startswith('lines='):
119+
line_nrs = tags_match.split('=')[1].split('..')
120+
117121
# Read tagged lines from Antora include
118122
with open(file_path, 'r', encoding='utf-8') as f:
119123
lines = f.readlines()
124+
if line_nrs[1]:
125+
lines = lines[:int(line_nrs[1])]
126+
if line_nrs[0]:
127+
lines = lines[int(line_nrs[0]) - 1:]
120128

121129
tagged_lines: Dict[str, List[str]] = {}
122130
current_tag = None
@@ -148,10 +156,13 @@ def retrieve_antora_include(self, include_str: str):
148156
logging.debug(f"... finished scanning included file, resolved tags: {tagged_lines}")
149157

150158
output_lines = []
151-
for tag in tags:
152-
if tagged_lines.get(tag) is None:
153-
self.error(f"Include is missing tag {tag}")
154-
output_lines += tagged_lines[tag]
159+
if tags:
160+
for tag in tags:
161+
if tagged_lines.get(tag) is None:
162+
self.error(f"Include is missing tag {tag}")
163+
output_lines += tagged_lines[tag]
164+
else:
165+
output_lines = lines
155166

156167
return output_lines
157168

test/code/runners/typeql_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def run_failing_queries(self, queries: List[str], type: TransactionType) -> str:
9393
return FailureMode.NoFailure
9494

9595
def run_transaction(self, queries: List[str], type: TransactionType, rollback=False) -> Union[int, None]:
96+
queries = [q for qs in queries for q in qs.split('end;') if q.strip()]
9697
with self.driver.transaction(self.db, type) as tx:
9798
try:
9899
for q in queries:
@@ -236,4 +237,4 @@ def try_tests(self, parsed_tests: List[ParsedTest], adoc_path: str, file_config:
236237

237238
current_test_index += 1
238239

239-
return None
240+
return None

0 commit comments

Comments
 (0)