robotframework-jsonquery 1.0.1__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robotframework_jsonquery-1.0.3/JsonQuery/JsonQuery.py +70 -0
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/PKG-INFO +12 -4
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/README.md +6 -3
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/pyproject.toml +7 -1
- robotframework_jsonquery-1.0.1/JsonQuery/JsonQuery.py +0 -57
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/JsonQuery/__init__.py +0 -0
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/JsonQuery/errors.py +0 -0
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/JsonQuery/module_importer.py +0 -0
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/JsonQuery/queries.py +0 -0
- {robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/LICENSE +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Library for handling json queries using different backends
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from types import ModuleType
|
|
6
|
+
|
|
7
|
+
from importlib import import_module
|
|
8
|
+
|
|
9
|
+
from JsonQuery.queries import JmesPath, JsonPathNg, Querable
|
|
10
|
+
|
|
11
|
+
jsonParserModule = {
|
|
12
|
+
"jmespath": JmesPath,
|
|
13
|
+
"jsonpath_ng.ext": JsonPathNg,
|
|
14
|
+
"jsonpath_ng": JsonPathNg,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class JsonQuery:
|
|
19
|
+
ROBOT_LIBRARY_SCOPE = "SUITE"
|
|
20
|
+
|
|
21
|
+
def __init__(self, query_module: str = "jmespath") -> None:
|
|
22
|
+
"""Initialize library with a module name used to parse syntax for a specific implementation
|
|
23
|
+
|
|
24
|
+
Example:
|
|
25
|
+
| =Settings= |
|
|
26
|
+
| Libraray | JsonQuery | jmespath | # initialize library with jmespath library |
|
|
27
|
+
| Libraray | JsonQuery | jsonpath_ng.ext | # initialize library with jsonpath_ng.ext (extended version which handles filtering, etc.) |
|
|
28
|
+
"""
|
|
29
|
+
self.imported_module: ModuleType = import_module(query_module)
|
|
30
|
+
self.qmodule: Querable = jsonParserModule[query_module](self.imported_module)
|
|
31
|
+
|
|
32
|
+
def get_query_module(self) -> str:
|
|
33
|
+
"""Get module name loaded in initialization
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
| =Settings= |
|
|
37
|
+
| Library | JsonQuery | `jmespath` |
|
|
38
|
+
| |
|
|
39
|
+
| =Keywords= |
|
|
40
|
+
| ... |
|
|
41
|
+
| ${module_name} | Get Module Name |
|
|
42
|
+
| Should Be Equal | `jmespath` | ${module_name} |
|
|
43
|
+
"""
|
|
44
|
+
return f"{self.imported_module.__name__}"
|
|
45
|
+
|
|
46
|
+
def read_json_file(self, file_path: str) -> dict:
|
|
47
|
+
"""Read json file using standard json module and return data in a dict format
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
| ... |
|
|
51
|
+
| =Test Cases= |
|
|
52
|
+
| Read Sample File |
|
|
53
|
+
| | ${content} | Read Json File | /path/to/the/json/file.json \ \ \ # unix-like path |
|
|
54
|
+
| ... |
|
|
55
|
+
"""
|
|
56
|
+
with open(file_path, "r") as fl:
|
|
57
|
+
content = json.load(fl)
|
|
58
|
+
return content
|
|
59
|
+
|
|
60
|
+
def query_json(self, document: dict, expression: str) -> dict:
|
|
61
|
+
"""Query json document/dictionary with a given expression using module of choice
|
|
62
|
+
|
|
63
|
+
| ... |
|
|
64
|
+
| =Keywords= |
|
|
65
|
+
| ... |
|
|
66
|
+
| ${content} | Read Json File | /path/to/file.json |
|
|
67
|
+
| ${query_result} | Query Json | ${content} | locations[?state == 'WA'].name | sort(@) | {WashingtonCities: join(', ', @)} | #jmespath syntax |
|
|
68
|
+
"""
|
|
69
|
+
result = self.qmodule.search(expression, document)
|
|
70
|
+
return result
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: robotframework-jsonquery
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Robot Framework library for parsing json files
|
|
5
|
+
Home-page: https://github.com/otemek/robotframework-jsonquery
|
|
5
6
|
License: MIT
|
|
6
7
|
Author: tom bsc
|
|
7
8
|
Author-email: etombsc@gmail.com
|
|
8
9
|
Requires-Python: >=3.9,<4.0
|
|
10
|
+
Classifier: Framework :: Robot Framework :: Library
|
|
11
|
+
Classifier: Framework :: Robot Framework :: Tool
|
|
9
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
13
|
Classifier: Programming Language :: Python :: 3
|
|
11
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -14,9 +17,11 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
14
17
|
Requires-Dist: jmespath (<2)
|
|
15
18
|
Requires-Dist: jsonpath_ng (<2)
|
|
16
19
|
Requires-Dist: robotframework
|
|
20
|
+
Project-URL: Documentation, https://otemek.github.io/robotframework-jsonquery/JsonQuery.html
|
|
21
|
+
Project-URL: Repository, https://github.com/otemek/robotframework-jsonquery
|
|
17
22
|
Description-Content-Type: text/markdown
|
|
18
23
|
|
|
19
|
-
# robotframework-jsonquery [](https://github.com/otemek/robotframework-jsonquery/actions/workflows/robotlib.yml)
|
|
24
|
+
# robotframework-jsonquery [](https://github.com/otemek/robotframework-jsonquery/actions/workflows/robotlib.yml) [](https://badge.fury.io/py/robotframework-jsonquery)
|
|
20
25
|
Simple wrapper for libraries used to query json files with different query language implementations
|
|
21
26
|
- jsonpath-ng.ext (extended version with e.g. filters)
|
|
22
27
|
- jsonpath-ng
|
|
@@ -30,7 +35,7 @@ Library JsonQuery jsonpath-ng.ext
|
|
|
30
35
|
*** Test Cases ***
|
|
31
36
|
Read and query json file
|
|
32
37
|
${file} Read Json File sample.json
|
|
33
|
-
Query Json ${file} friends[?(@.id>1)] #jsonpath-ng.ext syntax
|
|
38
|
+
${result} Query Json ${file} friends[?(@.id>1)] #jsonpath-ng.ext syntax
|
|
34
39
|
|
|
35
40
|
```
|
|
36
41
|
|
|
@@ -41,7 +46,10 @@ Library JsonQuery jmespath
|
|
|
41
46
|
*** Test Cases ***
|
|
42
47
|
Read and query json file
|
|
43
48
|
${file} Read Json File sample.json
|
|
44
|
-
Query Json ${file} friends[?id>`1`] #jmespath syntax
|
|
49
|
+
${result} Query Json ${file} friends[?id>`1`] #jmespath syntax
|
|
45
50
|
|
|
46
51
|
```
|
|
47
52
|
|
|
53
|
+
## Documentation
|
|
54
|
+
- [Keyword Documentation](https://otemek.github.io/robotframework-jsonquery/JsonQuery.html)
|
|
55
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# robotframework-jsonquery [](https://github.com/otemek/robotframework-jsonquery/actions/workflows/robotlib.yml)
|
|
1
|
+
# robotframework-jsonquery [](https://github.com/otemek/robotframework-jsonquery/actions/workflows/robotlib.yml) [](https://badge.fury.io/py/robotframework-jsonquery)
|
|
2
2
|
Simple wrapper for libraries used to query json files with different query language implementations
|
|
3
3
|
- jsonpath-ng.ext (extended version with e.g. filters)
|
|
4
4
|
- jsonpath-ng
|
|
@@ -12,7 +12,7 @@ Library JsonQuery jsonpath-ng.ext
|
|
|
12
12
|
*** Test Cases ***
|
|
13
13
|
Read and query json file
|
|
14
14
|
${file} Read Json File sample.json
|
|
15
|
-
Query Json ${file} friends[?(@.id>1)] #jsonpath-ng.ext syntax
|
|
15
|
+
${result} Query Json ${file} friends[?(@.id>1)] #jsonpath-ng.ext syntax
|
|
16
16
|
|
|
17
17
|
```
|
|
18
18
|
|
|
@@ -23,6 +23,9 @@ Library JsonQuery jmespath
|
|
|
23
23
|
*** Test Cases ***
|
|
24
24
|
Read and query json file
|
|
25
25
|
${file} Read Json File sample.json
|
|
26
|
-
Query Json ${file} friends[?id>`1`] #jmespath syntax
|
|
26
|
+
${result} Query Json ${file} friends[?id>`1`] #jmespath syntax
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
+
|
|
30
|
+
## Documentation
|
|
31
|
+
- [Keyword Documentation](https://otemek.github.io/robotframework-jsonquery/JsonQuery.html)
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "robotframework-jsonquery"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.3"
|
|
4
4
|
description = "Robot Framework library for parsing json files"
|
|
5
5
|
authors = ["tom bsc <etombsc@gmail.com>"]
|
|
6
|
+
repository = "https://github.com/otemek/robotframework-jsonquery"
|
|
7
|
+
documentation = "https://otemek.github.io/robotframework-jsonquery/JsonQuery.html"
|
|
6
8
|
license = "MIT"
|
|
7
9
|
readme = "README.md"
|
|
8
10
|
packages = [{include = "JsonQuery"}]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Framework :: Robot Framework :: Library",
|
|
13
|
+
"Framework :: Robot Framework :: Tool"
|
|
14
|
+
]
|
|
9
15
|
|
|
10
16
|
[tool.poetry.dependencies]
|
|
11
17
|
python = "^3.9"
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"""Library for handling json queries using different backends
|
|
2
|
-
"""
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
from types import ModuleType
|
|
6
|
-
|
|
7
|
-
from importlib import import_module
|
|
8
|
-
|
|
9
|
-
from JsonQuery.queries import JmesPath, JsonPathNg, Querable
|
|
10
|
-
|
|
11
|
-
jsonParserModule = {
|
|
12
|
-
"jmespath": JmesPath,
|
|
13
|
-
"jsonpath_ng.ext": JsonPathNg,
|
|
14
|
-
"jsonpath_ng": JsonPathNg
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class JsonQuery:
|
|
19
|
-
ROBOT_LIBRARY_SCOPE = "SUITE"
|
|
20
|
-
|
|
21
|
-
def __init__(self, query_module: str = "jmespath") -> None:
|
|
22
|
-
self.imported_module: ModuleType = import_module(query_module)
|
|
23
|
-
self.qmodule: Querable = jsonParserModule[query_module](self.imported_module)
|
|
24
|
-
|
|
25
|
-
def get_query_module(self) -> str:
|
|
26
|
-
"""Get module name loaded on initialization
|
|
27
|
-
|
|
28
|
-
Returns:
|
|
29
|
-
str: module name, e.g. jmespath, jsonpath_ng.ext, jsonpath_ng
|
|
30
|
-
"""
|
|
31
|
-
return f"{self.imported_module.__name__}"
|
|
32
|
-
|
|
33
|
-
def read_json_file(self, file_path: str) -> dict:
|
|
34
|
-
"""Read json file
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
file_path (str): Path to json file, e.g. /tmp/some/file.json
|
|
38
|
-
|
|
39
|
-
Returns:
|
|
40
|
-
dict: file content in a dict format, ready to be parsed
|
|
41
|
-
"""
|
|
42
|
-
with open(file_path, "r") as fl:
|
|
43
|
-
content = json.load(fl)
|
|
44
|
-
return content
|
|
45
|
-
|
|
46
|
-
def query_json(self, document: dict, expression: str) -> dict:
|
|
47
|
-
"""Query json doucment/dictionary with a given expression using module of choice
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
document (dict): Content of a json file
|
|
51
|
-
expression (str): expression used to query document using loaded module
|
|
52
|
-
|
|
53
|
-
Returns:
|
|
54
|
-
dict: expression result
|
|
55
|
-
"""
|
|
56
|
-
result = self.qmodule.search(expression, document)
|
|
57
|
-
return result
|
|
File without changes
|
|
File without changes
|
{robotframework_jsonquery-1.0.1 → robotframework_jsonquery-1.0.3}/JsonQuery/module_importer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|