Skip to content

Commit

Permalink
fix KeySet updating of already string-accessed keysets
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Sep 12, 2019
1 parent e299644 commit c839f4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion gpkit/keydict.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ def update(self, *args, **kwargs):
arg, = args
if isinstance(arg, KeySet): # assume unmapped
dict.update(self, arg)
self.keymap.update(arg.keymap)
for key, value in arg.keymap.items():
self.keymap[key].update(value)
self._unmapped_keys.update(arg._unmapped_keys) # pylint: disable=protected-access
else: # set-like interface
for item in arg:
Expand Down
6 changes: 2 additions & 4 deletions gpkit/tests/t_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ class Sub(Model):
"Submodel with mass, for testing"
def setup(self):
m = Variable("m", "lb", "mass")
return []


class Widget(Model):
Expand All @@ -739,7 +738,8 @@ 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"]]
return [self.subA, self.subB,
m_tot >= self.subA["m"] + self.subB["m"]]


class TestModelNoSolve(unittest.TestCase):
Expand Down Expand Up @@ -778,8 +778,6 @@ def test_duplicate_submodel_varnames(self):
# 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 c839f4a

Please sign in to comment.