'Test unpack results method.'

def test_unpack_results(self):

    with self.assertRaises(Exception) as cm:
        Problem(Minimize(exp(self.a))).unpack_results('blah', None)
    self.assertEqual(str(cm.exception), 'Unknown    solver.')
    prob = Problem(Minimize(exp(self.a)), [(self.a == 0)])
    args = prob.get_problem_data(s.SCS)
    data = {'c': args['c'], 'A': args['A'], 'b': args['b']}
    results_dict = scs.solve(data, args['dims'])
    prob = Problem(Minimize(exp(self.a)), [(self.a == 0)])
    prob.unpack_results(s.SCS, results_dict)
    self.assertAlmostEqual(self.a.value, 0, places=3)
    self.assertAlmostEqual(prob.value, 1, places=3)
    self.assertAlmostEqual(prob.status, s.OPTIMAL)
    prob = Problem(Minimize(norm(self.x)), [(self.x == 0)])
    args = prob.get_problem_data(s.ECOS)
    results_dict = ecos.solve(args['c'], args['G'], args['h'], args['dims'], args['A'], args['b'])
    prob = Problem(Minimize(norm(self.x)), [(self.x == 0)])
    prob.unpack_results(s.ECOS, results_dict)
    self.assertItemsAlmostEqual(self.x.value, [0, 0])
    self.assertAlmostEqual(prob.value, 0)
    self.assertAlmostEqual(prob.status, s.OPTIMAL)
    if (s.CVXOPT in installed_solvers()):
        import cvxopt
        prob = Problem(Minimize(norm(self.x)), [(self.x == 0)])
        args = prob.get_problem_data(s.CVXOPT)
        results_dict = cvxopt.solvers.conelp(args['c'], args['G'], args['h'], args['dims'], args['A'], args['b'])
        prob = Problem(Minimize(norm(self.x)), [(self.x == 0)])
        prob.unpack_results(s.CVXOPT, results_dict)
        self.assertItemsAlmostEqual(self.x.value, [0, 0])
        self.assertAlmostEqual(prob.value, 0)
        self.assertAlmostEqual(prob.status, s.OPTIMAL)
