mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-09 07:04:44 +00:00
added tests for more coverage
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3041 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
3a5f06cfa9
commit
3f6ac53fff
3 changed files with 153 additions and 17 deletions
|
|
@ -76,6 +76,38 @@ class TestListDict (tests.StandardTest):
|
|||
self.d[x] = x
|
||||
for i, k in enumerate(self.d.keys()):
|
||||
self.assertEqual(self.d[k], toinsert[i])
|
||||
for i, k in enumerate(self.d.iterkeys()):
|
||||
self.assertEqual(self.d[k], toinsert[i])
|
||||
for x in self.d.values():
|
||||
self.assert_(x in toinsert)
|
||||
for x in self.d.itervalues():
|
||||
self.assert_(x in toinsert)
|
||||
for x, y in self.d.items():
|
||||
self.assert_(x in toinsert)
|
||||
self.assert_(y in toinsert)
|
||||
for x, y in self.d.iteritems():
|
||||
self.assert_(x in toinsert)
|
||||
self.assert_(y in toinsert)
|
||||
|
||||
def test_clear (self):
|
||||
"""
|
||||
Test clearing.
|
||||
"""
|
||||
self.assert_(not self.d)
|
||||
self.d[2] = 1
|
||||
self.d[1] = 3
|
||||
self.d.clear()
|
||||
self.assert_(not self.d)
|
||||
|
||||
def test_get_true (self):
|
||||
"""
|
||||
Test getting a non-False object.
|
||||
"""
|
||||
self.assert_(not self.d)
|
||||
self.d["a"] = 0
|
||||
self.d["b"] = 1
|
||||
self.assertEqual(self.d.get_true("a", 2), 2)
|
||||
self.assertEqual(self.d.get_true("b", 2), 1)
|
||||
|
||||
|
||||
class TestSetList (tests.StandardTest):
|
||||
|
|
@ -118,6 +150,17 @@ class TestSetList (tests.StandardTest):
|
|||
self.assertEqual(self.l[0], 1)
|
||||
self.assertEqual(self.l[1], 2)
|
||||
|
||||
def test_insert (self):
|
||||
"""
|
||||
Test insert and equal elements.
|
||||
"""
|
||||
self.assert_(not self.l)
|
||||
self.l.append(2)
|
||||
self.l.insert(0, 1)
|
||||
self.assertEqual(len(self.l), 2)
|
||||
self.assertEqual(self.l[0], 1)
|
||||
self.assertEqual(self.l[1], 2)
|
||||
|
||||
def test_setitem (self):
|
||||
"""
|
||||
Test setting of equal elements.
|
||||
|
|
@ -165,6 +208,40 @@ class TestLRU (tests.StandardTest):
|
|||
# zero must have been deleted
|
||||
self.assert_(not self.lru.has_key('0'))
|
||||
|
||||
def test_init (self):
|
||||
"""
|
||||
Test initializing.
|
||||
"""
|
||||
lru = linkcheck.containers.LRU(1, {1: 2})
|
||||
self.assert_(1 in lru)
|
||||
self.assertEqual(lru[1], 2)
|
||||
|
||||
def test_iters (self):
|
||||
"""
|
||||
Test initializing.
|
||||
"""
|
||||
toinsert = random.sample(xrange(6000000), self.count)
|
||||
for x in toinsert:
|
||||
self.lru[x] = x
|
||||
for x in self.lru:
|
||||
self.assert_(x in toinsert)
|
||||
for x in self.lru.keys():
|
||||
self.assert_(x in toinsert)
|
||||
for x in self.lru.iterkeys():
|
||||
self.assert_(x in toinsert)
|
||||
for x in self.lru.itervalues():
|
||||
self.assert_(x in toinsert)
|
||||
for x, y in self.lru.iteritems():
|
||||
self.assert_(x in toinsert)
|
||||
self.assert_(y in toinsert)
|
||||
|
||||
def test_setdefault (self):
|
||||
"""
|
||||
Test setting of default values.
|
||||
"""
|
||||
self.assertEqual(self.lru.setdefault("hulla", "bla"), "bla")
|
||||
self.assertEqual(self.lru.setdefault("hulla", "bla"), "bla")
|
||||
|
||||
|
||||
def test_suite ():
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -116,10 +116,10 @@ parsetests = [
|
|||
("""<a href='"' >""", """<a href=""">"""),
|
||||
("""<a href="bla" %]" >""", """<a href="bla">"""),
|
||||
("""<a href=bla" >""", """<a href="bla">"""),
|
||||
("""<a onmouseover=MM_swapImage('nav1','',"""\
|
||||
"""'/images/dwnavpoint_over.gif',1);movein(this); b="c">""",
|
||||
"""<a onmouseover="MM_swapImage('nav1','',"""\
|
||||
"""'/images/dwnavpoint_over.gif',1);movein(this);" b="c">"""),
|
||||
("""<a onmouseover=blubb('nav1','',"""\
|
||||
"""'/images/nav.gif',1);move(this); b="c">""",
|
||||
"""<a onmouseover="blubb('nav1','',"""\
|
||||
"""'/images/nav.gif',1);move(this);" b="c">"""),
|
||||
("""<a onClick=location.href('/index.htm') b="c">""",
|
||||
"""<a onclick="location.href('/index.htm')" b="c">"""),
|
||||
# entity resolving
|
||||
|
|
@ -140,6 +140,19 @@ parsetests = [
|
|||
# doctype XHTML
|
||||
("""<!DOCTYPe html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><MeTa a="b"/>""",
|
||||
"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><meta a="b"/>"""),
|
||||
# meta tag with charset encoding
|
||||
("""<meta http-equiv="content-type" content>""",
|
||||
"""<meta http-equiv="content-type" content>"""),
|
||||
("""<meta http-equiv="content-type" content=>""",
|
||||
"""<meta http-equiv="content-type" content="">"""),
|
||||
("""<meta http-equiv="content-type" content="hulla">""",
|
||||
"""<meta http-equiv="content-type" content="hulla">"""),
|
||||
("""<meta http-equiv="content-type" content="text/html; charset=iso8859-1">""",
|
||||
"""<meta http-equiv="content-type" content="text/html; charset=iso8859-1">"""),
|
||||
("""<meta http-equiv="content-type" content="text/html; charset=hulla">""",
|
||||
"""<meta http-equiv="content-type" content="text/html; charset=hulla">"""),
|
||||
# CDATA
|
||||
("""<![CDATA[<a>hallo</a>]]>""", """<![CDATA[<a>hallo</a>]]>"""),
|
||||
# missing > in end tag
|
||||
("""</td <td a="b" >""", """</td><td a="b">"""),
|
||||
("""</td<td a="b" >""", """</td><td a="b">"""),
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ class TestStrFormat (tests.StandardTest):
|
|||
self.assertEquals(u("'\"a'"), "\"a")
|
||||
self.assertEquals(u('"a\'"'), 'a\'')
|
||||
self.assertEquals(u('"\'a"'), '\'a')
|
||||
self.assertEquals(u("'a'", matching=True), "a")
|
||||
self.assertEquals(u('"a"', matching=True), "a")
|
||||
# even mis-matching quotes should be removed...
|
||||
self.assertEquals(u("'a\""), "a")
|
||||
self.assertEquals(u("\"a'"), "a")
|
||||
|
|
@ -56,18 +58,25 @@ class TestStrFormat (tests.StandardTest):
|
|||
"""
|
||||
Test line wrapping.
|
||||
"""
|
||||
wrap = linkcheck.strformat.wrap
|
||||
s = "11%(sep)s22%(sep)s33%(sep)s44%(sep)s55" % {'sep': os.linesep}
|
||||
# testing width <= 0
|
||||
self.assertEquals(linkcheck.strformat.wrap(s, -1), s)
|
||||
self.assertEquals(linkcheck.strformat.wrap(s, 0), s)
|
||||
self.assertEquals(wrap(s, -1), s)
|
||||
self.assertEquals(wrap(s, 0), s)
|
||||
l = len(os.linesep)
|
||||
gap = " "*l
|
||||
s2 = "11%(gap)s22%(sep)s33%(gap)s44%(sep)s55" % \
|
||||
{'sep': os.linesep, 'gap': gap}
|
||||
# splitting lines
|
||||
self.assertEquals(linkcheck.strformat.wrap(s2, 2), s)
|
||||
self.assertEquals(wrap(s2, 2), s)
|
||||
# combining lines
|
||||
self.assertEquals(linkcheck.strformat.wrap(s, 4+l), s2)
|
||||
self.assertEquals(wrap(s, 4+l), s2)
|
||||
# misc
|
||||
self.assertEquals(wrap(s, -1), s)
|
||||
self.assertEquals(wrap(s, 0), s)
|
||||
self.assertEquals(wrap(None, 10), None)
|
||||
self.assertFalse(linkcheck.strformat.get_paragraphs(None))
|
||||
|
||||
|
||||
def test_remove_markup (self):
|
||||
"""
|
||||
|
|
@ -88,6 +97,8 @@ class TestStrFormat (tests.StandardTest):
|
|||
self.assertEquals(linkcheck.strformat.strsize(2), "2 Bytes")
|
||||
self.assertEquals(linkcheck.strformat.strsize(1023), "1023 Bytes")
|
||||
self.assertEquals(linkcheck.strformat.strsize(1024), "1.00 kB")
|
||||
self.assertEquals(linkcheck.strformat.strsize(1024*1024), "1.00 MB")
|
||||
self.assertEquals(linkcheck.strformat.strsize(1024*1024*1024), "1.00 GB")
|
||||
|
||||
def test_is_ascii (self):
|
||||
self.assert_(linkcheck.strformat.is_ascii("abcd./"))
|
||||
|
|
@ -96,19 +107,54 @@ class TestStrFormat (tests.StandardTest):
|
|||
|
||||
def test_indent (self):
|
||||
s = "bla"
|
||||
self.assertEquals(linkcheck.strformat.indent(s, ""), s)
|
||||
self.assertEquals(linkcheck.strformat.indent(s, " "), " "+s)
|
||||
self.assertEqual(linkcheck.strformat.indent(s, ""), s)
|
||||
self.assertEqual(linkcheck.strformat.indent(s, " "), " "+s)
|
||||
|
||||
def test_stripall (self):
|
||||
self.assertEquals(linkcheck.strformat.stripall("a\tb"), "ab")
|
||||
self.assertEquals(linkcheck.strformat.stripall(" a\t b"), "ab")
|
||||
self.assertEquals(linkcheck.strformat.stripall(" \r\na\t \nb\r"), "ab")
|
||||
self.assertEqual(linkcheck.strformat.stripall("a\tb"), "ab")
|
||||
self.assertEqual(linkcheck.strformat.stripall(" a\t b"), "ab")
|
||||
self.assertEqual(linkcheck.strformat.stripall(" \r\na\t \nb\r"), "ab")
|
||||
self.assertEqual(linkcheck.strformat.stripall(None), None)
|
||||
|
||||
def test_limit (self):
|
||||
self.assertEquals(linkcheck.strformat.limit("", 0), "")
|
||||
self.assertEquals(linkcheck.strformat.limit("a", 0), "")
|
||||
self.assertEquals(linkcheck.strformat.limit("1", 1), "1")
|
||||
self.assertEquals(linkcheck.strformat.limit("11", 1), "1...")
|
||||
self.assertEqual(linkcheck.strformat.limit("", 0), "")
|
||||
self.assertEqual(linkcheck.strformat.limit("a", 0), "")
|
||||
self.assertEqual(linkcheck.strformat.limit("1", 1), "1")
|
||||
self.assertEqual(linkcheck.strformat.limit("11", 1), "1...")
|
||||
|
||||
def test_time (self):
|
||||
zone = linkcheck.strformat.strtimezone()
|
||||
t = linkcheck.strformat.strtime(0)
|
||||
self.assertEqual(t, "1970-01-01 01:00:00"+zone)
|
||||
|
||||
def test_duration (self):
|
||||
strduration = linkcheck.strformat.strduration
|
||||
self.assertEqual(strduration(0), "0.000 seconds")
|
||||
self.assertEqual(strduration(1), "1.000 seconds")
|
||||
self.assertEqual(strduration(120), "2.000 minutes")
|
||||
self.assertEqual(strduration(60*60), "1.000 hours")
|
||||
|
||||
def test_linenumber (self):
|
||||
get_line_number = linkcheck.strformat.get_line_number
|
||||
self.assertEqual(get_line_number("a", -5), 0)
|
||||
self.assertEqual(get_line_number("a", 0), 1)
|
||||
self.assertEqual(get_line_number("a\nb", 2), 2)
|
||||
|
||||
def test_encoding (self):
|
||||
is_encoding = linkcheck.strformat.is_encoding
|
||||
self.assert_(is_encoding('ascii'))
|
||||
self.assertFalse(is_encoding('hulla'))
|
||||
|
||||
def test_unicode_safe (self):
|
||||
unicode_safe = linkcheck.strformat.unicode_safe
|
||||
self.assertEqual(unicode_safe("a"), u"a")
|
||||
self.assertEqual(unicode_safe(u"a"), u"a")
|
||||
|
||||
def test_ascii_safe (self):
|
||||
ascii_safe = linkcheck.strformat.ascii_safe
|
||||
self.assertEqual(ascii_safe("a"), "a")
|
||||
self.assertEqual(ascii_safe(u"a"), "a")
|
||||
self.assertEqual(ascii_safe(u"ä"), "")
|
||||
|
||||
|
||||
def test_suite ():
|
||||
|
|
|
|||
Loading…
Reference in a new issue