-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
130 changed files
with
413 additions
and
587 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# encoding: utf-8 | ||
|
||
"""JSON cube-response source files for testing purposes.""" | ||
|
||
import json | ||
import os | ||
|
||
CUBES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cubes') | ||
|
||
|
||
class LazyCubeResponseLoader(object): | ||
"""Loads and caches cube-responses by name from fixture directory. | ||
Provides access to all the cube-response fixtures in a directory by | ||
a standardized mapping of the file name, e.g. cat-x-cat.json is available | ||
as the `.CAT_X_CAT` attribute of the loader. | ||
The fixture directory is specified relative to this (fixture root) | ||
directory. | ||
""" | ||
|
||
def __init__(self, relpath): | ||
self._relpath = relpath | ||
self._cache = {} | ||
|
||
def __getattr__(self, fixture_name): | ||
"""Return cube-dict from JSON file mapping to *fixture_name*. | ||
A *fixture_name* like 'CAT_X_CAT' will map to the JSON file | ||
'cat-x-cat.json' in the directory specified on construction. | ||
""" | ||
if fixture_name not in self._cache: | ||
self._load_to_cache(fixture_name) | ||
return self._cache[fixture_name] | ||
|
||
@property | ||
def _dirpath(self): | ||
"""Absolute path to relative directory specified in relpath.""" | ||
thisdir = os.path.dirname(os.path.abspath(__file__)) | ||
return os.path.abspath(os.path.join(thisdir, self._relpath)) | ||
|
||
def _json_path(self, fixture_name): | ||
"""Return absolute path to JSON file for *fixture_name*.""" | ||
return ( | ||
'%s/%s.json' % | ||
(self._dirpath, fixture_name.replace('_', '-').lower()) | ||
) | ||
|
||
def _load_json(self, path): | ||
"""Return dict parsed from JSON at *path*.""" | ||
with open(path) as f: | ||
cube_response = json.load(f) | ||
return cube_response | ||
|
||
def _load_to_cache(self, fixture_name): | ||
json_path = self._json_path(fixture_name) | ||
if not os.path.exists(json_path): | ||
raise ValueError('no JSON fixture found at %s' % json_path) | ||
self._cache[fixture_name] = self._load_json(json_path) | ||
|
||
|
||
CR = LazyCubeResponseLoader('.') # ---mnemonic: CR = 'cube-response'--- | ||
SM = LazyCubeResponseLoader('./scale_means') |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.