Skip to content

Commit

Permalink
add null detector (useful for testing and potentially later on
Browse files Browse the repository at this point in the history
supporting ip updates without a dedicated dedection mechanism)
  • Loading branch information
infothrill committed Feb 25, 2015
1 parent 50882e4 commit 4e13c3f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
39 changes: 39 additions & 0 deletions dyndnsc/detector/null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-

import logging

from .base import IPDetector

log = logging.getLogger(__name__)


class IPDetector_Null(IPDetector):

This comment has been minimized.

Copy link
@ThomasWaldmann

ThomasWaldmann Feb 25, 2015

Contributor

remove empty line?

This comment has been minimized.

Copy link
@infothrill

infothrill Feb 25, 2015

Author Owner

Just trying to stick to https://www.python.org/dev/peps/pep-0257/ ;-)

"""Dummy IP detector."""

def __init__(self, family=None, *args, **kwargs):
"""
Initializer.
:param family: IP address family (default: '' (ANY), also possible: 'INET', 'INET6')
"""
super(IPDetector_Null, self).__init__(*args, family=family, **kwargs)

@staticmethod
def names():
return ("null",)

def can_detect_offline(self):
"""Return true, as this detector generates no network traffic.
:return: True
"""
return True

def detect(self):
"""
Return None.
:rtype: None
"""
return None
9 changes: 9 additions & 0 deletions dyndnsc/tests/detector/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,12 @@ def test_webcheck46(self):
self.assertEqual(AF_UNSPEC, detector.af())
self.assertEqual(None, detector.get_current_value())
self.assertTrue(type(detector.detect()) in (type(None), str))

def test_null(self):
import dyndnsc.detector.null as null
self.assertTrue("null" in null.IPDetector_Null.names())
detector = null.IPDetector_Null()
self.assertTrue(detector.can_detect_offline())
self.assertEqual(AF_UNSPEC, detector.af())
self.assertEqual(None, detector.get_current_value())
self.assertTrue(type(detector.detect()) in (type(None), str))

0 comments on commit 4e13c3f

Please sign in to comment.