1212
1313import snap7
1414from snap7 import util
15- from snap7 .exceptions import Snap7Exception
1615from snap7 .common import check_error
1716from snap7 .server import mainloop
1817from snap7 .types import S7AreaDB , S7DataItem , S7SZL , S7SZLList , buffer_type , buffer_size , S7Object , Areas , WordLen
@@ -61,7 +60,7 @@ def _as_check_loop(self, check_times=20) -> int:
6160 break
6261 time .sleep (0.5 )
6362 else :
64- raise Snap7Exception (f"Async Request not finished after { check_times } times - Fail" )
63+ raise TimeoutError (f"Async Request not finished after { check_times } times - Fail" )
6564 return check_status .value
6665
6766 def test_db_read (self ):
@@ -156,13 +155,13 @@ def test_upload(self):
156155 this raises an exception due to missing authorization? maybe not
157156 implemented in server emulator
158157 """
159- self .assertRaises (Snap7Exception , self .client .upload , db_number )
158+ self .assertRaises (RuntimeError , self .client .upload , db_number )
160159
161160 def test_as_upload (self ):
162161 _buffer = buffer_type ()
163162 size = ctypes .c_int (ctypes .sizeof (_buffer ))
164163 self .client .as_upload (1 , _buffer , size )
165- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
164+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
166165
167166 @unittest .skip ("TODO: invalid block size" )
168167 def test_download (self ):
@@ -229,7 +228,7 @@ def test_list_blocks(self):
229228 def test_list_blocks_of_type (self ):
230229 self .client .list_blocks_of_type ('DB' , 10 )
231230
232- self .assertRaises (Snap7Exception , self .client .list_blocks_of_type , 'NOblocktype' , 10 )
231+ self .assertRaises (ValueError , self .client .list_blocks_of_type , 'NOblocktype' , 10 )
233232
234233 def test_get_block_info (self ):
235234 """test Cli_GetAgBlockInfo"""
@@ -592,7 +591,7 @@ def test_wait_as_completion_timeouted(self, timeout=0, tries=500):
592591 try :
593592 res = self .client .wait_as_completion (timeout )
594593 check_error (res )
595- except Snap7Exception as s7_err :
594+ except RuntimeError as s7_err :
596595 if not s7_err .args [0 ] == b'CLI : Job Timeout' :
597596 self .fail (f"While waiting another error appeared: { s7_err } " )
598597 # Wait for a thread to finish
@@ -712,24 +711,24 @@ def test_as_eb_read(self):
712711 buffer = (type_ * 1 )()
713712 response = self .client .as_eb_read (0 , 1 , buffer )
714713 self .assertEqual (0 , response )
715- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
714+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
716715
717716 def test_as_eb_write (self ):
718717 # Cli_AsEBWrite
719718 response = self .client .as_eb_write (0 , 1 , bytearray (b'\x00 ' ))
720719 self .assertEqual (0 , response )
721- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
720+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
722721
723722 def test_as_full_upload (self ):
724723 # Cli_AsFullUpload
725724 self .client .as_full_upload ('DB' , 1 )
726- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
725+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
727726
728727 def test_as_list_blocks_of_type (self ):
729728 data = (ctypes .c_uint16 * 10 )()
730729 count = ctypes .c_int ()
731730 self .client .as_list_blocks_of_type ('DB' , data , count )
732- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
731+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
733732
734733 def test_as_mb_read (self ):
735734 # Cli_AsMBRead
@@ -738,13 +737,13 @@ def test_as_mb_read(self):
738737 data = (type_ * 1 )()
739738 self .client .as_mb_read (0 , 1 , data )
740739 bytearray (data )
741- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
740+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
742741
743742 def test_as_mb_write (self ):
744743 # Cli_AsMBWrite
745744 response = self .client .as_mb_write (0 , 1 , bytearray (b'\x00 ' ))
746745 self .assertEqual (0 , response )
747- self .assertRaises (Snap7Exception , self .client .wait_as_completion , 500 )
746+ self .assertRaises (RuntimeError , self .client .wait_as_completion , 500 )
748747
749748 def test_as_read_szl (self ):
750749 # Cli_AsReadSZL
@@ -927,8 +926,8 @@ def test_read_szl(self):
927926 # read_szl_invalid_id
928927 ssl_id = 0xffff
929928 index = 0xffff
930- self .assertRaises (Snap7Exception , self .client .read_szl , ssl_id )
931- self .assertRaises (Snap7Exception , self .client .read_szl , ssl_id , index )
929+ self .assertRaises (RuntimeError , self .client .read_szl , ssl_id )
930+ self .assertRaises (RuntimeError , self .client .read_szl , ssl_id , index )
932931
933932 def test_read_szl_list (self ):
934933 # Cli_ReadSZLList
@@ -952,7 +951,7 @@ def test_tm_write(self):
952951 data = b'\x10 \x01 '
953952 self .assertEqual (0 , self .client .tm_write (0 , 1 , bytearray (data )))
954953 self .assertEqual (data , self .client .tm_read (0 , 1 ))
955- self .assertRaises (Snap7Exception , self .client .tm_write , 0 , 100 , bytes (200 ))
954+ self .assertRaises (RuntimeError , self .client .tm_write , 0 , 100 , bytes (200 ))
956955 self .assertRaises (ValueError , self .client .tm_write , 0 , 2 , bytes (2 ))
957956
958957 def test_write_multi_vars (self ):
0 commit comments