remove doctest-ignore-unicode dependency

This commit is contained in:
Martin Zimmermann 2014-03-28 12:05:51 +01:00
parent 4fa0f0d8ea
commit 5166e69265
7 changed files with 98 additions and 70 deletions

View File

@ -38,8 +38,8 @@ site: $(RST) $(WWW) $(CSS)
cd docs && sphinx-build -b dirhtml . _build/html
coverage:
nosetests --with-doctest --with-doctest-ignore-unicode --with-coverage \
--cover-package=isso --cover-html isso/ specs/
nosetests --with-doctest --with-coverage --cover-package=isso \
--cover-html isso/ specs/
clean:
rm -f $(MAN) $(CSS) $(ISSO_JS_DST) $(ISSO_CSS_DST)

View File

@ -57,28 +57,6 @@ class IssoParser(ConfigParser):
Extended :class:`ConfigParser` to parse human-readable timedeltas
into seconds and handles multiple values per key.
>>> import io
>>> parser = IssoParser(allow_no_value=True)
>>> parser.read_file(io.StringIO(u'''
... [foo]
... bar = 1h
... baz = 12
... spam = a, b, cdef
... bla =
... spam
... ham
... asd = fgh
... '''))
>>> parser.getint("foo", "bar")
3600
>>> parser.getint("foo", "baz")
12
>>> parser.getlist("foo", "spam") # doctest: +IGNORE_UNICODE
['a', 'b', 'cdef']
>>> list(parser.getiter("foo", "bla")) # doctest: +IGNORE_UNICODE
['spam', 'ham']
>>> list(parser.getiter("foo", "asd")) # doctest: +IGNORE_UNICODE
['fgh']
"""
@classmethod

View File

@ -27,12 +27,6 @@ def anonymize(remote_addr):
Anonymize IPv4 and IPv6 :param remote_addr: to /24 (zero'd)
and /48 (zero'd).
>>> anonymize(u'12.34.56.78') # doctest: +IGNORE_UNICODE
'12.34.56.0'
>>> anonymize(u'1234:5678:90ab:cdef:fedc:ba09:8765:4321') # doctest: +IGNORE_UNICODE
'1234:5678:90ab:0000:0000:0000:0000:0000'
>>> anonymize(u'::ffff:127.0.0.1') # doctest: +IGNORE_UNICODE
'127.0.0.0'
"""
try:
ipv4 = ipaddress.IPv4Address(remote_addr)

View File

@ -56,44 +56,6 @@ def thread(data, default=u"Untitled.", id=None):
"""
Extract <h1> title from web page. The title is *probably* the text node,
which is the nearest H1 node in context to an element with the `isso-thread` id.
>>> thread("asdf") # doctest: +IGNORE_UNICODE
(None, 'Untitled.')
>>> thread('''
... <html>
... <head>
... <title>Foo!</title>
... </head>
... <body>
... <header>
... <h1>generic website title.</h1>
... <h2>subtile title.</h2>
... </header>
... <article>
... <header>
... <h1>Can you find me?</h1>
... </header>
... <section id="isso-thread">
... </section>
... </article>
... </body>
... </html>''') # doctest: +IGNORE_UNICODE
(None, 'Can you find me?')
>>> thread('''
... <html>
... <body>
... <h1>I'm the real title!1
... <section data-title="No way%21" id="isso-thread">
... ''') # doctest: +IGNORE_UNICODE
(None, 'No way!')
>>> thread('''
... <section id="isso-thread" data-title="Test" data-isso-id="test">
... ''') # doctest: +IGNORE_UNICODE
('test', 'Test')
>>> thread('''
... <section id="isso-thread" data-isso-id="Fuu.">
... ''') # doctest: +IGNORE_UNICODE
('Fuu.', 'Untitled.')
"""
html = html5lib.parse(data, treebuilder="dom")

32
specs/test_core.py Normal file
View File

@ -0,0 +1,32 @@
# -*- encoding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
import io
from isso import core
class TestConfig(unittest.TestCase):
def test_parser(self):
parser = core.IssoParser(allow_no_value=True)
parser.read_file(io.StringIO(u"""
[foo]
bar = 1h
baz = 12
spam = a, b, cdef
bla =
spam
ham
asd = fgh"""))
self.assertEqual(parser.getint("foo", "bar"), 3600)
self.assertEqual(parser.getint("foo", "baz"), 12)
self.assertEqual(parser.getlist("foo", "spam"), ['a', 'b', 'cdef'])
self.assertEqual(list(parser.getiter("foo", "bla")), ['spam', 'ham'])
self.assertEqual(list(parser.getiter("foo", "asd")), ['fgh'])

63
specs/test_utils.py Normal file
View File

@ -0,0 +1,63 @@
# -*- encoding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
from isso import utils
from isso.utils import parse
class TestUtils(unittest.TestCase):
def test_anonymize(self):
examples = [
(u'12.34.56.78', u'12.34.56.0'),
(u'1234:5678:90ab:cdef:fedc:ba09:8765:4321', u'1234:5678:90ab:0000:0000:0000:0000:0000'),
(u'::ffff:127.0.0.1', u'127.0.0.0')]
for (addr, anonymized) in examples:
self.assertEqual(utils.anonymize(addr), anonymized)
class TestParse(unittest.TestCase):
def test_thread(self):
self.assertEqual(parse.thread("asdf"), (None, 'Untitled.'))
self.assertEqual(parse.thread("""
<html>
<head>
<title>Foo!</title>
</head>
<body>
<header>
<h1>generic website title.</h1>
<h2>subtile title.</h2>
</header>
<article>
<header>
<h1>Can you find me?</h1>
</header>
<section id="isso-thread">
</section>
</article>
</body>
</html>"""), (None, 'Can you find me?'))
self.assertEqual(parse.thread("""
<html>
<body>
<h1>I'm the real title!1
<section data-title="No way%21" id="isso-thread">
"""), (None, 'No way!'))
self.assertEqual(parse.thread("""
<section id="isso-thread" data-title="Test" data-isso-id="test">
"""), ('test', 'Test'))
self.assertEqual(parse.thread('<section id="isso-thread" data-isso-id="Fuu.">'),
('Fuu.', 'Untitled.'))

View File

@ -22,8 +22,7 @@ deps =
[testenv]
deps =
nose
doctest-ignore-unicode
commands =
nosetests --with-doctest --with-doctest-ignore-unicode isso/ specs/
nosetests --with-doctest isso/ specs/
install_command =
pip install --allow-external ipaddr --allow-unverified ipaddr {opts} {packages}