예제 #1
0
    def test_update_blacklist(self):
        """Wrapping nested mapping should only apply to types not in the blacklist."""
        pl = DataContainer()
        pl.update([{
            "a": 1,
            "b": 2
        }, [{
            "c": 3,
            "d": 4
        }]],
                  wrap=True,
                  blacklist=(dict, ))
        self.assertTrue(isinstance(pl[0], dict),
                        "nested dict wrapped, even if black listed")
        self.assertTrue(isinstance(pl[1][0], dict),
                        "nested dict wrapped, even if black listed")
        pl.clear()

        pl.update({
            "a": [1, 2, 3],
            "b": {
                "c": [4, 5, 6]
            }
        },
                  wrap=True,
                  blacklist=(list, ))
        self.assertTrue(isinstance(pl.a, list),
                        "nested list wrapped, even if black listed")
        self.assertTrue(isinstance(pl.b.c, list),
                        "nested list wrapped, even if black listed")
        pl.clear()
예제 #2
0
    def test_update(self):
        pl = DataContainer()
        d = self.pl.to_builtin()
        pl.update(d, wrap=True)
        self.assertEqual(pl, self.pl,
                         "update from to_builtin does not restore list")
        with self.assertRaises(ValueError,
                               msg="no ValueError on invalid initializer"):
            pl.update("asdf")

        pl = self.pl.copy()
        pl.update({}, pyiron="yes", test="case")
        self.assertEqual((pl.pyiron, pl.test), ("yes", "case"),
                         "update via kwargs does not set values")
        pl.clear()
        d = {"a": 0, "b": 1, "c": 2}
        pl.update(d)
        self.assertEqual(
            dict(pl), d, "update without options does not call generic method")