Esempio n. 1
0
def test_delete_module(caplog):
    import logging
    caplog.set_level(logging.INFO, 'sasctl._services.service')

    # Delete should succeed even if object couldn't be found on server
    with mock.patch('sasctl._services.microanalytic_score.MicroAnalyticScore'
                    '.get') as get:
        get.return_value = None

        assert mas.delete_module('spam') is None
        assert any("Object 'spam' not found" in r.msg for r in caplog.records)
def test_publish_and_execute(tmpdir, boston_dataset):
    import pickle
    from sasctl.utils.pymas import from_pickle
    from sasctl.services import microanalytic_score as mas
    from sklearn.linear_model import LinearRegression

    X = boston_dataset[boston_dataset.columns[:-1]]
    y = boston_dataset[boston_dataset.columns[-1]]

    lm = LinearRegression()
    lm.fit(X, y)
    pkl = pickle.dumps(lm)
    p = from_pickle(pkl, 'predict', X, array_input=True)

    # Generate the score code & publish as a model
    code = p.score_code()
    mas.create_module('sasctl_test', source=code, language='ds2')

    x1 = {k.lower(): v for k, v in X.iloc[0, :].items()}
    result = mas.execute_module_step('sasctl_test', 'predict', **x1)

    assert round(result['var1'], 3) == 30.004

    mas.delete_module('sasctl_test')
    def test_delete_module(self):
        assert mas.get_module(self.MODULE_NAME) is not None

        mas.delete_module(self.MODULE_NAME)

        assert mas.get_module(self.MODULE_NAME) is None