예제 #1
0
def predict(path='/predict?sepal length=1.0&sepal width=1.1&'
            'petal length=0.777&petal width=5',
            predict_service_name='predict_service'):
    from palladium.server import app
    from palladium.server import predict
    from palladium.util import get_config

    model_persister = get_config()['model_persister']
    predict_service = get_config()[predict_service_name]

    with app.test_request_context(path):
        response = predict(model_persister, predict_service)
        assert response.status_code == 200
예제 #2
0
    def test_read_environ(self, get_config, config):
        config.initialized = False
        config_in_str = """
{
'mycomponent': {
    '__factory__': 'palladium.tests.test_util.MyDummyComponent',
    'arg1': 3,
    'arg2': "{}:{}".format(environ['PALLADIUM_DB_IP'],
                           environ['PALLADIUM_DB_PORT']),
    },
}"""

        with patch('palladium.util.open',
                   mock_open(read_data=config_in_str),
                   create=True):
            with patch(
                    'palladium.util.os.environ', {
                        'PALLADIUM_CONFIG': 'somepath',
                        'PALLADIUM_DB_IP': '192.168.0.1',
                        'PALLADIUM_DB_PORT': '666',
                    }):
                config_new = get_config()

            mycomponent = config_new['mycomponent']
            assert isinstance(mycomponent, MyDummyComponent)
            assert mycomponent.arg1 == 3
            assert mycomponent.arg2 == '192.168.0.1:666'
예제 #3
0
    def test_read_environ(self, get_config, config):
        config.initialized = False
        config_in_str = """
{
'mycomponent': {
    '__factory__': 'palladium.tests.test_util.MyDummyComponent',
    'arg1': 3,
    'arg2': "{}:{}".format(environ['PALLADIUM_DB_IP'],
                           environ['PALLADIUM_DB_PORT']),
    },
}"""

        with patch('palladium.util.open',
                   mock_open(read_data=config_in_str),
                   create=True):
            with patch('palladium.util.os.environ', {
                    'PALLADIUM_CONFIG': 'somepath',
                    'PALLADIUM_DB_IP': '192.168.0.1',
                    'PALLADIUM_DB_PORT': '666',
            }):
                config_new = get_config()

            mycomponent = config_new['mycomponent']
            assert isinstance(mycomponent, MyDummyComponent)
            assert mycomponent.arg1 == 3
            assert mycomponent.arg2 == '192.168.0.1:666'
예제 #4
0
    def test_read_here(self, get_config, config):
        config.initialized = False
        config_in_str = "{'here': here}"

        with patch('palladium.util.open',
                   mock_open(read_data=config_in_str),
                   create=True):
            with patch('palladium.util.os.environ', {
                    'PALLADIUM_CONFIG': '/home/megha/somepath.py',
            }):
                config_new = get_config()

            assert config_new['here'] == '/home/megha'
예제 #5
0
    def test_read_multiple_files(self, get_config, config):
        config.initialized = False

        fake_open = MagicMock()
        fake_open.return_value.__enter__.return_value.read.side_effect = [
            "{'a': 42, 'b': 6}", "{'b': 7}"
        ]
        with patch('palladium.util.open', fake_open, create=True):
            with patch('palladium.util.os.environ', {
                    'PALLADIUM_CONFIG': 'somepath, andanother',
            }):
                config_new = get_config()

        assert config_new == {'a': 42, 'b': 7}

        # Files later in the list override files earlier in the list:
        assert fake_open.call_args_list == [
            call('somepath'), call('andanother')
        ]
예제 #6
0
    def test_read(self, get_config, config):
        config.initialized = False
        config_in = {
            'mycomponent': {
                '__factory__': 'palladium.tests.test_util.MyDummyComponent',
                'arg1': 3,
                },
            'myconstant': 42,
            }

        with patch('palladium.util.open',
                   mock_open(read_data=str(config_in)),
                   create=True):
            with patch('palladium.util.os.environ', {'PALLADIUM_CONFIG': 'somepath'}):
                config_new = get_config()

            assert config_new['myconstant'] == config_in['myconstant']
            mycomponent = config_new['mycomponent']
            assert isinstance(mycomponent, MyDummyComponent)
            assert mycomponent.arg1 == 3
예제 #7
0
    def test_read(self, get_config, config):
        config.initialized = False
        config_in = {
            'mycomponent': {
                '__factory__': 'palladium.tests.test_util.MyDummyComponent',
                'arg1': 3,
            },
            'myconstant': 42,
        }

        with patch('palladium.util.open',
                   mock_open(read_data=str(config_in)),
                   create=True):
            with patch('palladium.util.os.environ',
                       {'PALLADIUM_CONFIG': 'somepath'}):
                config_new = get_config()

            assert config_new['myconstant'] == config_in['myconstant']
            mycomponent = config_new['mycomponent']
            assert isinstance(mycomponent, MyDummyComponent)
            assert mycomponent.arg1 == 3