diff --git a/doc/changes/DM-53791.bugfix.md b/doc/changes/DM-53791.bugfix.md new file mode 100644 index 0000000..a93233a --- /dev/null +++ b/doc/changes/DM-53791.bugfix.md @@ -0,0 +1 @@ +Fix copying of `ConfigChoiceField` and `RegistryField`. diff --git a/python/lsst/pex/config/configChoiceField.py b/python/lsst/pex/config/configChoiceField.py index b96f66c..412c5b6 100644 --- a/python/lsst/pex/config/configChoiceField.py +++ b/python/lsst/pex/config/configChoiceField.py @@ -192,7 +192,7 @@ def _copy(self, config: Config) -> ConfigInstanceDict: result._typemap = self._typemap if self._selection is not None: if self._field.multi: - result._selection = SelectionSet(result._dict, self._selection._set) + result._selection = SelectionSet(self, self._selection._set) else: result._selection = self._selection return result diff --git a/tests/test_configChoiceField.py b/tests/test_configChoiceField.py index f2fbf7c..7114763 100644 --- a/tests/test_configChoiceField.py +++ b/tests/test_configChoiceField.py @@ -165,6 +165,20 @@ def testNoPickle(self): with self.assertRaises(pexConfig.UnexpectedProxyUsageError): pickle.dumps(self.config.c.names) + def test_copy(self): + """Test the copy method on a ConfigChoiceField.""" + copy1: Config3 = self.config.copy() + copy1.a["AAA"].f = 1 + copy1.a["BBB"].f = 1.0 + copy1.a = "BBB" + self.assertEqual(self.config.a.name, "AAA") + self.assertEqual(self.config.a.active.f, 4) + self.assertEqual(self.config.a["AAA"].f, 4) + self.assertEqual(self.config.a["BBB"].f, 0.5) + self.assertEqual(copy1.a.name, "BBB") + self.assertEqual(copy1.a["AAA"].f, 1) + self.assertEqual(copy1.a["BBB"].f, 1.0) + if __name__ == "__main__": unittest.main()