Esempio n. 1
0
    def testDebrinesExtendable(self):
        """ Debrine """
        logger.debug("\nExtendable Debrine\n")

        brinee = self.B()

        s = \
"""{
  "w": 0,
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""

        debrinee = debrines(s, [self.B], extendable=True)
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug("Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug("Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)
Esempio n. 2
0
    def testDebrinesExtendable(self):
        """ Debrine """
        logger.debug("\nExtendable Debrine\n")

        brinee = self.B()

        s = \
"""{
  "w": 0,
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""

        debrinee = debrines(s, [self.B], extendable=True)
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug( "Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug( "Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)
Esempio n. 3
0
    def testDebrinesBasic(self):
        """ Debrine """
        logger.debug("\nBasic Debrine\n")

        brinee = self.B()

        s = \
"""{
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""

        debrinee = debrines(s, [self.B])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug("Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug("Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)

        logger.debug("\nWith Properties\n")
        #with properties
        self.B._Propertied = True
        logger.debug("Dumpable:\n%s" % (brinee._dumpable()))
        logger.debug("Dumps:\n%s" % (brinee._dumps()))

        self.assertDictEqual(
            brinee._dumpable(),
            OrderedDict([('p', 0), ('x', 1), ('y', 2), ('z', 3),
                         ('@class', 'B')]))
        s = \
"""{
  "p": 0,
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""
        self.assertEqual(brinee._dumps(), s)

        debrinee = debrines(s, [self.B])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug("Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug("Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)

        self.B._Keys = ['z', 'x', 'y']
        logger.debug("Debrine With Keys: %s \n", self.B._Keys)

        logger.debug("Dumpable:\n%s." % (brinee._dumpable()))
        logger.debug("Dumps:\n%s" % (brinee._dumps()))

        self.assertDictEqual(
            brinee._dumpable(),
            OrderedDict([('z', 3), ('x', 1), ('y', 2), ('@class', 'B')]))
        s = \
"""{
  "z": 3,
  "x": 1,
  "y": 2,
  "@class": "B"
}"""
        self.assertEqual(brinee._dumps(), s)
        debrinee = debrines(s, [self.B])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug("Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug("Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)
Esempio n. 4
0
    def testDebrinesRecursive(self):
        """ Debrine recursive"""
        class B(object):
            def __init__(self):
                self.a = 0
                self.x = 1
                self.y = 2
                self.z = 3
                self.under = None
                self.name = "Over"

            def getp(self):
                return self._p

            def setp(self, value):
                self._p = value

            def delp(self):
                del self._p

            p = property(getp, setp, delp, "Property p of T")

            @staticmethod
            def pest():
                pass

        class C(object):
            def __init__(self):
                self.a = 2
                self.under = None
                self.name = "Other"

            def getp(self):
                return self._p

            def setp(self, value):
                self._p = value

            def delp(self):
                del self._p

            p = property(getp, setp, delp, "Property p of T")

            @staticmethod
            def pest():
                pass

        over = B()
        over.name = "Over"
        over.under = B()
        over.a = 2
        over.under.name = "Under"
        over.under.a = 3
        over.under.under = C()
        over.under.under.name = "Bottom"

        logger.debug("\Debrine Recursive.")

        s = \
"""{
  "a": 2,
  "name": "Over",
  "under": {
    "a": 3,
    "name": "Under",
    "under": {
      "a": 2,
      "name": "Bottom",
      "under": null,
      "@class": "C"
    },
    "x": 1,
    "y": 2,
    "z": 3,
    "@class": "B"
  },
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""

        debrinee = debrines(s, [B, C])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug("Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug("Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)
Esempio n. 5
0
    def testDebrinesBasic(self):
        """ Debrine """
        logger.debug("\nBasic Debrine\n")

        brinee = self.B()

        s = \
"""{
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""

        debrinee = debrines(s, [self.B])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug( "Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug( "Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)

        logger.debug("\nWith Properties\n")
        #with properties
        self.B._Propertied = True
        logger.debug( "Dumpable:\n%s" % (brinee._dumpable()))
        logger.debug( "Dumps:\n%s" % (brinee._dumps()))

        self.assertDictEqual(brinee._dumpable(),
                OrderedDict([('p', 0), ('x', 1), ('y', 2), ('z', 3), ('@class', 'B')]))
        s = \
"""{
  "p": 0,
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""
        self.assertEqual(brinee._dumps(), s)

        debrinee = debrines(s, [self.B])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug( "Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug( "Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)


        self.B._Keys = ['z', 'x', 'y']
        logger.debug("Debrine With Keys: %s \n", self.B._Keys)

        logger.debug("Dumpable:\n%s." % (brinee._dumpable()))
        logger.debug("Dumps:\n%s" % (brinee._dumps()))

        self.assertDictEqual(brinee._dumpable(),
                OrderedDict([('z', 3), ('x', 1), ('y', 2), ('@class', 'B')]))
        s = \
"""{
  "z": 3,
  "x": 1,
  "y": 2,
  "@class": "B"
}"""
        self.assertEqual(brinee._dumps(), s)
        debrinee = debrines(s, [self.B])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug( "Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug( "Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)
Esempio n. 6
0
    def testDebrinesRecursive(self):
        """ Debrine recursive"""
        class B(object):
            def __init__(self):
                self.a = 0
                self.x =  1
                self.y =  2
                self.z =  3
                self.under = None
                self.name = "Over"

            def getp(self):
                return self._p
            def setp(self, value):
                self._p = value
            def delp(self):
                del self._p
            p = property(getp, setp, delp, "Property p of T")

            @staticmethod
            def pest():
                pass

        class C(object):
            def __init__(self):
                self.a = 2
                self.under = None
                self.name = "Other"

            def getp(self):
                return self._p
            def setp(self, value):
                self._p = value
            def delp(self):
                del self._p
            p = property(getp, setp, delp, "Property p of T")

            @staticmethod
            def pest():
                pass

        over = B()
        over.name = "Over"
        over.under = B()
        over.a = 2
        over.under.name = "Under"
        over.under.a =  3
        over.under.under = C()
        over.under.under.name = "Bottom"

        logger.debug("\Debrine Recursive.")

        s = \
"""{
  "a": 2,
  "name": "Over",
  "under": {
    "a": 3,
    "name": "Under",
    "under": {
      "a": 2,
      "name": "Bottom",
      "under": null,
      "@class": "C"
    },
    "x": 1,
    "y": 2,
    "z": 3,
    "@class": "B"
  },
  "x": 1,
  "y": 2,
  "z": 3,
  "@class": "B"
}"""

        debrinee = debrines(s, [B, C])
        logger.debug("debrinee dir = \n%s\n debrinee __dict__ = \n%s" %\
                                    (dir(debrinee), debrinee.__dict__))
        logger.debug( "Dumpable:\n%s" % (debrinee._dumpable()))
        logger.debug( "Dumps:\n%s" % (debrinee._dumps()))
        self.assertEqual(debrinee._dumps(), s)