Beispiel #1
0
    def test_00_null(self):
        md0 = TT.make()

        # check if md0 is an object of base and default class:
        self.assertTrue(isinstance(md0, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0, MD.UpdateWithMergeDict))
        self.assertTrue(not md0)
Beispiel #2
0
    def test_00_null(self):
        md0 = TT.make()

        # check if md0 is an object of base and default class:
        self.assertTrue(isinstance(md0, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0, MD.UpdateWithMergeDict))
        self.assertTrue(not md0)
Beispiel #3
0
 def test_30_to_namedtuple(self):
     _point = collections.namedtuple("Point", "x y")
     _triangle = collections.namedtuple("Triangle", "p0 p1 p2")
     itpl = _triangle(_point(0, 0), _point(1, 0), _point(0, 1))
     md0 = TT.make(itpl)
     otpl = TT.convert_to(md0, to_namedtuple=True)
     self.assertEqual(otpl, itpl)
Beispiel #4
0
 def test_30_to_namedtuple(self):
     _point = collections.namedtuple("Point", "x y")
     _triangle = collections.namedtuple("Triangle", "p0 p1 p2")
     itpl = _triangle(_point(0, 0), _point(1, 0), _point(0, 1))
     md0 = TT.make(itpl)
     otpl = TT.convert_to(md0, to_type=MG.NAMED_TUPLE_TYPE)
     self.assertEqual(otpl, itpl)
Beispiel #5
0
    def test_20_mdict(self):
        md0 = TT.make(_CNF_0)
        dic0 = TT.convert_to(md0)

        for k in "name a c e f".split():
            self.assertTrue(dic0[k] == md0[k], "%r vs. %r" % (dic0[k], md0[k]))

        for k in dic0["b"].keys():
            self.assertTrue(dic0["b"][k] == md0["b"][k])
Beispiel #6
0
    def test_20_mdict(self):
        md0 = TT.make(_CNF_0)
        dic0 = TT.convert_to(md0)

        for k in "name a c e f".split():
            self.assertTrue(dic0[k] == md0[k], "%r vs. %r" % (dic0[k], md0[k]))

        for k in dic0["b"].keys():
            self.assertTrue(dic0["b"][k] == md0["b"][k])
Beispiel #7
0
    def test_10_default(self):
        md0 = TT.make(_CNF_0)

        self.assertTrue(isinstance(md0, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0, MD.UpdateWithMergeDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithMergeDict))
        for k in "name a c e f".split():
            self.assertTrue(md0[k] == _CNF_0[k],
                            "%r vs. %r" % (md0[k], _CNF_0[k]))
Beispiel #8
0
    def test_30_ordered(self):
        md0 = TT.make(_CNF_0, ordered=True)

        self.assertTrue(isinstance(md0, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0, MD.UpdateWithMergeOrderedDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithMergeOrderedDict))
        for k in "name a c e f".split():
            self.assertTrue(md0[k] == _CNF_0[k],
                            "%r vs. %r" % (md0[k], _CNF_0[k]))
Beispiel #9
0
    def test_10_default(self):
        md0 = TT.make(_CNF_0)

        self.assertTrue(isinstance(md0, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0, MD.UpdateWithMergeDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithMergeDict))
        for k in "name a c e f".split():
            self.assertTrue(md0[k] == _CNF_0[k],
                            "%r vs. %r" % (md0[k], _CNF_0[k]))
Beispiel #10
0
    def test_30_ordered(self):
        md0 = TT.make(_CNF_0, ordered=True)

        self.assertTrue(isinstance(md0, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0, MD.UpdateWithMergeOrderedDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md0["b"], MD.UpdateWithMergeOrderedDict))
        for k in "name a c e f".split():
            self.assertTrue(md0[k] == _CNF_0[k],
                            "%r vs. %r" % (md0[k], _CNF_0[k]))
