Beispiel #1
0
    def test_simple(self):
        self.assertTrue(sanitize(ImmutableDict()) is ImmutableDict())
        self.assertTrue(sanitize({}) is ImmutableDict())
        self.assertTrue(sanitize(ImmutableList()) is ImmutableList())
        self.assertTrue(sanitize([]) is ImmutableList())

        self.assertTrue(sanitize(None) is None)
        self.assertTrue(sanitize(True) is True)
        self.assertTrue(sanitize(False) is False)
        self.assertEqual(sanitize("foobar"), "foobar")
        self.assertEqual(sanitize(1234), 1234)
        self.assertEqual(sanitize(1.234), 1.234)
 def test_basic(self):
     self.assertEqual(immutables_count(), 1)
     data = sanitize({
         "foo": "bar",
         "x1": [0, 1, 2, {
             "__symlink__": "x2"
         }, 4],
         "x2": {
             "y1": 123,
             "y2": {
                 "__symlink__": "foo"
             },
             "y3": {
                 "__symlink__": "/x1/[3]/y1"
             },
             "y4": {
                 "__symlink__": ["x2", "y2"]
             },
         },
     })
     data_resolved = sanitize({
         "foo":
         "bar",
         "x1": [
             0,
             1,
             2,
             {
                 "y1": 123,
                 "y2": "bar",
                 "y3": 123,
                 "y4": "bar"
             },
             4,
         ],
         "x2": {
             "y1": 123,
             "y2": "bar",
             "y3": 123,
             "y4": "bar"
         },
     })
     self.assertEqual(immutables_count(), 12)
     resolved = AttachedInfo.resolved(data)
     self.assertTrue(resolved is data_resolved)
     self.assertEqual(immutables_count(), 25)
     data_resolved = resolved = None
     self.assertEqual(immutables_count(), 25)
     data = None
     self.assertEqual(immutables_count(), 1)
Beispiel #3
0
    def test_nested(self):
        self.assertTrue(
            sanitize({
                "a": 1,
                "b": None,
                "c": {
                    "x": True
                },
                "d": ImmutableDict(y=False),
            }) is ImmutableDict(
                a=1, b=None, c=ImmutableDict(x=True), d=ImmutableDict(
                    y=False)))

        self.assertTrue(
            sanitize([1, None, [True], ImmutableList([False])]) is
            ImmutableList(
                [1, None,
                 ImmutableList([True]),
                 ImmutableList([False])]))
Beispiel #4
0
    def test_pass_immutable(self):
        self.assertTrue(
            sanitize([[]]) is sanitize(ImmutableList([[]])) is sanitize(
                ImmutableList([ImmutableList()])) is ImmutableList(
                    [ImmutableList()]))

        self.assertTrue(
            sanitize({"a": {}}) is sanitize(ImmutableDict({"a": {}})) is
            sanitize(ImmutableDict(
                a={})) is sanitize(ImmutableDict(
                    a=ImmutableDict())) is ImmutableDict(a=ImmutableDict()))
Beispiel #5
0
    def setRawState(self, new_state: ImmutableDict):
        new_state = sanitize(new_state)
        if self.__rawState is new_state:
            return
        if not new_state.isImmutableJson:
            raise Exception("Invalid state (not immutable json)")
        self.__rawState = new_state
        self.__updatePlugins()

        for plugin in self.__pluginInfos:
            new_state = setDataForPath(new_state, plugin.path, plugin.state)

        self.__nextState = new_state
        self.__setCore(
            ("plugins",),
            {pathToString(path): config for path, config in self.__pluginList},
            force=True,
        )