瀏覽代碼

Bugfix in pickling/unpickling

Yann Weber 3 年之前
父節點
當前提交
4f6bbd30f0
共有 2 個文件被更改,包括 14 次插入1 次删除
  1. 1
    0
      rpn_jit.c
  2. 13
    1
      tests/tests_pyrpn.py

+ 1
- 0
rpn_jit.c 查看文件

@@ -152,6 +152,7 @@ int rpn_expr_untokenize(rpn_expr_t *expr, rpn_tokenized_t *tokens, char long_op)
152 152
 			goto ret_err;
153 153
 		}
154 154
 	}
155
+	expr->toks.tokens_sz = tokens->tokens_sz;
155 156
 
156 157
 	if(_rpn_expr_end_map(expr))
157 158
 	{

+ 13
- 1
tests/tests_pyrpn.py 查看文件

@@ -118,7 +118,19 @@ class Test0RpnModule(unittest.TestCase):
118 118
         entropy = 1-sum([(n/all_count)**2
119 119
                           for _, n in counters.items()])
120 120
         self.assertGreater(entropy, 1-(1/all_ops), "Low entropy !")
121
-                
121
+    
122
+    def test_pickle_state(self):
123
+        """ Testing pickling/unpickling """
124
+        e = pyrpn.RPNExpr(pyrpn.random_expr(2), 2)
125
+
126
+        e2 = pickle.loads(pickle.dumps(e))
127
+
128
+        self.assertEqual(e.__getstate__(), e2.__getstate__())
129
+
130
+        e3 = pickle.loads(pickle.dumps(e2))
131
+
132
+        self.assertEqual(e.__getstate__(), e3.__getstate__())
133
+        self.assertEqual(e2.__getstate__(), e3.__getstate__())
122 134
 
123 135
 if __name__ == '__main__':
124 136
     unittest.main()

Loading…
取消
儲存