-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Release preparation. - README updated. - polygon is excluded from the codebase. * Test utils separated. * load_json moved to tests/utils.
- Loading branch information
1 parent
bcd2b18
commit a96dc46
Showing
6 changed files
with
71 additions
and
78 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import json | ||
import os | ||
import re | ||
import shutil | ||
import sys | ||
|
||
|
||
def shell(command, exit_status=0): | ||
""" | ||
Run command through shell and return exit status if exit status of command run match with given exit status. | ||
Args: | ||
command: (str) Command string which runs through system shell. | ||
exit_status: (int) Expected exit status of given command run. | ||
Returns: actual_exit_status | ||
""" | ||
actual_exit_status = os.system(command) | ||
if actual_exit_status == exit_status: | ||
return 0 | ||
return actual_exit_status | ||
|
||
|
||
def validate_and_exit(expected_out_status=0, **kwargs): | ||
if all([arg == expected_out_status for arg in kwargs.values()]): | ||
# Expected status, OK | ||
sys.exit(0) | ||
else: | ||
# Failure | ||
print_console_centered("Summary Results") | ||
fail_count = 0 | ||
for component, exit_status in kwargs.items(): | ||
if exit_status != expected_out_status: | ||
print(f"{component} failed.") | ||
fail_count += 1 | ||
print_console_centered(f"{len(kwargs)-fail_count} success, {fail_count} failure") | ||
sys.exit(1) | ||
|
||
|
||
def print_console_centered(text: str, fill_char="="): | ||
w, _ = shutil.get_terminal_size((80, 20)) | ||
print(f" {text} ".center(w, fill_char)) | ||
|
||
|
||
def shell_capture(command, out_json=True): | ||
out = os.popen(command).read() | ||
if out_json: | ||
out = re.findall(r"{\s+.*\}", out, flags=re.MULTILINE | re.DOTALL)[0].replace("\n", "") | ||
return json.loads(out) | ||
return out |
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,67 +1,16 @@ | ||
import json | ||
import os | ||
import re | ||
import shutil | ||
import sys | ||
from typing import Dict | ||
|
||
from deepdiff import DeepDiff | ||
|
||
|
||
def load_json(path: str): | ||
with open(path, "r") as jf: | ||
content = json.load(jf) | ||
return content | ||
|
||
|
||
def shell(command, exit_status=0): | ||
""" | ||
Run command through shell and return exit status if exit status of command run match with given exit status. | ||
Args: | ||
command: (str) Command string which runs through system shell. | ||
exit_status: (int) Expected exit status of given command run. | ||
Returns: actual_exit_status | ||
""" | ||
actual_exit_status = os.system(command) | ||
if actual_exit_status == exit_status: | ||
return 0 | ||
return actual_exit_status | ||
|
||
|
||
def validate_and_exit(expected_out_status=0, **kwargs): | ||
if all([arg == expected_out_status for arg in kwargs.values()]): | ||
# Expected status, OK | ||
sys.exit(0) | ||
else: | ||
# Failure | ||
print_console_centered("Summary Results") | ||
fail_count = 0 | ||
for component, exit_status in kwargs.items(): | ||
if exit_status != expected_out_status: | ||
print(f"{component} failed.") | ||
fail_count += 1 | ||
print_console_centered(f"{len(kwargs)-fail_count} success, {fail_count} failure") | ||
sys.exit(1) | ||
|
||
|
||
def print_console_centered(text: str, fill_char="="): | ||
w, _ = shutil.get_terminal_size((80, 20)) | ||
print(f" {text} ".center(w, fill_char)) | ||
|
||
|
||
def assert_almost_equal(actual, desired, decimal=3, exclude_paths=None, **kwargs): | ||
# significant digits default value changed to 3 (from 5) due to variety in | ||
# results for different hardware architectures. | ||
diff = DeepDiff(actual, desired, significant_digits=decimal, exclude_paths=exclude_paths, **kwargs) | ||
assert diff == {}, f"Actual and Desired Dicts are not Almost Equal:\n {json.dumps(diff, indent=2, default=str)}" | ||
|
||
|
||
def shell_capture(command, out_json=True): | ||
out = os.popen(command).read() | ||
if out_json: | ||
out = re.findall(r"{\s+.*\}", out, flags=re.MULTILINE | re.DOTALL)[0].replace("\n", "") | ||
return json.loads(out) | ||
return out | ||
def load_json(path: str): | ||
with open(path, "r") as jf: | ||
content = json.load(jf) | ||
return content |