Skip to content

Commit

Permalink
Merge pull request #1636 from DKilkenny/promotes_star
Browse files Browse the repository at this point in the history
Added logic to stop error being raised if promotes * is used and no matches are found
  • Loading branch information
swryan committed Aug 21, 2020
2 parents 39777d6 + 471b671 commit 5930a52
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
7 changes: 4 additions & 3 deletions openmdao/core/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,9 +1954,10 @@ def resolve(to_match, io_types, matches, proms):
if fnmatchcase(i, p):
break
else:
raise RuntimeError("%s: '%s' failed to find any matches for the following "
"pattern: '%s'.%s" %
(self.msginfo, call, p, empty_group_msg))
if p != '*':
raise RuntimeError("%s: '%s' failed to find any matches for the "
"following pattern: '%s'.%s" %
(self.msginfo, call, p, empty_group_msg))
if p == patterns[-1]:
break
else:
Expand Down
21 changes: 0 additions & 21 deletions openmdao/core/tests/test_connections_in_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,6 @@ def test_connect_in_configure(self):

class TestAddSubcomponentIOInConfigure(unittest.TestCase):

def test_queue_subcomponent_io_in_configure(self):
"""
This test queues IO to a component in configure, but that subcomponent resolves the
queued I/O at setup and therefore this will fail.
"""
p = om.Problem(model=om.Group())

g = GroupQueuesIOInConfigure()

g.add_var_to_cube('foo', units='m')

p.model.add_subsystem('g', subsys=g)

with self.assertRaises(RuntimeError) as e:
p.setup()

err_msg = str(e.exception)
expected = "Cuber (g.cuber): 'promotes_inputs' failed to find any matches for the " \
"following pattern: '*'."
self.assertEqual(err_msg, expected)

def test_add_subcomponent_io_in_configure(self):
"""
This test directly adds IO to a component in configure, and should behave as expected.
Expand Down
6 changes: 1 addition & 5 deletions openmdao/core/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,7 @@ def test_empty_group(self):
p = om.Problem()
g1 = p.model.add_subsystem('G1', om.Group(), promotes=['*'])

with self.assertRaises(Exception) as context:
p.setup()
self.assertEqual(str(context.exception),
"Group (G1): 'promotes' failed to find any matches for the following "
"pattern: '*'. Group contains no variables.")
p.setup()

def test_missing_promote_var(self):
p = om.Problem()
Expand Down
11 changes: 11 additions & 0 deletions openmdao/core/tests/test_indep_var_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ def test_add_output(self):
assert_near_equal(prob.get_val('indep_var_1'), 1.0)
assert_near_equal(prob.get_val('indep_var_2'), 2.0)

def test_promote_glob_no_inputs(self):
p = om.Problem()
p.model.add_subsystem('indep',
om.IndepVarComp('x', 2.0),
promotes_inputs=['*'],
promotes_outputs=['x'])
p.model.add_subsystem('C1', om.ExecComp('y=x'), promotes_inputs=['x'], promotes_outputs=['y'])
p.setup()
p.run_model()
self.assertEqual(p.get_val('x'), p.get_val('y'))

def test_invalid_tags(self):
with self.assertRaises(TypeError) as cm:
comp = om.IndepVarComp('indep_var', tags=99)
Expand Down

0 comments on commit 5930a52

Please sign in to comment.