Add test suite
This commit adds a test suite and fixes replacement of ip address nodes for IP addresses that are not part of a IP range directive.
This commit is contained in:
parent
a5c82a6985
commit
869039df5d
8 changed files with 113 additions and 15 deletions
|
@ -13,13 +13,13 @@
|
|||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys
|
||||
import os
|
||||
#import sys
|
||||
#import os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
#sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ Contents:
|
|||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
testpage1
|
||||
testpage2
|
||||
|
||||
|
||||
Indices and tables
|
||||
|
|
6
tests/root/testpage1.rst
Normal file
6
tests/root/testpage1.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
Test page 1
|
||||
===========
|
||||
|
||||
.. ip:v4range:: 192.168.0.1/24
|
||||
|
||||
.. ip:v6range:: 2001:dead:beef::/64
|
8
tests/root/testpage2.rst
Normal file
8
tests/root/testpage2.rst
Normal file
|
@ -0,0 +1,8 @@
|
|||
Test page 2
|
||||
===========
|
||||
|
||||
This page contains IP addresses :ip:v4:`127.0.0.1`, :ip:v4:`192.168.0.1` and
|
||||
:ip:v6:`2001:dead:beef::1` as well as :ip:v6:`::1`.
|
||||
|
||||
There is also :ip:v6range:`2001:dada:b001::/64` and
|
||||
:ip:v4range:`172.16.0.0/24`.
|
43
tests/run.py
Executable file
43
tests/run.py
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
jandd.sphinxext.ip unit test driver
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This script runs the jandd.sphinxext.ip unit test suite.
|
||||
|
||||
:copyright: Copyright 2016 Jan Dittberner
|
||||
:license: GPLv3+, see COPYING for details.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from os import path
|
||||
import unittest
|
||||
|
||||
|
||||
def run(extra_args=[]):
|
||||
sys.path.insert(0, path.join(path.dirname(__file__), path.pardir))
|
||||
sys.path.insert(1, path.abspath(
|
||||
path.join(path.dirname(__file__), path.pardir,
|
||||
'jandd', 'sphinxext', 'ip'
|
||||
))
|
||||
)
|
||||
|
||||
try:
|
||||
import sphinx
|
||||
except ImportError:
|
||||
print("The sphinx package is needed to run the jandd.sphinxext.ip "
|
||||
"test suite.")
|
||||
|
||||
import test_ip
|
||||
|
||||
print("Running jandd.sphinxext.ip test suite ...")
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(
|
||||
test_ip.TestIPExtension
|
||||
)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
|
@ -1,20 +1,60 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from io import StringIO
|
||||
from .util import TestApp, test_root
|
||||
from util import TestApp, test_root
|
||||
import unittest
|
||||
|
||||
|
||||
IP4_ADDRESSES = ['127.0.0.1', '192.168.0.1']
|
||||
IP6_ADDRESSES = ['::1', '2001:dead:beef::1']
|
||||
IP4_RANGES = ['172.16.0.0/24', '192.168.0.0/24']
|
||||
IP6_RANGES = ['2001:dead:beef::/64', '2001:dada:b001::/64']
|
||||
|
||||
|
||||
class TestIPExtension(unittest.TestCase):
|
||||
def setUp(self):
|
||||
if not (test_root / '_static').exists():
|
||||
(test_root / '_static').mkdir()
|
||||
self.feed_warnfile = StringIO()
|
||||
self.app = TestApp(
|
||||
buildername='html', warning=self.feed_warnfile, cleanenv=True)
|
||||
self.app.build(force_all=True, filenames=[])
|
||||
|
||||
def tearDown(self):
|
||||
self.app.cleanup()
|
||||
(test_root / '_build').rmtree(True)
|
||||
|
||||
def test_ip4_role(self):
|
||||
feed_warnfile = self.feed_warnfile
|
||||
app = TestApp(buildername='html', warning=feed_warnfile, cleanenv=True)
|
||||
app.build(force_all=True, filenames=[])
|
||||
def test_ip_domaindata(self):
|
||||
self.assertIn('ip', self.app.env.domaindata)
|
||||
ipdomdata = self.app.env.domaindata['ip']
|
||||
self.assertIn('v4', ipdomdata)
|
||||
self.assertIn('v6', ipdomdata)
|
||||
self.assertIn('v4range', ipdomdata)
|
||||
self.assertIn('v6range', ipdomdata)
|
||||
self.assertIn('ips', ipdomdata)
|
||||
|
||||
def find_in_index(self, entry):
|
||||
indexentries = self.app.env.indexentries
|
||||
for index in indexentries:
|
||||
for value in indexentries[index]:
|
||||
if value[1] == entry:
|
||||
return
|
||||
self.fail("%s not found in index" % entry)
|
||||
|
||||
def test_ip4_addresses(self):
|
||||
ipv4 = self.app.env.domaindata['ip']['v4']
|
||||
ips = self.app.env.domaindata['ip']['ips']
|
||||
for ip in IP4_ADDRESSES:
|
||||
self.assertIn(ip, ipv4)
|
||||
self.assertIn(ip, [item['ip'] for item in ips])
|
||||
self.find_in_index("IPv4 address; %s" % ip)
|
||||
self.find_in_index("%s; Test page 2" % ip)
|
||||
|
||||
def test_ip6_addresses(self):
|
||||
ipv6 = self.app.env.domaindata['ip']['v6']
|
||||
ips = self.app.env.domaindata['ip']['ips']
|
||||
for ip in IP6_ADDRESSES:
|
||||
self.assertIn(ip, ipv6)
|
||||
self.assertIn(ip, [item['ip'] for item in ips])
|
||||
self.find_in_index("IPv6 address; %s" % ip)
|
||||
self.find_in_index("%s; Test page 2" % ip)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue