parent
4fa0f0d8ea
commit
5166e69265
@ -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'])
|
@ -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.'))
|
Loading…
Reference in new issue