Example #1
0
        public void testSets()
        {
            byte[]    o;
            Pickler   p  = new Pickler(false);
            Unpickler up = new Unpickler();

            var intset = new HashSet <int>();

            intset.Add(1);
            intset.Add(2);
            intset.Add(3);
            o = p.dumps(intset);
            HashSet <object> resultset = (HashSet <object>)up.loads(o);

            AssertUtils.AssertEqual(intset, resultset);

            HashSet <string> stringset = new HashSet <string>();

            stringset.Add("A");
            stringset.Add("B");
            stringset.Add("C");
            o         = p.dumps(stringset);
            resultset = (HashSet <object>)up.loads(o);
            AssertUtils.AssertEqual(stringset, resultset);
        }
Example #2
0
        public void testMappings()
        {
            byte[]    o;
            Pickler   p      = new Pickler(false);
            Unpickler pu     = new Unpickler();
            var       intmap = new Dictionary <int, int>();

            intmap.Add(1, 11);
            intmap.Add(2, 22);
            intmap.Add(3, 33);
            o = p.dumps(intmap);
            Hashtable resultmap = (Hashtable)pu.loads(o);

            AssertUtils.AssertEqual(intmap, resultmap);

            var stringmap = new Dictionary <string, string>();

            stringmap.Add("A", "1");
            stringmap.Add("B", "2");
            stringmap.Add("C", "3");
            o         = p.dumps(stringmap);
            resultmap = (Hashtable)pu.loads(o);
            AssertUtils.AssertEqual(stringmap, resultmap);

            Hashtable table = new Hashtable();

            table.Add(1, 11);
            table.Add(2, 22);
            table.Add(3, 33);
            o         = p.dumps(table);
            resultmap = (Hashtable)pu.loads(o);
            AssertUtils.AssertEqual(table, resultmap);
        }
Example #3
0
        public void TestMappings()
        {
            Pickler   p      = new Pickler(false);
            Unpickler pu     = new Unpickler();
            var       intmap = new Dictionary <int, int> {
                { 1, 11 }, { 2, 22 }, { 3, 33 }
            };
            var       o         = p.dumps(intmap);
            Hashtable resultmap = (Hashtable)pu.loads(o);

            AssertUtils.AssertEqual(intmap, resultmap);

            var stringmap = new Dictionary <string, string> {
                { "A", "1" }, { "B", "2" }, { "C", "3" }
            };

            o         = p.dumps(stringmap);
            resultmap = (Hashtable)pu.loads(o);
            AssertUtils.AssertEqual(stringmap, resultmap);

            Hashtable table = new Hashtable {
                { 1, 11 }, { 2, 22 }, { 3, 33 }
            };

            o         = p.dumps(table);
            resultmap = (Hashtable)pu.loads(o);
            AssertUtils.AssertEqual(table, resultmap);
        }
Example #4
0
        public void testSet()
        {
            var set = new HashSet <object> {
                1, 2, "abc"
            };

            AssertUtils.AssertEqual(set, (HashSet <object>)U("c__builtin__\nset\np0\n((lp1\nI1\naI2\naS'abc'\np2\natp3\nRp4\n."));
        }
Example #5
0
        public void testBeans()
        {
            Pickler   p  = new Pickler(false);
            Unpickler pu = new Unpickler();

            byte[]   o;
            Relative person = new Relative("Tupac", true);

            o = p.dumps(person);
            Hashtable map     = (Hashtable)pu.loads(o);
            Hashtable testmap = new Hashtable();

            testmap.Add("Name", "Tupac");
            testmap.Add("Deceased", true);
            testmap.Add("Relation", "unspecified");
            testmap.Add("__class__", "Pyrolite.Tests.Pickle.PicklerTests+Relative");
            AssertUtils.AssertEqual(testmap, map);
        }
Example #6
0
        public void TestSets()
        {
            Pickler   p  = new Pickler(false);
            Unpickler up = new Unpickler();

            var intset = new HashSet <int> {
                1, 2, 3
            };
            var o = p.dumps(intset);
            HashSet <object> resultset = (HashSet <object>)up.loads(o);

            AssertUtils.AssertEqual(intset, resultset);

            HashSet <string> stringset = new HashSet <string> {
                "A", "B", "C"
            };

            o         = p.dumps(stringset);
            resultset = (HashSet <object>)up.loads(o);
            AssertUtils.AssertEqual(stringset, resultset);
        }
