mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
Validate JSON testset format
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
__title__ = 'HttpRunner'
|
__title__ = 'HttpRunner'
|
||||||
__description__ = 'One-stop solution for HTTP(S) testing.'
|
__description__ = 'One-stop solution for HTTP(S) testing.'
|
||||||
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
||||||
__version__ = '1.2.3'
|
__version__ = '1.3.0'
|
||||||
__author__ = 'debugtalk'
|
__author__ = 'debugtalk'
|
||||||
__author_email__ = 'mail@debugtalk.com'
|
__author_email__ = 'mail@debugtalk.com'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
|
|||||||
+8
-1
@@ -8,7 +8,7 @@ from httprunner import logger
|
|||||||
from httprunner.__about__ import __version__
|
from httprunner.__about__ import __version__
|
||||||
from httprunner.task import HttpRunner
|
from httprunner.task import HttpRunner
|
||||||
from httprunner.utils import (create_scaffold, load_dot_env_file, print_output,
|
from httprunner.utils import (create_scaffold, load_dot_env_file, print_output,
|
||||||
string_type)
|
string_type, validate_json_file)
|
||||||
|
|
||||||
|
|
||||||
def main_hrun():
|
def main_hrun():
|
||||||
@@ -40,6 +40,9 @@ def main_hrun():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--startproject',
|
'--startproject',
|
||||||
help="Specify new project name.")
|
help="Specify new project name.")
|
||||||
|
parser.add_argument(
|
||||||
|
'--validate', nargs='*',
|
||||||
|
help="Validate JSON testset format.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
logger.setup_logger(args.log_level)
|
logger.setup_logger(args.log_level)
|
||||||
@@ -48,6 +51,10 @@ def main_hrun():
|
|||||||
logger.color_print("{}".format(__version__), "GREEN")
|
logger.color_print("{}".format(__version__), "GREEN")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
if args.validate:
|
||||||
|
validate_json_file(args.validate)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
dot_env_path = args.dot_env_path or os.path.join(os.getcwd(), ".env")
|
dot_env_path = args.dot_env_path or os.path.join(os.getcwd(), ".env")
|
||||||
if dot_env_path:
|
if dot_env_path:
|
||||||
load_dot_env_file(dot_env_path)
|
load_dot_env_file(dot_env_path)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import hmac
|
|||||||
import imp
|
import imp
|
||||||
import importlib
|
import importlib
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
@@ -421,3 +422,21 @@ def load_dot_env_file(path):
|
|||||||
variable, value = line.split("=")
|
variable, value = line.split("=")
|
||||||
os.environ[variable] = value
|
os.environ[variable] = value
|
||||||
logger.log_debug("Loaded variable: {}".format(variable))
|
logger.log_debug("Loaded variable: {}".format(variable))
|
||||||
|
|
||||||
|
def validate_json_file(file_list):
|
||||||
|
""" validate JSON testset format
|
||||||
|
"""
|
||||||
|
for json_file in set(file_list):
|
||||||
|
if not json_file.endswith(".json"):
|
||||||
|
logger.log_warning("Only JSON file format can be validated.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.color_print("start to validate JSON file: {}".format(json_file), "GREEN")
|
||||||
|
|
||||||
|
with open(json_file) as stream:
|
||||||
|
try:
|
||||||
|
json.load(stream)
|
||||||
|
except ValueError as e:
|
||||||
|
raise SystemExit(e)
|
||||||
|
|
||||||
|
print("OK")
|
||||||
|
|||||||
Reference in New Issue
Block a user