Skip to content

Commit

Permalink
Merge pull request #561 from jay-m-dev/pep8_tabs
Browse files Browse the repository at this point in the history
retabbed py files, using 4 spaces per PEP 8 style
  • Loading branch information
jay-m-dev authored Jan 19, 2023
2 parents c49e1db + c4f30ed commit 6fa3810
Show file tree
Hide file tree
Showing 7 changed files with 743 additions and 743 deletions.
8 changes: 4 additions & 4 deletions ai/tests/lab_api_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,8 @@ def handle_post_no_datasets(path, data):
}
]

api_experiment_ai_on = [{
"_id": "562a12bd612a17b20f99a143"
api_experiment_ai_on = [{
"_id": "562a12bd612a17b20f99a143"
}]

api_launch_experiment_running = {
Expand Down Expand Up @@ -1050,8 +1050,8 @@ def handle_post_no_datasets(path, data):

# invalid response; should return a dict, not a list
api_launch_experiment_invalid = [
{
"_id": "562a12bd612a17b20f99a143"
{
"_id": "562a12bd612a17b20f99a143"
}]

api_launch_experiment_no_capacity = {
Expand Down
16 changes: 8 additions & 8 deletions ai/tests/test_ai_and_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
@patch('requests.request', side_effect=mocker.mocked_requests_request)
@patch('requests.post', side_effect=mocker.mocked_requests_post)
def test_ai_init_args(mock_request, mock_post):
lab_connection_args = {}
pennai = AI(
rec_class=None,
api_path='http://lab:5080',
user="testuser",
lab_connection_args = {}
pennai = AI(
rec_class=None,
api_path='http://lab:5080',
user="testuser",
verbose=True,
n_recs=1,
warm_start=False,
Expand All @@ -79,8 +79,8 @@ def test_ai_init_knowledgebase(mock_request, mock_post):
@patch('requests.request', side_effect=mocker.mocked_requests_request)
@patch('requests.post', side_effect=mocker.mocked_requests_post)
def test_ai_init(mock_request, mock_post):
lab_connection_args = {}
pennai = AI()
lab_connection_args = {}
pennai = AI()

@patch('requests.request', side_effect=mocker.mocked_requests_request)
@patch('requests.post', side_effect=mocker.mocked_requests_post)
Expand Down Expand Up @@ -118,4 +118,4 @@ def test_main_command_line_queue_exception(mock_request, mock_post, mock_sleep):
"""
testargs = ["ai"]
with patch.object(sys, 'argv', testargs):
aiProc = ai.ai.main()
aiProc = ai.ai.main()
162 changes: 81 additions & 81 deletions ai/tests/test_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,59 @@
import pandas as pd

class TestLabApi:
def setup(self):
"set up test fixtures"
self.labApi = LabApi(
api_path=mocker.api_path,
user=mocker.user,
api_key=None,
extra_payload=mocker.extra_payload,
verbose=True)


self.partial_expected_classification_ml_p = [
{
def setup(self):
"set up test fixtures"
self.labApi = LabApi(
api_path=mocker.api_path,
user=mocker.user,
api_key=None,
extra_payload=mocker.extra_payload,
verbose=True)


self.partial_expected_classification_ml_p = [
{
"algorithm":"SVC",
"algorithm_id":"5ba41716dfe741699222871b",
"category":"classification",
"parameters":{'C': 0.0001,
'kernel': 'poly',
'tol': 1e-05}
},
{
{
"algorithm":"SVC",
"algorithm_id":"5ba41716dfe741699222871b",
"category":"classification",
"parameters":{'C': 0.0001,
'kernel': 'poly',
'tol': 0.0001}},
{
{
"algorithm":"SVC",
"algorithm_id":"5ba41716dfe741699222871b",
"category":"classification",
"parameters":{'C': 0.0001,
'kernel': 'poly',
'tol': 0.001}},
{
{
"algorithm":"SVC",
"algorithm_id":"5ba41716dfe741699222871b",
"category":"classification",
"parameters":{'C': 25,
'kernel': 'rbf',
'tol': 0.1}},
{
{
"algorithm":"SVC",
"algorithm_id":"5ba41716dfe741699222871b",
"category":"classification",
"parameters":{'C': 1,
'kernel': 'poly',
'tol': 1e-05}},
]
]

self.expected_total_classification_ml_p = 80
self.expected_total_classification_ml_p = 80

self.partial_expected_regression_ml_p = [
{
self.partial_expected_regression_ml_p = [
{
"algorithm":"DecisionTreeRegressor",
"algorithm_id":"5da8d68c4590b0868cbf574e",
"category":"regression",
Expand All @@ -99,7 +99,7 @@ def setup(self):
'min_samples_leaf':1,
'min_weight_fraction_leaf':0}
},
{
{
"algorithm":"DecisionTreeRegressor",
"algorithm_id":"5da8d68c4590b0868cbf574e",
"category":"regression",
Expand All @@ -109,7 +109,7 @@ def setup(self):
'min_samples_leaf':1,
'min_weight_fraction_leaf':.45}
},
{
{
"algorithm":"DecisionTreeRegressor",
"algorithm_id":"5da8d68c4590b0868cbf574e",
"category":"regression",
Expand All @@ -119,7 +119,7 @@ def setup(self):
'min_samples_leaf':5,
'min_weight_fraction_leaf':0}
},
{
{
"algorithm":"DecisionTreeRegressor",
"algorithm_id":"5da8d68c4590b0868cbf574e",
"category":"regression",
Expand All @@ -129,81 +129,81 @@ def setup(self):
'min_samples_leaf':1,
'min_weight_fraction_leaf':0}
},
]
]

self.expected_total_regression_ml_p = 48
self.expected_total_regression_ml_p = 48

@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_projects(self, mock_request):
res = self.labApi.get_projects()
#print("type: ", type(res))
#assert_is_instance(res, dict)
assert len(res) > 0
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_projects(self, mock_request):
res = self.labApi.get_projects()
#print("type: ", type(res))
#assert_is_instance(res, dict)
assert len(res) > 0


@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_all_ml_p(self, mock_request):
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_all_ml_p(self, mock_request):

res = self.labApi.get_all_ml_p()
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) == (self.expected_total_classification_ml_p + self.expected_total_regression_ml_p)
res = self.labApi.get_all_ml_p()
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) == (self.expected_total_classification_ml_p + self.expected_total_regression_ml_p)

resDict = res.to_dict('records')
resDict = res.to_dict('records')

for expectedRow in self.partial_expected_classification_ml_p:
assert_in(expectedRow, resDict)
for expectedRow in self.partial_expected_classification_ml_p:
assert_in(expectedRow, resDict)

for expectedRow in self.partial_expected_regression_ml_p:
assert_in(expectedRow, resDict)
for expectedRow in self.partial_expected_regression_ml_p:
assert_in(expectedRow, resDict)

@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_set_recommender_status(self, mock_request):
res = self.labApi.set_recommender_status(RECOMMENDER_STATUS.RUNNING.value)
print("type: ", type(res))
print(res)
assert_dict_equal(res, {"message": "AI status set to 'running'"})
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_set_recommender_status(self, mock_request):
res = self.labApi.set_recommender_status(RECOMMENDER_STATUS.RUNNING.value)
print("type: ", type(res))
print(res)
assert_dict_equal(res, {"message": "AI status set to 'running'"})

@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_all_ml_p_classification(self, mock_request):
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_all_ml_p_classification(self, mock_request):

res = self.labApi.get_all_ml_p("classification")
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) == self.expected_total_classification_ml_p
res = self.labApi.get_all_ml_p("classification")
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) == self.expected_total_classification_ml_p

resDict = res.to_dict('records')
resDict = res.to_dict('records')

for expectedRow in self.partial_expected_classification_ml_p:
assert_in(expectedRow, resDict)
for expectedRow in self.partial_expected_classification_ml_p:
assert_in(expectedRow, resDict)

@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_all_ml_p_regression(self, mock_request):
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_all_ml_p_regression(self, mock_request):

res = self.labApi.get_all_ml_p("regression")
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) == self.expected_total_regression_ml_p
res = self.labApi.get_all_ml_p("regression")
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) == self.expected_total_regression_ml_p

resDict = res.to_dict('records')
resDict = res.to_dict('records')

for expectedRow in self.partial_expected_regression_ml_p:
assert_in(expectedRow, resDict)
for expectedRow in self.partial_expected_regression_ml_p:
assert_in(expectedRow, resDict)

@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_dataset_ai_status_none(self, mock_request):
res = self.labApi.get_dataset_ai_status(mocker.test_dataset_id_no_ai)
assert_equal(res, None)
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_dataset_ai_status_none(self, mock_request):
res = self.labApi.get_dataset_ai_status(mocker.test_dataset_id_no_ai)
assert_equal(res, None)

@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_dataset_ai_status_on(self, mock_request):
res = self.labApi.get_dataset_ai_status(mocker.test_dataset_id_ai_on)
assert_equal(res, "on")
assert_equal(res, AI_STATUS.ON.value)
@patch('requests.request', side_effect=mocker.mocked_requests_request)
def test_get_dataset_ai_status_on(self, mock_request):
res = self.labApi.get_dataset_ai_status(mocker.test_dataset_id_ai_on)
assert_equal(res, "on")
assert_equal(res, AI_STATUS.ON.value)

@patch('requests.request', side_effect=mocker.mocked_requests_request_multi_machine)
def test_get_all_ml_p_mulit_machine(self, mock_request):
res = self.labApi.get_all_ml_p()
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) > 0
@patch('requests.request', side_effect=mocker.mocked_requests_request_multi_machine)
def test_get_all_ml_p_mulit_machine(self, mock_request):
res = self.labApi.get_all_ml_p()
print("type: ", type(res))
assert_is_instance(res, pd.DataFrame)
assert len(res) > 0
Loading

0 comments on commit 6fa3810

Please sign in to comment.