def test_check_connections(self):
        class A(Component):
            def __init__(self):
                super(A, self).__init__()
                self.add_state('y', np.zeros((2,)), shape=(2,))

        class B(Component):
            def __init__(self):
                super(B, self).__init__()
                self.add_param('y', np.zeros((3,)), shape=(3,))

        class C(Component):
            def __init__(self):
                super(C, self).__init__()
                self.add_state('y', np.zeros((2,)))

        class D(Component):
            def __init__(self):
                super(D, self).__init__()
                self.add_param('y', np.zeros((2,)))

        class E(Component):
            def __init__(self):
                super(E, self).__init__()
                self.add_param('y', 1.0)

        # Type mismatch error message
        type_err = "Type <type '%s'> of source %s" \
                   " must be the same as "             \
                   "type <type '%s'> of target %s."

        # Type mismatch in explicit connection
        prob = Problem()
        prob.root = Group()
        prob.root.add('A', A())
        prob.root.add('E', E())

        prob.root.connect('A.y', 'E.y')

        with self.assertRaises(Exception) as cm:
            prob.setup(check=False)

        expected = py3fix(type_err % ('numpy.ndarray', "'A.y'", 'float', "'E.y'"))
        self.assertEqual(str(cm.exception), expected)

        # Type mismatch in implicit connection
        prob = Problem()
        prob.root = Group()
        prob.root.add('A', A(), promotes=['y'])
        prob.root.add('E', E(), promotes=['y'])

        with self.assertRaises(Exception) as cm:
            prob.setup(check=False)

        expected = py3fix(type_err % ('numpy.ndarray', "'A.y' (y)", 'float', "'E.y' (y)"))
        self.assertEqual(str(cm.exception), expected)

        # Shape mismatch error message
        shape_err = "Shape %s of source %s" \
                    " must be the same as "     \
                    "shape %s of target %s."

        # Shape mismatch in explicit connection
        prob = Problem()
        prob.root = Group()

        prob.root.add('A', A())
        prob.root.add('B', B())
        prob.root.connect('A.y', 'B.y')

        with self.assertRaises(Exception) as cm:
            prob.setup(check=False)

        raised_error = str(cm.exception)
        raised_error = raised_error.replace('(2L,', '(2,')
        raised_error = raised_error.replace('(3L,', '(3,')

        expected = shape_err % ('(2,)', "'A.y'", '(3,)', "'B.y'")
        self.assertTrue(expected in raised_error)

        # Shape mismatch in implicit connection
        prob = Problem()
        prob.root = Group()

        prob.root.add('A', A(), promotes=['y'])
        prob.root.add('B', B(), promotes=['y'])

        with self.assertRaises(Exception) as cm:
            prob.setup(check=False)

        raised_error = str(cm.exception)
        raised_error = raised_error.replace('(2L,', '(2,')
        raised_error = raised_error.replace('(3L,', '(3,')

        expected = shape_err % ('(2,)', "'A.y' (y)", '(3,)', "'B.y' (y)")
        self.assertTrue(expected in raised_error)

        # Shape mismatch in explicit connection
        prob = Problem()
        prob.root = Group()
        prob.root.add('B', B())
        prob.root.add('C', C())
        prob.root.connect('C.y', 'B.y')

        with self.assertRaises(Exception) as cm:
            prob.setup(check=False)

        raised_error = str(cm.exception)
        raised_error = raised_error.replace('(2L,', '(2,')
        raised_error = raised_error.replace('(3L,', '(3,')

        expected = ('(2,)', "'C.y'", '(3,)', "'B.y'") % shape_err
        self.assertTrue(expected in raised_error)

        # Shape mismatch in implicit connection
        prob = Problem()
        prob.root = Group()
        prob.root.add('B', B(), promotes=['y'])
        prob.root.add('C', C(), promotes=['y'])

        with self.assertRaises(Exception) as cm:
            prob.setup(check=False)

        raised_error = str(cm.exception)
        raised_error = raised_error.replace('(2L,', '(2,')
        raised_error = raised_error.replace('(3L,', '(3,')

        expected = shape_err % ('(2,)', "'C.y' (y)", '(3,)', "'B.y' (y)")
        self.assertTrue(expected in raised_error)

        # Explicit
        prob = Problem()
        prob.root = Group()
        prob.root.ln_solver = ScipyGMRES()
        prob.root.add('A', A())
        prob.root.add('D', D())
        prob.root.connect('A.y', 'D.y')

        stream = cStringIO()
        checks = prob.setup(out_stream=stream)

        self.assertEqual(checks['no_unknown_comps'], ['D'])
        self.assertEqual(checks['recorders'], [])
        content = stream.getvalue()
        self.assertTrue("The following components have no unknowns:\nD\n" in content)
        self.assertTrue("No recorders have been specified, so no data will be saved." in content)

        # Implicit
        prob = Problem()
        prob.root = Group()
        prob.root.ln_solver = ScipyGMRES()
        prob.root.add('A', A(), promotes=['y'])
        prob.root.add('D', D(), promotes=['y'])

        stream = cStringIO()
        checks = prob.setup(out_stream=stream)

        self.assertEqual(checks['no_unknown_comps'], ['D'])
        self.assertEqual(checks['recorders'], [])
        content = stream.getvalue()
        self.assertTrue("The following components have no unknowns:\nD\n" in content)
        self.assertTrue("No recorders have been specified, so no data will be saved." in content)

        # Explicit
        prob = Problem()
        prob.root = Group()
        prob.root.ln_solver = ScipyGMRES()
        prob.root.add('C', C())
        prob.root.add('D', D())
        prob.root.connect('C.y', 'D.y')

        stream = cStringIO()
        checks = prob.setup(out_stream=stream)

        self.assertEqual(checks['no_unknown_comps'], ['D'])
        self.assertEqual(checks['recorders'], [])
        content = stream.getvalue()
        self.assertTrue("The following components have no unknowns:\nD\n" in content)
        self.assertTrue("No recorders have been specified, so no data will be saved." in content)

        # Implicit
        prob = Problem()
        prob.root = Group()
        prob.root.ln_solver = ScipyGMRES()
        prob.root.add('C', C(), promotes=['y'])
        prob.root.add('D', D(), promotes=['y'])

        stream = cStringIO()
        checks = prob.setup(out_stream=stream)

        self.assertEqual(checks['no_unknown_comps'], ['D'])
        self.assertEqual(checks['recorders'], [])
        content = stream.getvalue()
        self.assertTrue("The following components have no unknowns:\nD\n" in content)
        self.assertTrue("No recorders have been specified, so no data will be saved." in content)
dataset/ETHPy150Open OpenMDAO/OpenMDAO/openmdao/core/test/test_problem.py/TestProblem.test_check_connections/swapped operands of `%`