from numpy.testing import assert_
from statsmodels.base.optimizer import (_fit_newton, _fit_nm,
                                        _fit_bfgs, _fit_cg,
                                        _fit_ncg, _fit_powell,
                                        _fit_lbfgs, _fit_basinhopping)

fit_funcs = {
    'newton': _fit_newton,
    'nm': _fit_nm,  # Nelder-Mead
    'bfgs': _fit_bfgs,
    'cg': _fit_cg,
    'ncg': _fit_ncg,
    'powell': _fit_powell,
    'lbfgs': _fit_lbfgs,
    'basinhopping': _fit_basinhopping,
            }


def dummy_func(x):
    return x**2

def dummy_score(x):
    return 2.*x

def dummy_hess(x):
    return [[2.]]

def test_full_output_false():
    # just a smoke test

    # newton needs f, score, start, fargs, kwargs
    # bfgs needs f, score start, fargs, kwargs
    # nm needs ""
    # cg ""
    # ncg ""
    # powell ""
    for method in fit_funcs:
        func = fit_funcs[method]
        if method == "newton":
            xopt, retvals = func(dummy_func, dummy_score, [1], (), {},
                    hess=dummy_hess, full_output=False, disp=0)

        else:
            xopt, retvals = func(dummy_func, dummy_score, [1], (), {},
                full_output=False, disp=0)
        assert_(retvals is None)
        if method == "powell":
            #NOTE: I think I reported this? Might be version/optimize API
            # dependent
            assert_(xopt.shape == () and xopt.size == 1)
        else:
            assert_(len(xopt) == 1)

@@ -1473,12 +1473,739 @@
 xopt) == 1)%0A
+%0A%0Adef test_full_output():%0A    for method in fit_funcs:%0A        func = fit_funcs%5Bmethod%5D%0A        if method == %22newton%22:%0A            xopt, retvals = func(dummy_func, dummy_score, %5B1%5D, (), %7B%7D,%0A                                 hess=dummy_hess, full_output=True, disp=0)%0A%0A        else:%0A            xopt, retvals = func(dummy_func, dummy_score, %5B1%5D, (), %7B%7D,%0A                                 full_output=True, disp=0)%0A%0A        assert_(retvals is not None)%0A        assert_('converged' in retvals)%0A%0A        if method == %22powell%22:%0A            #NOTE: I think I reported this? Might be version/optimize API%0A            # dependent%0A            assert_(xopt.shape == () and xopt.size == 1)%0A        else:%0A            assert_(len(xopt) == 1)%0A%0A

Test full_output=1