mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix: keep negative index in jmespath unchanged when converting pytest files
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## 3.1.8 (2022-03-22)
|
## 3.1.8 (2022-03-22)
|
||||||
|
|
||||||
|
- fix: keep negative index in jmespath unchanged when converting pytest files, e.g. body.users[-1]
|
||||||
- change: load yaml file with FullLoader
|
- change: load yaml file with FullLoader
|
||||||
|
|
||||||
## 3.1.7 (2022-03-22)
|
## 3.1.7 (2022-03-22)
|
||||||
|
|||||||
@@ -58,9 +58,11 @@ def _convert_jmespath(raw: Text) -> Text:
|
|||||||
|
|
||||||
raw_list = []
|
raw_list = []
|
||||||
for item in raw.split("."):
|
for item in raw.split("."):
|
||||||
if "-" in item:
|
if "-" in item and "[-" not in item:
|
||||||
# add quotes for field with separator
|
# add quotes for field with separator
|
||||||
# e.g. headers.Content-Type => headers."Content-Type"
|
# e.g. headers.Content-Type => headers."Content-Type"
|
||||||
|
# also need to avoid replacing negative index in jmespath
|
||||||
|
# e.g. body.users[-1] => body.users[-1], keep unchanged
|
||||||
item = item.strip('"')
|
item = item.strip('"')
|
||||||
raw_list.append(f'"{item}"')
|
raw_list.append(f'"{item}"')
|
||||||
elif item.isdigit():
|
elif item.isdigit():
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ class TestCompat(unittest.TestCase):
|
|||||||
compat._convert_jmespath("body.data.buildings.0.building_id"),
|
compat._convert_jmespath("body.data.buildings.0.building_id"),
|
||||||
"body.data.buildings[0].building_id",
|
"body.data.buildings[0].building_id",
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
compat._convert_jmespath("body.users[-1]"),
|
||||||
|
"body.users[-1]",
|
||||||
|
)
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
compat._convert_jmespath("2.buildings.0.building_id")
|
compat._convert_jmespath("2.buildings.0.building_id")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user