Skip to content

Commit

Permalink
less flake8y
Browse files Browse the repository at this point in the history
  • Loading branch information
zwolf committed May 22, 2024
1 parent c6e8ba9 commit 71528fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion panoptes_aggregation/batch_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
celery.conf.broker_url = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379")
celery.conf.result_backend = os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379")


@celery.task(name="run_aggregation")
def run_aggregation(project_id, workflow_id, user_id):
ba = BatchAggregator(project_id, workflow_id, user_id)
ba.save_exports()

wf_df = ba.process_wf_export(ba.wf_csv)
ba.process_wf_export(ba.wf_csv)
cls_df = ba.process_cls_export(ba.cls_csv)

extractor_config = workflow_extractor_config(ba.tasks)
Expand All @@ -51,6 +52,7 @@ def run_aggregation(project_id, workflow_id, user_id):

# hit up panoptes, let em know you're done


class BatchAggregator:
"""
Bunch of stuff to manage a batch aggregation run
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import unittest
from unittest.mock import patch, Mock, MagicMock, call
from unittest.mock import patch, MagicMock, call
from panoptes_aggregation.scripts import batch_utils
from panoptes_aggregation.batch_aggregation import run_aggregation
from panoptes_aggregation import batch_aggregation as batch_agg

wf_export = f'panoptes_aggregation/tests/batch_aggregation/wf_export.csv'
cls_export = f'panoptes_aggregation/tests/batch_aggregation/cls_export.csv'
wf_export = 'panoptes_aggregation/tests/batch_aggregation/wf_export.csv'
cls_export = 'panoptes_aggregation/tests/batch_aggregation/cls_export.csv'


@patch("panoptes_aggregation.batch_aggregation.BatchAggregator._connect_api_client", new=MagicMock())
class TestBatchAggregation(unittest.TestCase):
Expand All @@ -16,7 +17,7 @@ def test_run_aggregation(self, mock_aggregator, mock_wf_ext_conf):
mock_aggregator.process_cls_export.return_value = MagicMock()

mock_df = MagicMock()
test_extracts = { 'question_extractor': mock_df }
test_extracts = {'question_extractor': mock_df}
batch_utils.batch_extract = MagicMock(return_value=test_extracts)
mock_reducer = MagicMock()
batch_utils.batch_reduce = mock_reducer
Expand Down Expand Up @@ -49,7 +50,7 @@ def test_run_aggregation(self, mock_aggregator, mock_wf_ext_conf):
@patch("panoptes_aggregation.batch_aggregation.Panoptes.connect")
def test_save_exports(self, mock_client, mock_project, mock_workflow, mock_mkdir):
# Test that Panoptes calls are made and files are saved
csv_dict = {'media': [ {'src': 'http://zooniverse.org/123.csv'} ] }
csv_dict = {'media': [{'src': 'http://zooniverse.org/123.csv'}]}
mock_project.return_value.describe_export.return_value = csv_dict
mock_workflow.return_value.describe_export.return_value = csv_dict
ba = batch_agg.BatchAggregator(1, 10, 100)
Expand Down
1 change: 1 addition & 0 deletions panoptes_aggregation/tests/router_tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_one_running_reducer_route(self):

# Override json.dumps() for this test so it doesn't try to jsonify the mock
import json

@patch("panoptes_aggregation.batch_aggregation.json.dumps", return_value=json.dumps({'project_id': 1, 'workflow_id': 10, 'user_id': 100, 'task_id': 'asdf'}))
@patch("panoptes_aggregation.batch_aggregation.run_aggregation.delay")
def test_run_aggregation_route(self, mocked_task, mocked_json):
Expand Down

0 comments on commit 71528fe

Please sign in to comment.