File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,15 @@ PYTHON=python3
6
6
7
7
LEEP_CORE =base.py raw.py ca.py file.py logic.py
8
8
9
- all : test_cli
9
+ all : test_cli test_raw
10
10
11
11
test_cli : $(LEEP_CORE ) cli.py
12
12
PYTHONPATH=" $( THIS_DIR) /..:$( BUILD_DIR) " $(PYTHON ) -m leep.test.test_cli test
13
13
14
+ .PHONY : test_raw
15
+ test_raw : raw.py
16
+ @PYTHONPATH=" $( THIS_DIR) /.." $(PYTHON ) -m leep.test.test_raw
17
+
14
18
# This is a test target currently only used for manual testing. Development is in progress
15
19
# for including this in automated regression tests.
16
20
server : $(LEEP_CORE ) cli.py
Original file line number Diff line number Diff line change @@ -111,11 +111,13 @@ def _int(s):
111
111
return int (s )
112
112
except ValueError :
113
113
pass
114
- bases = (2 , 16 , 10 )
115
- for base in bases :
114
+ if hasattr (s , 'startswith' ):
116
115
try :
117
- return int (s , base )
118
- except (TypeError , ValueError ):
116
+ if s .startswith ('0x' ):
117
+ return int (s , 16 )
118
+ elif s .startswith ('0b' ):
119
+ return int (s , 2 )
120
+ except ValueError :
119
121
pass
120
122
return None
121
123
Original file line number Diff line number Diff line change @@ -189,3 +189,29 @@ def test_array(self):
189
189
self .assertEqual (self .serv .data [101 ], 0xdeadbeef )
190
190
self .assertEqual (self .serv .data [102 ], 0x12345679 )
191
191
self .assertEqual (self .serv .data [103 ], 0xdeadbeef )
192
+
193
+
194
+ def test_raw_int ():
195
+ from leep .raw import _int
196
+ tests = {
197
+ "foo" : None ,
198
+ "123" : 123 ,
199
+ "0x100" : 0x100 ,
200
+ "0b1000" : 0b1000 ,
201
+ "0xreg" : None ,
202
+ "0bentry" : None ,
203
+ }
204
+ for key , val in tests .items ():
205
+ if val != _int (key ):
206
+ raise Exception ("Test failed _int({}) = {} != {}" .format (key , _int (key ), val ))
207
+ return True
208
+
209
+
210
+ def doTests ():
211
+ test_raw_int ()
212
+ print ("PASS" )
213
+ return
214
+
215
+
216
+ if __name__ == "__main__" :
217
+ doTests ()
You can’t perform that action at this time.
0 commit comments