summaryrefslogtreecommitdiff
blob: 5ac64a256cb6b7a047799f52f3eb437565c0d43a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Upstream: https://github.com/DiffSK/configobj/commit/e2731538d1a37a5b67a6e518848be6a8988043ae

diff --git a/tests/test_validate.py b/tests/test_validate.py
index bffb0dc..4eed7e9 100644
--- a/tests/test_validate.py
+++ b/tests/test_validate.py
@@ -161,3 +161,26 @@ class TestBasic(object):
                     'test3': 3,
                     'test4': 6.0
         }}}
+
+
+class TestDottedQuadToNum(object):
+
+    def test_stripped(self):
+        assert dottedQuadToNum('192.0.2.0') == 3221225984
+        assert dottedQuadToNum('192.0.2.1 ') == 3221225985
+        assert dottedQuadToNum(' 192.0.2.2') == 3221225986
+        assert dottedQuadToNum('\t\t192.0.2.3\n') == 3221225987
+        with pytest.raises(ValueError) as excinfo:
+            dottedQuadToNum('192. 0. 2. 4')
+        assert str(excinfo.value) == 'Not a good dotted-quad IP: 192. 0. 2. 4'
+
+    def test_boundaries(self):
+        assert dottedQuadToNum('0.0.0.0') == 0
+        assert dottedQuadToNum('255.255.255.255') == 4294967295
+        with pytest.raises(ValueError) as excinfo:
+            dottedQuadToNum('255.255.255.256')
+        assert str(excinfo.value) == (
+            'Not a good dotted-quad IP: 255.255.255.256')
+        with pytest.raises(ValueError) as excinfo:
+            dottedQuadToNum('-1')
+        assert str(excinfo.value) == 'Not a good dotted-quad IP: -1'
diff --git a/validate.py b/validate.py
index b7a964c..9d8c94d 100644
--- a/validate.py
+++ b/validate.py
@@ -277,17 +277,8 @@ def dottedQuadToNum(ip):
     
     >>> int(dottedQuadToNum('1 '))
     1
-    >>> int(dottedQuadToNum(' 1.2'))
-    16777218
-    >>> int(dottedQuadToNum(' 1.2.3 '))
-    16908291
     >>> int(dottedQuadToNum('1.2.3.4'))
     16909060
-    >>> dottedQuadToNum('255.255.255.255')
-    4294967295
-    >>> dottedQuadToNum('255.255.255.256')
-    Traceback (most recent call last):
-    ValueError: Not a good dotted-quad IP: 255.255.255.256
     """
     
     # import here to avoid it when ip_addr values are not used