Beispiel #11
0
    def test_20_merge(self):
        md1 = TT.make(_CNF_0, merge=MG.MS_REPLACE)
        md2 = TT.make(_CNF_0, merge=MG.MS_NO_REPLACE)
        md3 = TT.make(_CNF_0, merge=MG.MS_DICTS_AND_LISTS)

        self.assertTrue(isinstance(md1, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md2, MD.UpdateWoReplaceDict))
        self.assertTrue(isinstance(md3, MD.UpdateWithMergeListsDict))

        for idx, mdn in enumerate((md1, md2, md3)):
            self.assertTrue(isinstance(mdn["b"], type(mdn)),
                            "#%d %r (%r)" % (idx, mdn["b"], type(mdn["b"])))
            for k in "name a c e f".split():
                self.assertTrue(mdn[k] == _CNF_0[k],
                                "%r vs. %r" % (mdn[k], _CNF_0[k]))

        raised = False
        md4 = None
        try:
            md4 = TT.make(_CNF_0, merge="invalid_merge")
        except ValueError:
            raised = True
        self.assertTrue(raised, "md4 = %r" % type(md4))
Beispiel #12
0
    def test_20_merge(self):
        md1 = TT.make(_CNF_0, merge=MG.MS_REPLACE)
        md2 = TT.make(_CNF_0, merge=MG.MS_NO_REPLACE)
        md3 = TT.make(_CNF_0, merge=MG.MS_DICTS_AND_LISTS)

        self.assertTrue(isinstance(md1, MD.UpdateWithReplaceDict))
        self.assertTrue(isinstance(md2, MD.UpdateWoReplaceDict))
        self.assertTrue(isinstance(md3, MD.UpdateWithMergeListsDict))

        for idx, mdn in enumerate((md1, md2, md3)):
            self.assertTrue(isinstance(mdn["b"], type(mdn)),
                            "#%d %r (%r)" % (idx, mdn["b"], type(mdn["b"])))
            for k in "name a c e f".split():
                self.assertTrue(mdn[k] == _CNF_0[k],
                                "%r vs. %r" % (mdn[k], _CNF_0[k]))

        raised = False
        md4 = None
        try:
            md4 = TT.make(_CNF_0, merge="invalid_merge")
        except ValueError:
            raised = True
        self.assertTrue(raised, "md4 = %r" % type(md4))
Beispiel #13
0
    def test_40_namedtuple(self):
        _point = collections.namedtuple("Point", "x y")
        _triangle = collections.namedtuple("Triangle", "p0 p1 p2")
        obj = _triangle(_point(0, 0), _point(1, 0), _point(0, 1))
        md0 = TT.make(obj)

        self.assertTrue(isinstance(md0, MD.UpdateWithMergeOrderedDict))
        self.assertTrue(isinstance(md0["p0"], MD.UpdateWithMergeOrderedDict))

        for k in "p0 p1 p2".split():
            self.assertEqual(md0[MG.NTPL_CLS_KEY], "Triangle")
            for k2 in "x y".split():
                self.assertEqual(md0[k][MG.NTPL_CLS_KEY], "Point")
                ref = getattr(getattr(obj, k), k2)
                self.assertTrue(md0[k][k2] == ref,
                                "%r vs. %r" % (md0[k][k2], ref))
Beispiel #14
0
    def test_40_namedtuple(self):
        _point = collections.namedtuple("Point", "x y")
        _triangle = collections.namedtuple("Triangle", "p0 p1 p2")
        obj = _triangle(_point(0, 0), _point(1, 0), _point(0, 1))
        md0 = TT.make(obj)

        self.assertTrue(isinstance(md0, MD.UpdateWithMergeOrderedDict))
        self.assertTrue(isinstance(md0["p0"], MD.UpdateWithMergeOrderedDict))

        for k in "p0 p1 p2".split():
            self.assertEqual(md0[MG.NTPL_CLS_KEY], "Triangle")
            for k2 in "x y".split():
                self.assertEqual(md0[k][MG.NTPL_CLS_KEY], "Point")
                ref = getattr(getattr(obj, k), k2)
                self.assertTrue(md0[k][k2] == ref,
                                "%r vs. %r" % (md0[k][k2], ref))