-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #540 from robbrad/headless_refactor
Headless refactor
- Loading branch information
Showing
51 changed files
with
299 additions
and
185 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
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
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
34 changes: 15 additions & 19 deletions
34
uk_bin_collection/tests/step_defs/step_helpers/file_handler.py
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 |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import json | ||
import logging | ||
import os | ||
from jsonschema import validate, ValidationError | ||
from pathlib import Path | ||
|
||
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s') | ||
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s") | ||
|
||
def load_inputs_file(file_name): | ||
cwd = os.getcwd() | ||
with open(os.path.join(cwd, "uk_bin_collection", "tests", file_name)) as f: | ||
data = json.load(f) | ||
logging.info(f"{file_name} Input file loaded") | ||
return data | ||
# Dynamically compute the base path relative to this file's location | ||
current_file_path = Path(__file__).resolve() | ||
BASE_PATH = current_file_path.parent.parent.parent.parent / "tests" | ||
|
||
|
||
def load_schema_file(file_name): | ||
cwd = os.getcwd() | ||
with open(os.path.join(cwd, "uk_bin_collection", "tests", file_name)) as f: | ||
def load_json_file(file_name): | ||
file_path = BASE_PATH / file_name | ||
with open(file_path) as f: | ||
data = json.load(f) | ||
logging.info(f"{file_name} Schema file loaded") | ||
logging.info(f"{file_name} file loaded") | ||
return data | ||
|
||
|
||
def validate_json(json_str): | ||
try: | ||
json.loads(json_str) | ||
return json.loads(json_str) | ||
except ValueError as err: | ||
logging.info(f"The following error occured {err}") | ||
return False | ||
return True | ||
logging.error(f"JSON validation error: {err}") | ||
raise | ||
|
||
|
||
def validate_json_schema(json_str, schema): | ||
json_data = json.loads(json_str) | ||
json_data = validate_json(json_str) | ||
try: | ||
validate(instance=json_data, schema=schema) | ||
except ValidationError as err: | ||
logging.info(f"The following error occured {err}") | ||
logging.error(f"Schema validation error: {err}") | ||
logging.info(f"Data: {json_str}") | ||
logging.info(f"Schema: {schema}") | ||
return False | ||
raise | ||
return 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
Oops, something went wrong.