Skip to content

Commit

Permalink
add failing test for issue #1432
Browse files Browse the repository at this point in the history
  • Loading branch information
whoburg committed Sep 8, 2019
1 parent 34313b0 commit e299644
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions gpkit/tests/t_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,22 @@ def setup(self, box):
box.w*box.d <= A_floor]


class Sub(Model):
"Submodel with mass, for testing"
def setup(self):
m = Variable("m", "lb", "mass")
return []


class Widget(Model):
"A model with two Sub models"
def setup(self):
m_tot = Variable("m_{tot}", "lb", "total mass")
self.subA = Sub()
self.subB = Sub()
return [self.subA, self.subB, m_tot >= self.subA["m"] + self.subB["m"]]


class TestModelNoSolve(unittest.TestCase):
"""model tests that don't require a solver"""
def test_modelname_added(self):
Expand All @@ -748,6 +764,22 @@ def test_no_naming_on_var_access(self):
for var in ("h", "w", "d"):
self.assertEqual(len(M.variables_byname(var)), 1)

def test_duplicate_submodel_varnames(self):
w = Widget()
# w has two Sub models, both with their own variable m
self.assertEqual(len(w.variables_byname("m")), 2)
# keys for both submodel m's should be in the parent model varkeys
self.assertIn(w.subA["m"].key, w.varkeys)
self.assertIn(w.subB["m"].key, w.varkeys)
# keys of w.variables_byname("m") should match m.varkeys
m_vbn_keys = [v.key for v in w.variables_byname("m")]
self.assertIn(w.subA["m"].key, m_vbn_keys)
self.assertIn(w.subB["m"].key, m_vbn_keys)
# dig a level deeper, into the keymap
self.assertEqual(len(w.varkeys.keymap["m"]), 2)
w2 = Widget()
# next line surprisingly fails -- 7 vs 5
self.assertEqual(len(w.varkeys.keymap), len(w2.varkeys.keymap))

TESTS = [TestModelSolverSpecific, TestModelNoSolve]
MULTI_SOLVER_TESTS = [TestGP, TestSP]
Expand Down

0 comments on commit e299644

Please sign in to comment.