Loading autocnet/graph/cluster_submit.py +11 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import copy import os import json import sys import warnings import logging from io import StringIO from contextlib import redirect_stdout Loading @@ -20,6 +20,9 @@ from autocnet.utils.utils import import_func from autocnet.utils.serializers import JsonEncoder, object_hook from autocnet.io.db.model import JobsHistory # set up the logging file log = logging.getLogger(__name__) def parse_args(): # pragma: no cover parser = argparse.ArgumentParser() parser.add_argument('-r', '--host', help='The host URL for the redis queue to to pull messages from.') Loading Loading @@ -178,7 +181,7 @@ def manage_messages(args, queue): if msg is None: if args['queue'] == False: warnings.warn('Expected to process a cluster job, but the message queue is empty.') log.warning('Expected to process a cluster job, but the message queue is empty.') return elif args['queue'] == True: print(f'Completed processing from queue: {queue}.') Loading @@ -197,8 +200,9 @@ def manage_messages(args, queue): with redirect_stdout(stdout): # Apply the algorithm response = process(msgdict) # Should go to a logger someday! print(response) # Should go to a logger someday! (today is that day!) log.info(response) out = stdout.getvalue() # print to get everything on the logs in the directory Loading Loading @@ -226,6 +230,9 @@ def manage_messages(args, queue): def main(): # pragma: no cover args = vars(parse_args()) # set up the logger logging.basicConfig(level=os.environ.get("autocnet_loglevel", "INFO")) log.error("hello") # Get the message queue = StrictRedis(host=args['host'], port=args['port'], db=0) manage_messages(args, queue) Loading autocnet/graph/tests/test_cluster_submit.py +13 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ from unittest.mock import patch import numpy as np import pytest import logging from autocnet.utils.serializers import JsonEncoder, object_hook from autocnet.graph import cluster_submit Loading @@ -12,6 +13,7 @@ from autocnet.graph.node import NetworkNode from autocnet.graph.edge import NetworkEdge from autocnet.io.db.model import Points, JobsHistory log = logging.getLogger(__name__) @pytest.fixture def args(): Loading Loading @@ -102,9 +104,11 @@ def test_finalize_message_from_work_queue(args, queue, simple_message): cluster_submit.finalize_message_from_work_queue(queue, args['working_queue'], remove_key) assert queue.llen(args['working_queue']) == 0 def test_no_msg(args, queue): with pytest.warns(UserWarning, match='Expected to process a cluster job, but the message queue is empty.'): def test_no_msg(caplog,args, queue): cluster_submit.manage_messages(args, queue) expected_log = 'Expected to process a cluster job, but the message queue is empty.' assert expected_log in caplog.text # Classes and funcs for testing job submission. Loading Loading @@ -167,6 +171,11 @@ def test_process_row(along, func, msg_additions, mocker): cluster_submit._instantiate_row.assert_called_once() @pytest.mark.parametrize() def _do_something(): log.debug("Doing something!") log.info("This is some info") @pytest.mark.parametrize("along, func, msg_additions",[ ([1,2,3,4,5], _do_nothing, {}) ]) Loading @@ -181,6 +190,7 @@ def test_process_generic(along, func, msg_additions, mocker): mocker.patch('autocnet.graph.cluster_submit._instantiate_obj', side_effect=_generate_obj) mocker.patch('autocnet.graph.network.NetworkCandidateGraph.Session', return_value=True) mocker.patch('autocnet.graph.network.NetworkCandidateGraph.config_from_dict') _do_something() assert not cluster_submit._instantiate_row.called assert not cluster_submit._instantiate_obj.called Loading Loading
autocnet/graph/cluster_submit.py +11 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import copy import os import json import sys import warnings import logging from io import StringIO from contextlib import redirect_stdout Loading @@ -20,6 +20,9 @@ from autocnet.utils.utils import import_func from autocnet.utils.serializers import JsonEncoder, object_hook from autocnet.io.db.model import JobsHistory # set up the logging file log = logging.getLogger(__name__) def parse_args(): # pragma: no cover parser = argparse.ArgumentParser() parser.add_argument('-r', '--host', help='The host URL for the redis queue to to pull messages from.') Loading Loading @@ -178,7 +181,7 @@ def manage_messages(args, queue): if msg is None: if args['queue'] == False: warnings.warn('Expected to process a cluster job, but the message queue is empty.') log.warning('Expected to process a cluster job, but the message queue is empty.') return elif args['queue'] == True: print(f'Completed processing from queue: {queue}.') Loading @@ -197,8 +200,9 @@ def manage_messages(args, queue): with redirect_stdout(stdout): # Apply the algorithm response = process(msgdict) # Should go to a logger someday! print(response) # Should go to a logger someday! (today is that day!) log.info(response) out = stdout.getvalue() # print to get everything on the logs in the directory Loading Loading @@ -226,6 +230,9 @@ def manage_messages(args, queue): def main(): # pragma: no cover args = vars(parse_args()) # set up the logger logging.basicConfig(level=os.environ.get("autocnet_loglevel", "INFO")) log.error("hello") # Get the message queue = StrictRedis(host=args['host'], port=args['port'], db=0) manage_messages(args, queue) Loading
autocnet/graph/tests/test_cluster_submit.py +13 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ from unittest.mock import patch import numpy as np import pytest import logging from autocnet.utils.serializers import JsonEncoder, object_hook from autocnet.graph import cluster_submit Loading @@ -12,6 +13,7 @@ from autocnet.graph.node import NetworkNode from autocnet.graph.edge import NetworkEdge from autocnet.io.db.model import Points, JobsHistory log = logging.getLogger(__name__) @pytest.fixture def args(): Loading Loading @@ -102,9 +104,11 @@ def test_finalize_message_from_work_queue(args, queue, simple_message): cluster_submit.finalize_message_from_work_queue(queue, args['working_queue'], remove_key) assert queue.llen(args['working_queue']) == 0 def test_no_msg(args, queue): with pytest.warns(UserWarning, match='Expected to process a cluster job, but the message queue is empty.'): def test_no_msg(caplog,args, queue): cluster_submit.manage_messages(args, queue) expected_log = 'Expected to process a cluster job, but the message queue is empty.' assert expected_log in caplog.text # Classes and funcs for testing job submission. Loading Loading @@ -167,6 +171,11 @@ def test_process_row(along, func, msg_additions, mocker): cluster_submit._instantiate_row.assert_called_once() @pytest.mark.parametrize() def _do_something(): log.debug("Doing something!") log.info("This is some info") @pytest.mark.parametrize("along, func, msg_additions",[ ([1,2,3,4,5], _do_nothing, {}) ]) Loading @@ -181,6 +190,7 @@ def test_process_generic(along, func, msg_additions, mocker): mocker.patch('autocnet.graph.cluster_submit._instantiate_obj', side_effect=_generate_obj) mocker.patch('autocnet.graph.network.NetworkCandidateGraph.Session', return_value=True) mocker.patch('autocnet.graph.network.NetworkCandidateGraph.config_from_dict') _do_something() assert not cluster_submit._instantiate_row.called assert not cluster_submit._instantiate_obj.called Loading