-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify unit tests to make it easier to read
- Loading branch information
1 parent
c77b6aa
commit 292ae0f
Showing
5 changed files
with
57 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Utility code to help with testing | ||
""" | ||
import base64 | ||
import json | ||
import numpy as np | ||
import os | ||
|
||
RELATIVE_TOLERANCE_FIT=1e-3 | ||
RELATIVE_TOLERANCE_PROB=1e-2 | ||
|
||
|
||
def _json_numpy_obj_hook(dct): | ||
""" | ||
Decodes a previously encoded numpy ndarray | ||
with proper shape and dtype | ||
:param dct: (dict) json encoded ndarray | ||
:return: (ndarray) if input was an encoded ndarray | ||
""" | ||
if isinstance(dct, dict) and '__ndarray__' in dct: | ||
data = base64.b64decode(dct['__ndarray__']) | ||
return np.frombuffer(data, dct['dtype']).reshape(dct['shape']) | ||
return dct | ||
|
||
|
||
def load_json(*args, **kwargs): | ||
"""Loads a json-encoded file-like object to a dictionary. | ||
Adds supports for decoding numpy arrays | ||
See json.load. | ||
""" | ||
kwargs.setdefault('object_hook', _json_numpy_obj_hook) | ||
return json.load(*args, **kwargs) | ||
|
||
|
||
def add_path(file_path, file_name): | ||
"""Sets the path for a file | ||
""" | ||
return os.path.join(file_path, file_name) |
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