mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
change: convert lst.0.name to lst[0].name
This commit is contained in:
@@ -24,12 +24,18 @@ def convert_jmespath(raw: Text) -> Text:
|
|||||||
raw_list.append(f'"{item}"')
|
raw_list.append(f'"{item}"')
|
||||||
elif item.isdigit():
|
elif item.isdigit():
|
||||||
# convert lst.0.name to lst[0].name
|
# convert lst.0.name to lst[0].name
|
||||||
raw_list.append(f"[{item}]")
|
if len(raw_list) == 0:
|
||||||
|
raise exceptions.FileFormatError(
|
||||||
|
f"Invalid jmespath: {raw}, jmespath should startswith headers/body/status_code/cookies"
|
||||||
|
)
|
||||||
|
|
||||||
|
last_item = raw_list.pop()
|
||||||
|
item = f"{last_item}[{item}]"
|
||||||
|
raw_list.append(item)
|
||||||
else:
|
else:
|
||||||
raw_list.append(item)
|
raw_list.append(item)
|
||||||
|
|
||||||
# lst.[0].name => lst[0].name
|
return ".".join(raw_list)
|
||||||
return ".".join(raw_list).replace(".[", "[")
|
|
||||||
|
|
||||||
|
|
||||||
def convert_extractors(extractors: Union[List, Dict]) -> Dict:
|
def convert_extractors(extractors: Union[List, Dict]) -> Dict:
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ class FileFormatError(MyBaseError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestCaseFormatError(MyBaseError):
|
class TestCaseFormatError(FileFormatError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestSuiteFormatError(MyBaseError):
|
class TestSuiteFormatError(FileFormatError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from httprunner import compat
|
from httprunner import compat, exceptions
|
||||||
|
|
||||||
|
|
||||||
class TestCompat(unittest.TestCase):
|
class TestCompat(unittest.TestCase):
|
||||||
@@ -18,6 +18,8 @@ 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",
|
||||||
)
|
)
|
||||||
|
with self.assertRaises(exceptions.FileFormatError):
|
||||||
|
compat.convert_jmespath("2.buildings.0.building_id")
|
||||||
|
|
||||||
def test_convert_extractors(self):
|
def test_convert_extractors(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user