-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON variable file support (#4542)
Implements #4532. Documentation still missing.
- Loading branch information
Showing
14 changed files
with
263 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
*** Settings *** | ||
Suite Setup Run Tests --variablefile ${VARDIR}/cli.json -V ${VARDIR}/cli2.json --pythonpath ${VARDIR} | ||
... variables/json_variable_file.robot | ||
Resource atest_resource.robot | ||
|
||
*** Variables *** | ||
${VARDIR} ${DATADIR}/../testresources/res_and_var_files | ||
|
||
*** Test Cases *** | ||
Valid JSON file | ||
Check Test Case ${TESTNAME} | ||
|
||
Valid JSON file with uper case extension | ||
Check Test Case ${TESTNAME} | ||
|
||
Non-ASCII strings | ||
Check Test Case ${TESTNAME} | ||
|
||
Dictionary is dot-accessible | ||
Check Test Case ${TESTNAME} | ||
|
||
Nested dictionary is dot-accessible | ||
Check Test Case ${TESTNAME} | ||
|
||
Dictionary inside list is dot-accessible | ||
Check Test Case ${TESTNAME} | ||
|
||
JSON file in PYTHONPATH | ||
Check Test Case ${TESTNAME} | ||
|
||
Import Variables keyword | ||
Check Test Case ${TESTNAME} | ||
|
||
JSON file from CLI | ||
Check Test Case ${TESTNAME} | ||
|
||
Invalid JSON file | ||
Processing should have failed 0 4 invalid.json | ||
... ${EMPTY} | ||
... JSONDecodeError* | ||
|
||
Non-mapping JSON file | ||
Processing should have failed 1 5 non_dict.json | ||
... ${EMPTY} | ||
... JSON variable file must be a mapping, got list. | ||
|
||
JSON files do not accept arguments | ||
Processing should have failed 2 6 valid.json | ||
... with arguments ? arguments | not | accepted ?${SPACE} | ||
... JSON variable files do not accept arguments. | ||
|
||
Non-existing JSON file | ||
Importing should have failed 3 7 | ||
... Variable file 'non_existing.Json' does not exist. | ||
|
||
JSON with invalid encoding | ||
Processing should have failed 4 8 invalid_encoding.json | ||
... ${EMPTY} | ||
... UnicodeDecodeError* | ||
|
||
*** Keywords *** | ||
Processing should have failed | ||
[Arguments] ${index} ${lineno} ${file} ${arguments} ${error} | ||
${path} = Normalize Path ${DATADIR}/variables/${file} | ||
Importing should have failed ${index} ${lineno} | ||
... Processing variable file '${path}' ${arguments}failed: | ||
... ${error} | ||
|
||
Importing should have failed | ||
[Arguments] ${index} ${lineno} @{error} | ||
Error In File ${index} variables/json_variable_file.robot ${lineno} | ||
... @{error} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: "jack" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"encoding": "latin-1", | ||
"expected": "utf-8", | ||
"non-ascii": "hyvää yötä!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
*** Settings *** | ||
Variables valid.json | ||
Variables pythonpath.json | ||
Variables ./invalid.json | ||
Variables ..${/}variables${/}non_dict.json | ||
Variables valid.json arguments not accepted | ||
Variables non_existing.Json | ||
Variables invalid_encoding.json | ||
Variables valid3.JSON | ||
Test Template Should Be Equal | ||
|
||
*** Variables *** | ||
@{EXPECTED LIST} one ${2} | ||
&{EXPECTED DICT} a=1 b=${2} 3=${EXPECTED LIST} key with spaces=value with spaces | ||
|
||
|
||
*** Test Cases *** | ||
Valid JSON file | ||
${STRING} Hello, YAML! | ||
${INTEGER} ${42} | ||
${FLOAT} ${3.14} | ||
${LIST} ${EXPECTED LIST} | ||
${DICT} ${EXPECTED DICT} | ||
${BOOL} ${TRUE} | ||
${NULL} ${NULL} | ||
|
||
Valid JSON file with uper case extension | ||
${STRING IN JSON} Hello, YAML! | ||
${INTEGER IN JSON} ${42} | ||
${FLOAT IN JSON} ${3.14} | ||
${LIST IN JSON} ${EXPECTED LIST} | ||
${DICT IN JSON} ${EXPECTED DICT} | ||
${BOOL IN JSON} ${TRUE} | ||
${NULL IN JSON} ${NULL} | ||
|
||
Non-ASCII strings | ||
${NON} äscii | ||
${NÖN} äscii | ||
|
||
Dictionary is dot-accessible | ||
${DICT.a} 1 | ||
${DICT.b} ${2} | ||
|
||
Nested dictionary is dot-accessible | ||
${NESTED DICT.dict} ${EXPECTED DICT} | ||
${NESTED DICT.dict.a} 1 | ||
${NESTED DICT.dict.b} ${2} | ||
|
||
Dictionary inside list is dot-accessible | ||
${LIST WITH DICT[1].key} value | ||
${LIST WITH DICT[2].dict} ${EXPECTED DICT} | ||
${LIST WITH DICT[2].nested[0].leaf} value | ||
|
||
JSON file in PYTHONPATH | ||
${JSON FILE IN PYTHONPATH} ${TRUE} | ||
|
||
Import Variables keyword | ||
[Setup] Import Variables ${CURDIR}/valid2.json | ||
${VALID 2} imported successfully | ||
|
||
JSON file from CLI | ||
${JSON FILE FROM CLI} woot! | ||
${JSON FILE FROM CLI2} kewl! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
"Not dictionary", | ||
{ | ||
"true": "top-level" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"string": "Hello, YAML!", | ||
"non": "äscii", | ||
"nön": "äscii", | ||
"integer": 42, | ||
"float": 3.14, | ||
"bool": true, | ||
"null": null, | ||
"list": [ | ||
"one", | ||
2 | ||
], | ||
"dict": { | ||
"a": "1", | ||
"b": 2, | ||
"3": [ | ||
"one", | ||
2 | ||
], | ||
"key with spaces": "value with spaces" | ||
}, | ||
"nested dict": { | ||
"dict": { | ||
"a": "1", | ||
"b": 2, | ||
"3": [ | ||
"one", | ||
2 | ||
], | ||
"key with spaces": "value with spaces" | ||
} | ||
}, | ||
"list with dict": [ | ||
"scalar", | ||
{ | ||
"key": "value" | ||
}, | ||
{ | ||
"dict": { | ||
"a": "1", | ||
"b": 2, | ||
"3": [ | ||
"one", | ||
2 | ||
], | ||
"key with spaces": "value with spaces" | ||
}, | ||
"nested": [ | ||
{ | ||
"leaf": "value" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"valid 2": "imported successfully" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"string in JSON": "Hello, YAML!", | ||
"integer in JSON": 42, | ||
"float in JSON": 3.14, | ||
"bool in JSON": true, | ||
"null in JSON": null, | ||
"list in JSON": [ | ||
"one", | ||
2 | ||
], | ||
"dict in JSON": { | ||
"a": "1", | ||
"b": 2, | ||
"3": [ | ||
"one", | ||
2 | ||
], | ||
"key with spaces": "value with spaces" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"json file from cli": "woot!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"json file from cli2": "kewl!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"json file in pythonpath": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters