8282
8383from privex import helpers
8484from privex .loghelper import LogHelper
85- from privex .helpers import ip_to_rdns , BoundaryException , plugin , r_cache , random_str , CacheAdapter , env_bool
85+ from privex .helpers import ping , ip_to_rdns , BoundaryException , plugin , r_cache , random_str , CacheAdapter , env_bool
8686
8787if env_bool ('DEBUG' , False ) is True :
8888 LogHelper ('privex.helpers' , level = logging .DEBUG ).add_console_handler (logging .DEBUG )
@@ -426,7 +426,7 @@ class TestCacheDecoratorRedis(TestCacheDecoratorMemory):
426426 @classmethod
427427 def setUpClass (cls ):
428428 if not plugin .HAS_REDIS :
429- print ('The package "redis" is not installed, skipping Redis dependent tests.' )
429+ print (f 'The package "redis" is not installed, skipping Redis dependent tests ( { cls . __name__ } ) .' )
430430 return cls .tearDownClass ()
431431 helpers .cache .adapter_set (helpers .RedisCache ())
432432
@@ -437,6 +437,17 @@ class TestGeneral(PrivexBaseCase):
437437 def setUp (self ):
438438 self .tries = 0
439439
440+ def test_ping (self ):
441+ """Test success & failure cases for ping function, as well as input validation"""
442+ with self .assertRaises (ValueError ):
443+ ping ('127.0.0.1' , - 1 )
444+ with self .assertRaises (ValueError ):
445+ ping ('127.0.0.1' , 0 )
446+ with self .assertRaises (ValueError ):
447+ ping ('notavalidip' , 1 )
448+ self .assertTrue (ping ('127.0.0.1' , 3 ))
449+ self .assertFalse (ping ('192.0.2.0' , 3 ))
450+
440451 def test_chunked (self ):
441452 """Create a 20 element long list, split it into 4 chunks, and verify the chunks are correctly made"""
442453 x = list (range (0 , 20 ))
@@ -602,6 +613,9 @@ class TestRedisCache(TestMemoryCache):
602613 @classmethod
603614 def setUpClass (cls ):
604615 """Set the current cache adapter to an instance of RedisCache() and make it available through ``self.cache``"""
616+ if not plugin .HAS_REDIS :
617+ print (f'The package "redis" is not installed, skipping Redis dependent tests ({ cls .__name__ } ).' )
618+ return cls .tearDownClass ()
605619 helpers .cache .adapter_set (helpers .RedisCache ())
606620 cls .cache = helpers .cache
607621
@@ -642,4 +656,4 @@ def setUpClass(cls):
642656HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
643657OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
644658SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
645- """
659+ """
0 commit comments