File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ def from_other(cls, other):
88 return DiceException (* other .args )
99 elif isinstance (other , ParseFatalException ):
1010 return DiceFatalException (* other .args )
11- return cls (* other .args )
11+ raise NotImplementedError (
12+ 'DiceBaseException can only wrap ParseException or ParseFatalException'
13+ )
1214
1315 def pretty_print (self ):
1416 string , location , description = self .args
Original file line number Diff line number Diff line change 11from __future__ import absolute_import
22
33from dice .constants import DiceExtreme
4- from dice .exceptions import DiceFatalException
4+ from dice .exceptions import DiceException , DiceFatalException
5+ import pickle
56from pytest import raises
67import random
78
@@ -135,6 +136,13 @@ def test_roll_error(self):
135136 rolled = roll ("6d6" )
136137 rolled .do_roll_single (4 , 3 )
137138
139+ def test_invalid_wrap (self ):
140+ with raises (NotImplementedError ):
141+ try :
142+ raise RuntimeError ('blah' )
143+ except Exception as e :
144+ raise DiceException .from_other (e )
145+
138146
139147class TestEvaluate (object ):
140148 def test_cache (self ):
@@ -191,3 +199,18 @@ def test_sysrandom_op(self):
191199
192200 def test_sysrandom_roll (self ):
193201 roll ("6d6" , random = self .sysrandom )
202+
203+
204+ class TestPickle (object ):
205+ for expr in [
206+ '-d20' ,
207+ '4d6t' ,
208+ '+-(1,2,3)' ,
209+ '2d20h' ,
210+ '4d6h3s' ,
211+ '4dF - 2' ,
212+ '4*d%'
213+ ]:
214+ value = roll (expr , raw = True , single = False )
215+ pickled = pickle .dumps (value )
216+ clone = pickle .loads (pickled )
You can’t perform that action at this time.
0 commit comments