def test_raises_err_with_no_inputs(self, mock_credentials): """ Assert ConnectionError raised if no connection arg, ENV, profile """ mock_credentials.return_value = {} msg = "Could not determine credentials to use." with pytest.raises(ConnectionError, match=msg): connect()
def test_uses_args_over_env(self, mock_connect, mock_credentials_by_env, mock_credentials_by_profile): """ Assert uses connect args over env """ mock_credentials_by_profile.return_value = {} mock_credentials_by_env.return_value = { "endpoints": "a", "apikey": "b" } connect("cat", "dog") mock_connect.assert_called_once_with(endpoints="cat", apikey="dog")
def test_uses_env_over_profile(self, mock_connect, mock_credentials_by_env, mock_credentials_by_profile): """ Assert connect uses env over profile info """ mock_credentials_by_profile.return_value = { "endpoints": "a", "apikey": "b" } mock_credentials_by_env.return_value = { "endpoints": "c", "apikey": "d" } connect() mock_connect.assert_called_once_with(endpoints="c", apikey="d")
def test_connect_with_env(self, mock_conn, mock_credentials_by_profile): """ Assert connect uses ENV variables """ mock_credentials_by_profile.return_value = {} address = "127.0.0.1:4410" os.environ[BTRDB_ENDPOINTS] = address btrdb = connect() mock_conn.assert_called_once_with(address, apikey=None) mock_conn.reset_mock() apikey = "abcd" os.environ[BTRDB_API_KEY] = apikey btrdb = connect() mock_conn.assert_called_once_with(address, apikey=apikey)
def btrdb_deserializer(_, conn_str=None, apikey=None, profile=None): """ deserialize function Parameters ---------- conn_str: str, default=None The address and port of the cluster to connect to, e.g. `192.168.1.1:4411`. If set to None, will look in the environment variable `$BTRDB_ENDPOINTS` (recommended). apikey: str, default=None The API key used to authenticate requests (optional). If None, the key is looked up from the environment variable `$BTRDB_API_KEY`. profile: str, default=None The name of a profile containing the required connection information as found in the user's predictive grid credentials file `~/.predictivegrid/credentials.yaml`. Returns ------- db : BTrDB An instance of the BTrDB context to directly interact with the database. """ return btrdb.connect(conn_str=conn_str, apikey=apikey, profile=profile)
from matplotlib import pyplot as plt import btrdb from btrdb.utils.timez import * path_to_data = os.path.join('../../../../../Volumes/NO NAME/sentinel') streams = ['ac_voltage','freq','sync_status'] fnames = ['bedford_2013-03-01_%s.h5'%(str(hr).zfill(2)) for hr in range(0,24)] for fname in fnames: assert fname in os.listdir(path_to_data) print('\n'.join(fnames)) laurels_api_key = '2301C47D67FB1C2C48D0CC7B' db = btrdb.connect("api.ni4ai.org:4411", apikey=laurels_api_key) f = h5py.File(os.path.join(path_to_data, fnames[0]), 'r') collection = 'lndunn/sentinel/bedford' annotations = {'latitude': np.average(f['alldata']['latitude']['raw']), 'longitude': np.average(f['alldata']['longitude']['raw'])} tags = {'ac_voltage': {'name': 'voltage', 'unit': 'volts'}, 'freq': {'name': 'frequency', 'unit': 'Hz'}, 'neutral_current': {'name': 'neutral_current', 'unit': 'amps'}, 'sync_status': {'name': 'sync_stats', 'unit': 'mask'} } uuids = dict(zip(tags.keys(), [uuid.uuid4() for key in tags.keys()]))
def test_raises_err_if_both_profile_and_credentials(self): """ Assert error is raised if both profile and credentials are sent """ with pytest.raises(ValueError): connect("192.168.1.100:4410", None, "default")
parser.add_argument( '--quiet', '-q', action='store_true', help='Suppress progress bars & info-level logging to stdout.') args = parser.parse_args() assert bool(args.s3_object_prefix) ^ bool( args.hdf5_export_files ), 'Specify either an s3 object or hdf5 file, but not both.' LOGGING_FORMAT = '%(asctime)-15s | %(message)s' logging.basicConfig(format=LOGGING_FORMAT, level=logging.INFO) logger = logging.getLogger() db = btrdb.connect(args.endpoints, apikey=args.apikey) etl_start_time = time.time() if args.hdf5_export_files: source_file_names = args.hdf5_export_files else: # get a file list from S3 session = boto3.Session(profile_name='225685591965_PTDeveloperAccess') client = session.client("s3") s3 = session.resource('s3') bucket_name, obj_prefix = args.s3_object_prefix.split( '/')[0], '/'.join(args.s3_object_prefix.split('/')[1:]) # s3_prefix = 'pt-ni4ai-sentinel/2016-08-16/' bucket_name, obj_prefix = args.s3_object_prefix.split( '/')[0], '/'.join(args.s3_object_prefix.split('/')[1:]) source_bucket = s3.Bucket(bucket_name)