Ejemplo n.º 1
0
def test_get_all(test_subdir):
    ws = mlbriefcase.Briefcase()

    all = ws.get_all()

    assert len(all) == 1
    assert all[0].name == 'query1'
Ejemplo n.º 2
0
def test_service_csv1(test_subdir):
    ws = mlbriefcase.Briefcase()

    url = ws['dataset'].get_url()
    df = pd.read_csv(url, sep='\t')

    # df = ws['csv1'].to_pandas_dataframe()
    assert (df.columns == ['a', 'b', 'c']).all()
    assert df.shape == (2, 3)
Ejemplo n.º 3
0
def test_cog_service_keyring(test_subdir):
    ws = mlbriefcase.Briefcase()

    keyring.set_password('mlbriefcase', 'anom1', 'abc123')

    svc1 = ws['anom1']
    
    assert svc1.url == 'https://foo.bar'
    assert svc1.get_secret() == 'abc123'
Ejemplo n.º 4
0
def test_dotenv(test_subdir):
    ws = mlbriefcase.Briefcase()

    # resolve from .env file
    assert ws['dummy1'].get_secret() == 'secret1'
    assert ws['dummy2'].get_secret() == 'secret2'

    # also support arbitrary properties
    assert ws['dummy1'].url == 'http://my.host'
Ejemplo n.º 5
0
def test_azure_storage_url(test_subdir, caplog):
    # caplog.set_level(logging.DEBUG, logger='briefcase')

    ws = mlbriefcase.Briefcase()

    url = ws['workspacetest1'].get_url()
    df = pd.read_csv(url, sep='\t')

    assert (df.columns == ['a', 'b', 'c']).all()
    assert df.shape == (2, 3)
Ejemplo n.º 6
0
def test_metadata(test_subdir):
    ws = mlbriefcase.Briefcase()

    metadata = ws['query1'].metadata
    assert isinstance(metadata, dict)

    assert metadata['a'] == 1
    assert metadata['tag'] == 'datasource'

    assert metadata['b'] == [1, 2]
Ejemplo n.º 7
0
def test_Credential_Resolution(test_subdir):
    ws = mlbriefcase.Briefcase()

    # make sure we don't call out to keyvault in tests
    for keyvault in ws.get_all_of_type(mlbriefcase.azure.keyvault):
        keyvault.set_client(MockKeyVault())

    # mock keyvault appends 123 at the end
    # explicit credential store reference
    assert '123' == ws['myblobsource1'].get_secret() 
Ejemplo n.º 8
0
def test_google_facedetect(test_subdir, caplog):
	# caplog.set_level(logging.DEBUG, logger='briefcase')

	ws = mlbriefcase.Briefcase()

	image = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../face1.jpg'), "rb").read() 

	client = ws['face'].get_client()
	
	result = client.face_detection(io.BytesIO(image))

	assert result.face_annotations[0].joy_likelihood > 4
def test_aws_facedetect(test_subdir, caplog):
    # caplog.set_level(logging.DEBUG, logger='briefcase')

    ws = mlbriefcase.Briefcase()

    image = open(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     '../../face1.jpg'), "rb").read()

    reko_client = ws['faceaws1'].get_client()

    result = reko_client.detect_faces(Image={"Bytes": image})
    assert 'FaceDetails' in result
Ejemplo n.º 10
0
def test_sql_alchemy(test_subdir):
    ws = mlbriefcase.Briefcase()

    query1 = ws['query1']

    # test fixture setup
    engine = query1.get_client()
    engine.execute("CREATE TABLE table1(col1 VARCHAR(255))")
    engine.execute("INSERT INTO table1 VALUES('abc')")

    # actual usage
    df = psql.read_sql("SELECT * FROM table1", con=engine)
    assert df.iloc[0][0] == 'abc'
Ejemplo n.º 11
0
def test_clarifai_moderation(test_subdir, caplog):
	# caplog.set_level(logging.DEBUG, logger='briefcase')

	ws = mlbriefcase.Briefcase()

	client = ws['moderation'].get_client()
	
	image = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../face1.jpg'), "rb").read() 

	result = client.public_models.moderation_model.predict_by_bytes(raw_bytes=image)

	assert result['status']['code'] == 10000
	assert list(filter(lambda x: x['name'] == 'explicit', result['outputs'][0]['data']['concepts']))[0]['value'] < 0.1
Ejemplo n.º 12
0
def test_google_language(test_subdir, caplog):
	# caplog.set_level(logging.DEBUG, logger='briefcase')

	ws = mlbriefcase.Briefcase()

	client = ws['language'].get_client()
	
	document = types.Document(content="The moon is visible from New York City.", language="en", type=enums.Document.Type.PLAIN_TEXT)
	result = client.analyze_entities(document)

	assert result.entities[0].name == 'moon'
	assert result.entities[0].type == enums.Entity.Type.LOCATION

	assert result.entities[1].name == 'New York City'
	assert result.entities[1].type == enums.Entity.Type.LOCATION
Ejemplo n.º 13
0
def test_service_principal(test_subdir):

    ws = mlbriefcase.Briefcase()

    svc1 = ws['myvault1']
    assert len(svc1.get_secret("workspacetest1")) > 0
def test_azure_keyvault(test_subdir):

    ws = mlbriefcase.Briefcase()

    svc1 = ws['kv1']
Ejemplo n.º 15
0
def test_dont_infinite_recurse_if_cred_not_found(test_subdir):
    with pytest.raises(mlbriefcase.base.KeyNotFoundException, match=r".*myserviceprincipal.*EnvironmentCredentialProvider.*"):
        ws = mlbriefcase.Briefcase()
        client = ws['face_test'].get_client() 
Ejemplo n.º 16
0
def test_can_load_empty(test_subdir):
    ws = mlbriefcase.Briefcase()
Ejemplo n.º 17
0
def test_Briefcase_can_load(test_subdir):
    ws = mlbriefcase.Briefcase()
Ejemplo n.º 18
0
def test_Briefcase_indexing(test_subdir):
    ws = mlbriefcase.Briefcase()

    assert ws['myvault1'] is not None
    assert ws['myvault2'] is None
Ejemplo n.º 19
0
def test_Briefcase_can_find_AzureStorage(test_subdir):
    ws = mlbriefcase.Briefcase()

    assert 0 < len(ws.get_all_of_type(mlbriefcase.azure.storage.account))