Example #7
0
        public void testDicts()
        {
            Hashtable map  = new Hashtable();
            Hashtable map2 = new Hashtable();
            ArrayList list = new ArrayList();

            Assert.AreEqual(map, U("}."));      // {}
            map.Add(97, 98);
            map.Add(99, 100);
            Assert.AreEqual(map, U("}(KaKbKcKdu."));               // {97: 98, 99: 100}
            Assert.AreEqual(map, U("(dI97\nI98\nsI99\nI100\ns.")); // {97: 98, 99: 100}
            Assert.AreEqual(map, U("(I97\nI98\nI99\nI100\nd."));   // {97: 98, 99: 100}

            map.Clear();
            map.Add(1, 2);
            map.Add(3, 4);
            map2.Add(5, 6);
            map2.Add(7, 8);
            list.Add(map);
            list.Add(map2);
            Assert.AreEqual(list, U("(lp0\n(dp1\nI1\nI2\nsI3\nI4\nsa(dp2\nI5\nI6\nsI7\nI8\nsa."));                                           // [{1:2, 3:4}, {5:6, 7:8}]
            Assert.AreEqual(list, U("\u0080\u0002]q\u0000(}q\u0001(K\u0001K\u0002K\u0003K\u0004u}q\u0002(K\u0005K\u0006K\u0007K\u0008ue.")); // [{1:2, 3:4}, {5:6, 7:8}]

            map.Clear();
            map2.Clear();
            list.Clear();

            map["abc"] = null;
            Assert.AreEqual(map, U("(dp0\nS'abc'\np1\nNs."));                     // {'abc': None}
            Assert.AreEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001Ns."));  // {'abc': None}
            map["abc"] = 111;
            Assert.AreEqual(map, U("(dp0\nS'abc'\np1\nI111\ns."));                // {'abc': 111}
            Assert.AreEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001Kos.")); // {'abc': 111}
            list.Add(111);
            list.Add(111);
            map["abc"] = list;
            AssertUtils.AssertEqual(map, U("(dp0\nS'abc'\np1\n(lp2\nI111\naI111\nas."));                            // {'abc': [111,111]}
            AssertUtils.AssertEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001]q\u0002(KoKoes."));               // {'abc': 111}
            map["abc"] = map2;
            AssertUtils.AssertEqual(map, U("(dp0\nS'abc'\np1\n(dp2\ns."));                                          // {'abc': {} }
            AssertUtils.AssertEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001}q\u0002s."));                     // {'abc': {} }
            map2["def"] = 111;
            AssertUtils.AssertEqual(map, U("(dp0\nS'abc'\np1\n(dp2\nS'def'\np3\nI111\nss."));                       // {'abc': {'def':111}}
            AssertUtils.AssertEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001}q\u0002U\u0003defq\u0003Koss.")); // {'abc': {'def':111}}

            map2["def"] = list;
            AssertUtils.AssertEqual(map, U("(dp0\nS'abc'\np1\n(dp2\nS'def'\np3\n(lp4\nI111\naI111\nass."));                     // {'abc': {'def': [111,111] }}
            AssertUtils.AssertEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001}q\u0002U\u0003defq\u0003]q\u0004(KoKoess.")); // {'abc': {'def': [111,111] }}

            ArrayList list2 = new ArrayList();

            list2.Add(222);
            list2.Add(222);
            map2["ghi"] = list2;
            AssertUtils.AssertEqual(map, U("(dp0\nS'abc'\np1\n(dp2\nS'ghi'\np3\n(lp4\nI222\naI222\nasS'def'\np5\n(lp6\nI111\naI111\nass."));                              // {'abc': {'def': [111,111], ghi: [222,222] }}
            AssertUtils.AssertEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001}q\u0002(U\u0003ghiq\u0003]q\u0004(K\u00deK\u00deeU\u0003defq\u0005]q\u0006(KoKoeus.")); // {'abc': {'def': [111,111], ghi: [222,222] }}

            map2.Clear();
            map2["def"] = list;
            map2["abc"] = list;
            AssertUtils.AssertEqual(map, U("(dp0\nS'abc'\np1\n(dp2\ng1\n(lp3\nI111\naI111\nasS'def'\np4\ng3\nss."));                           // {'abc': {'def': [111,111], abc: [111,111] }}
            AssertUtils.AssertEqual(map, U("\u0080\u0002}q\u0000U\u0003abcq\u0001}q\u0002(h\u0001]q\u0003(KoKoeU\u0003defq\u0004h\u0003us.")); // {'abc': {'def': [111,111], abc: [111,111] }}
        }