Commit b2e9f2e5 authored by Gavin's avatar Gavin
Browse files

updated matcher module to use logging rather then warnings

parent dd77e5eb
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -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
@@ -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.')
@@ -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}.')
@@ -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
@@ -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)
+13 −3
Original line number Diff line number Diff line
@@ -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
@@ -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():
@@ -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.
@@ -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, {})
                        ])
@@ -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