def test_autocommit_switching(dsn, configuration): table_name = unique_table_name() connection = connect(dsn, **get_credentials(configuration)) connection.autocommit = True # <--- connection.cursor().execute(f"CREATE TABLE {table_name} (a INTEGER)") connection.close() options = make_options(autocommit=True) connection = connect( dsn, turbodbc_options=options, **get_credentials(configuration) ) connection.autocommit = False # <--- connection.cursor().execute(f"INSERT INTO {table_name} VALUES (?)", [42]) connection.close() # table is there, but data was not persisted connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute(f"SELECT * FROM {table_name}") results = cursor.fetchall() assert results == [] cursor.execute(f"DROP TABLE {table_name}") connection.commit()
def test_no_autocommit(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute("CREATE TABLE test_no_autocommit (a INTEGER)") connection.close() connection = connect(dsn, **get_credentials(configuration)) with pytest.raises(DatabaseError): connection.cursor().execute("SELECT * FROM test_no_autocommit")
def test_no_autocommit(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE test_no_autocommit (a INTEGER)') connection.close() connection = connect(dsn, **get_credentials(configuration)) with pytest.raises(DatabaseError): connection.cursor().execute('SELECT * FROM test_no_autocommit')
def get_gvkey(): aws_param = my.get_credentials(credential='aws') with my.postgresql_connect(aws_param) as conn: df_companies = my.sql_query(sql="SELECT * FROM reuters.company_list", conn=conn) company_list = [ i.split('.')[0] for i in df_companies['constituent_ric'].tolist() ] wrds_username = my.get_credentials( credential='wrds_credentials')['username'] wrds_password = my.get_credentials( credential='wrds_credentials')['password'] wrds_conn = wrds.Connection(wrds_username=wrds_username, wrds_password=wrds_password) gvkey_mapping = wrds_conn.raw_sql( my.create_wrds_sql_query(table='security', columns=['tic', 'gvkey'], distinct=True, conditions={'tic': company_list}, no_observations=-1)) gvkey_list = gvkey_mapping['gvkey'].tolist() wrds_companies = wrds_conn.raw_sql( my.create_wrds_sql_query( table='company', columns=['gvkey', 'conm', 'conml', 'fic', 'loc', 'weburl'], distinct=True, conditions={'gvkey': gvkey_list}, no_observations=-1)) df_companies['tic'] = company_list df_combined = pd.merge(df_companies, gvkey_mapping, on='tic', how='left') df_combined = pd.merge(df_combined, wrds_companies, on='gvkey', how='left') df_combined['match'] = df_combined.apply(lambda x: algorithims.levenshtein( x['tr_indexjlconstituentcomname'], x['conml']), axis=1) df_combined['match'].fillna(0, inplace=True) df_combined['row_add'] = [ i / 1000000 for i in list(range(len(df_combined), 0, -1)) ] df_combined['score'] = df_combined['match'] + df_combined['row_add'] grouped_df = df_combined.groupby('score') maxs = grouped_df.max() df_combined = maxs.reset_index() df_combined = df_combined[['constituent_ric', 'tic', 'gvkey']] df_combined['include_company'] = np.where(df_combined['gvkey'].isna(), False, True) data_dir = my.get_project_directories(key='data_dir') output_file_path = os.path.join(data_dir, 'reuters_wrds_mapping.csv') df_combined.to_csv(output_file_path, index=False)
def test_commit(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE test_commit (a INTEGER)') connection.commit() connection.close() connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute('SELECT * FROM test_commit') results = cursor.fetchall() assert results == [] cursor.execute('DROP TABLE test_commit') connection.commit()
def test_closed_cursor_raises_when_used(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.close() with pytest.raises(InterfaceError): cursor.execute("SELECT 42") with pytest.raises(InterfaceError): cursor.executemany("SELECT 42") with pytest.raises(InterfaceError): cursor.executemanycolumns("SELECT 42", []) with pytest.raises(InterfaceError): cursor.fetchone() with pytest.raises(InterfaceError): cursor.fetchmany() with pytest.raises(InterfaceError): cursor.fetchall() with pytest.raises(InterfaceError): six.next(cursor)
def test_connect_with_connection_string(dsn, configuration): connection_string = "DSN=%s;" % dsn for para, val in get_credentials(configuration).items(): connection_string = connection_string + f"{para}={val};" connection = connect(connection_string=connection_string) connection.cursor().execute("SELECT 'foo'") connection.close()
def test_setinputsizes_does_not_raise(dsn, configuration): """ It is legal for setinputsizes() to do nothing, so anything except raising an exception is ok """ cursor = connect(dsn, **get_credentials(configuration)).cursor() cursor.setinputsizes([10, 20])
def test_commit(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE test_commit (a INTEGER)') connection.commit() connection.close() connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute('SELECT * FROM test_commit') results = cursor.fetchall() assert results == [] cursor.execute('DROP TABLE test_commit') connection.commit()
def test_closed_cursor_raises_when_used(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.close() with pytest.raises(InterfaceError): cursor.execute("SELECT 42") with pytest.raises(InterfaceError): cursor.executemany("SELECT 42") with pytest.raises(InterfaceError): cursor.executemanycolumns("SELECT 42", []) with pytest.raises(InterfaceError): cursor.fetchone() with pytest.raises(InterfaceError): cursor.fetchmany() with pytest.raises(InterfaceError): cursor.fetchall() with pytest.raises(InterfaceError): six.next(cursor)
def test_autocommit_enabled_at_start(dsn, configuration): table_name = unique_table_name() options = make_options(autocommit=True) connection = connect(dsn, turbodbc_options=options, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE {} (a INTEGER)'.format(table_name)) connection.close() connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute('SELECT * FROM {}'.format(table_name)) results = cursor.fetchall() assert results == [] cursor.execute('DROP TABLE {}'.format(table_name)) connection.commit()
def test_setinputsizes_does_not_raise(dsn, configuration): """ It is legal for setinputsizes() to do nothing, so anything except raising an exception is ok """ cursor = connect(dsn, **get_credentials(configuration)).cursor() cursor.setinputsizes([10, 20])
def test_connect_with_connection_string(dsn, configuration): connection_string = "DSN=%s;" % dsn for para, val in get_credentials(configuration).items(): connection_string = connection_string + "%s=%s;" % (para, val) connection = connect(connection_string=connection_string) connection.cursor().execute("SELECT 'foo'") connection.close()
def test_new_cursor_properties(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() # https://www.python.org/dev/peps/pep-0249/#rowcount assert cursor.rowcount == -1 assert None == cursor.description assert cursor.arraysize == 1
def test_rollback(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE test_rollback (a INTEGER)') connection.rollback() with pytest.raises(DatabaseError): connection.cursor().execute('SELECT * FROM test_rollback')
def test_pep343_with_statement(dsn, configuration): with connect(dsn, **get_credentials(configuration)) as connection: cursor = connection.cursor() # connection should be closed, test it with the cursor with pytest.raises(InterfaceError): cursor.execute("SELECT 42")
def test_commit(dsn, configuration): table_name = unique_table_name() connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute(f"CREATE TABLE {table_name} (a INTEGER)") connection.commit() connection.close() connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute(f"SELECT * FROM {table_name}") results = cursor.fetchall() assert results == [] cursor.execute(f"DROP TABLE {table_name}") connection.commit()
def test_new_cursor_properties(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() # https://www.python.org/dev/peps/pep-0249/#rowcount assert cursor.rowcount == -1 assert None == cursor.description assert cursor.arraysize == 1
def test_pep343_with_statement(dsn, configuration): with connect(dsn, **get_credentials(configuration)) as connection: with connection.cursor() as cursor: cursor.execute("SELECT 42") # cursor should be closed with pytest.raises(InterfaceError): cursor.execute("SELECT 42")
def test_commit(dsn, configuration): table_name = unique_table_name() connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE {} (a INTEGER)'.format(table_name)) connection.commit() connection.close() connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute('SELECT * FROM {}'.format(table_name)) results = cursor.fetchall() assert results == [] cursor.execute('DROP TABLE {}'.format(table_name)) connection.commit()
def test_rollback(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE test_rollback (a INTEGER)') connection.rollback() with pytest.raises(DatabaseError): connection.cursor().execute('SELECT * FROM test_rollback')
def test_rollback(dsn, configuration): table_name = unique_table_name() connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute('CREATE TABLE {} (a INTEGER)'.format(table_name)) connection.rollback() with pytest.raises(DatabaseError): connection.cursor().execute('SELECT * FROM {}'.format(table_name))
def test_setoutputsize_does_not_raise(dsn, configuration): """ It is legal for setinputsizes() to do nothing, so anything except raising an exception is ok """ cursor = connect(dsn, **get_credentials(configuration)).cursor() cursor.setoutputsize(1000, 42) # with column cursor.setoutputsize(1000, column=42) # with column cursor.setoutputsize(1000) # without column
def test_rollback(dsn, configuration): table_name = unique_table_name() connection = connect(dsn, **get_credentials(configuration)) connection.cursor().execute(f"CREATE TABLE {table_name} (a INTEGER)") connection.rollback() with pytest.raises(DatabaseError): connection.cursor().execute(f"SELECT * FROM {table_name}")
def test_setoutputsize_does_not_raise(dsn, configuration): """ It is legal for setinputsizes() to do nothing, so anything except raising an exception is ok """ cursor = connect(dsn, **get_credentials(configuration)).cursor() cursor.setoutputsize(1000, 42) # with column cursor.setoutputsize(1000, column=42) # with column cursor.setoutputsize(1000) # without column
def test_connect_performance_settings(dsn, configuration): connection = connect(dsn=dsn, rows_to_buffer=317, parameter_sets_to_buffer=123, use_async_io=True, **get_credentials(configuration)) assert connection.impl.get_buffer_size().rows == 317 assert connection.impl.parameter_sets_to_buffer == 123 assert connection.impl.use_async_io == True
def test_connect_performance_settings(dsn, configuration): connection = connect(dsn=dsn, rows_to_buffer=317, parameter_sets_to_buffer=123, use_async_io=True, **get_credentials(configuration)) assert connection.impl.get_buffer_size().rows == 317 assert connection.impl.parameter_sets_to_buffer == 123 assert connection.impl.use_async_io == True
def test_closing_connection_closes_all_cursors(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor_1 = connection.cursor() cursor_2 = connection.cursor() connection.close() with pytest.raises(InterfaceError): cursor_1.execute("SELECT 42") with pytest.raises(InterfaceError): cursor_2.execute("SELECT 42")
def test_closing_connection_closes_all_cursors(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor_1 = connection.cursor() cursor_2 = connection.cursor() connection.close() with pytest.raises(InterfaceError): cursor_1.execute("SELECT 42") with pytest.raises(InterfaceError): cursor_2.execute("SELECT 42")
def test_rest_create_draft(): username, password, prefix = get_credentials() d = get_rest(username=username, password=password, prefix=prefix, with_fake_url=False) doi = d.draft_doi() datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix url = 'https://github.com/inveniosoftware/datacite' new_url = d.update_url(doi, url) assert new_url == url d.delete_doi(doi)
def test_rest_create_draft_metadata(): username, password, prefix = get_credentials() d = get_rest(username=username, password=password, prefix=prefix, with_fake_url=False) metadata = {"titles": [{"title": "hello world", "lang": "en"}]} doi = prefix+'/12345' returned_doi = d.draft_doi(metadata, doi) assert returned_doi == doi url = 'https://github.com/inveniosoftware/datacite' returned_metadata = d.update_doi(doi, url=url) assert returned_metadata['url'] == url assert returned_metadata['titles'][0]['title'] == 'hello world' d.delete_doi(doi)
def test_autocommit_switching(dsn, configuration): table_name = unique_table_name() connection = connect(dsn, **get_credentials(configuration)) connection.autocommit = True # <--- connection.cursor().execute('CREATE TABLE {} (a INTEGER)'.format(table_name)) connection.close() options = make_options(autocommit=True) connection = connect(dsn, turbodbc_options=options, **get_credentials(configuration)) connection.autocommit = False # <--- connection.cursor().execute('INSERT INTO {} VALUES (?)'.format(table_name), [42]) connection.close() # table is there, but data was not persisted connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.execute('SELECT * FROM {}'.format(table_name)) results = cursor.fetchall() assert results == [] cursor.execute('DROP TABLE {}'.format(table_name)) connection.commit()
def test_rest_create_public(example_json43): """Test creating DOIs with all example metadata""" example_metadata = load_json_path(example_json43) url = 'https://github.com/inveniosoftware/datacite' username, password, prefix = get_credentials() d = get_rest(username=username, password=password, prefix=prefix, with_fake_url=False) doi = d.public_doi(example_metadata, url) datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix metadata = {'publisher': 'Invenio'} new_metadata = d.update_doi(doi, metadata) assert new_metadata['publisher'] == 'Invenio' url = 'https://github.com/inveniosoftware' new_metadata = d.update_doi(doi, url=url) assert new_metadata['url'] == url
def test_rest_create_private(): """Test creating private DOI""" example_json43 = 'data/4.3/datacite-example-dataset-v4.json' example_metadata = load_json_path(example_json43) url = 'https://github.com/inveniosoftware/datacite' username, password, prefix = get_credentials() d = get_rest(username=username, password=password, prefix=prefix, with_fake_url=False) doi = d.private_doi(example_metadata, url) datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix datacite_metadata = d.get_metadata(doi) assert datacite_metadata['state'] == 'registered' new_metadata = d.show_doi(doi) assert new_metadata['state'] == 'findable' new_metadata = d.hide_doi(doi) assert new_metadata['state'] == 'registered'
def test_connect_returns_connection_when_successful(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) assert isinstance(connection, Connection)
def test_nextset_unsupported(dsn, configuration): cursor = connect(dsn, **get_credentials(configuration)).cursor() with pytest.raises(AttributeError): cursor.nextset()
def test_cursor_on_closed_connection_raises(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.close() with pytest.raises(InterfaceError): connection.cursor()
def test_closing_twice_is_ok(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.close() connection.close()
def __init__(self): credentials = helpers.get_credentials() self.client = MongoClient('mongodb+srv://' + credentials[0] + ":" + credentials[1] + "@cluster0.n0rcn.mongodb.net/") self.database = self.client[credentials[2]]
def test_connection_does_not_strongly_reference_cursors(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() import sys assert sys.getrefcount(cursor) == 2
def test_closing_twice_does_not_raise(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.close() cursor.close()
def test_connect_with_rows(dsn, configuration): connection = connect(dsn=dsn, read_buffer_size=Rows(317), **get_credentials(configuration)) assert connection.impl.get_buffer_size().rows == 317
def test_open_cursor_without_result_set_raises(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() with pytest.raises(InterfaceError): cursor.fetchone()
def test_closing_twice_does_not_raise(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() cursor.close() cursor.close()
"Fill out health screening (assuming a reservation has already been made)", action="store_true") cli_args = cli_parser.parse_args() try: # Set headless option for web driver opts = Options() opts.headless = True driver = Firefox(options=opts) # Supply the driver a direct link to the amenities site driver.get( "https://www.avalonaccess.com/Information/Information/Amenities") # Login email, password = get_credentials(cli_args.manual) driver.find_element_by_id("UserName").send_keys(email) driver.find_element_by_id("password").send_keys(password) driver.find_element_by_id("submit-sign-in").click() # Collect account name and number name, account_num = get_account_details(driver) # Double negative check to see if the user is only filling out the health screening if not cli_args.health: driver.find_element_by_id("reserve").click() make_reservation(driver) if cli_args.skip: exit(0)
from helpers import get_credentials from binance.client import Client import json import os import time # Initialize environment variables env = os.environ # Read credentials and initialize Client instance credentials = get_credentials("credentials/fbltr.json") client = Client(credentials["api_key"], credentials["api_secret"]) # Get all exchange info info = client.get_exchange_info() # Save in the output file with open(env["OUTPUT_FILE"], "w", encoding='utf-8') as f: json.dump(info, f, ensure_ascii=False, indent=4) print("Info saved!") while True: print("sleeping...") time.sleep(5)
def test_rollback_on_closed_connection_raises(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.close() with pytest.raises(InterfaceError): connection.rollback()
def test_autocommit_querying(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) assert connection.autocommit == False connection.autocommit = True assert connection.autocommit == True connection.close()
def test_read_buffer_size_has_priority_to_rows_to_buffer(dsn, configuration): connection = connect(dsn=dsn, read_buffer_size=Megabytes(1), rows_to_buffer=317, **get_credentials(configuration)) assert connection.impl.get_buffer_size().megabytes == 1
def test_connection_does_not_strongly_reference_cursors(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() import sys assert sys.getrefcount(cursor) == 2
def test_autocommit_querying(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) assert connection.autocommit is False connection.autocommit = True assert connection.autocommit is True connection.close()
def test_connect_returns_connection_with_explicit_dsn(dsn, configuration): connection = connect(dsn=dsn, **get_credentials(configuration)) assert isinstance(connection, Connection)
Returns True if host responds to a ping request """ # Ping parameters as function of OS ping_str = "-n 1" if platform.system().lower() == "windows" else "-c 1" # Ping return 0 == os.system("ping " + ping_str + " " + host + "> /dev/null 2>&1") def just_died(l): alives = sum(l) if alives > 3: return True credentials = get_credentials() api = remote.API(api_password=credentials['api_password'], port=443, use_ssl=True, host=credentials['host']) previous = [] domain = 'light' arguments = { "entity_id": 'light.desk', "color_temp": 375, "brightness": 107, } while True: alive = ping('192.168.0.60') desk = remote.get_state(api, 'light.desk') logger.debug('^^^^^^^^^^^') logger.debug("{previous} - {alive} - {state}".format(previous=previous, alive=alive, state=desk.state))
def test_open_cursor_without_result_set_raises(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) cursor = connection.cursor() with pytest.raises(InterfaceError): cursor.fetchone()
def test_closing_twice_is_ok(dsn, configuration): connection = connect(dsn, **get_credentials(configuration)) connection.close() connection.close()
def test_connect_with_megabytes(dsn, configuration): connection = connect(dsn=dsn, read_buffer_size=Megabytes(1), **get_credentials(configuration)) assert connection.impl.get_buffer_size().megabytes == 1
def test_nextset_unsupported(dsn, configuration): cursor = connect(dsn, **get_credentials(configuration)).cursor() with pytest.raises(AttributeError): cursor.nextset()