comparison test/test_templating.py @ 4009:e335ce40d6c8

Make URL matching code less matchy
author Richard Jones <richard@users.sourceforge.net>
date Mon, 01 Sep 2008 01:37:00 +0000
parents 13161539e5bd
children 797eacd945af
comparison
equal deleted inserted replaced
4008:0bf9f8ae7d1b 4009:e335ce40d6c8
89 cls["nosy"] 89 cls["nosy"]
90 90
91 def test_url_match(self): 91 def test_url_match(self):
92 '''Test the URL regular expression in StringHTMLProperty. 92 '''Test the URL regular expression in StringHTMLProperty.
93 ''' 93 '''
94 def t(s, **groups): 94 def t(s, nothing=False, **groups):
95 m = StringHTMLProperty.hyper_re.search(s) 95 m = StringHTMLProperty.hyper_re.search(s)
96 self.assertNotEquals(m, None, '%r did not match'%s) 96 if nothing:
97 self.assertEquals(m, None, '%r matched'%s)
98 return
99 else:
100 self.assertNotEquals(m, None, '%r did not match'%s)
97 d = m.groupdict() 101 d = m.groupdict()
98 for g in groups: 102 for g in groups:
99 self.assertEquals(d[g], groups[g], '%s %r != %r in %r'%(g, d[g], 103 self.assertEquals(d[g], groups[g], '%s %r != %r in %r'%(g, d[g],
100 groups[g], s)) 104 groups[g], s))
101 105
102 #t('123.321.123.321', 'url') 106 #t('123.321.123.321', 'url')
103 t('http://roundup.net/', url='http://roundup.net/') 107 t('http://roundup.net/', url='http://roundup.net/')
104 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/') 108 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/')
105 t('www.a.ex', url='www.a.ex') 109 t('www.a.ex', url='www.a.ex')
110 t('foo.a.ex', nothing=True)
111 t('StDevValidTimeSeries.GetObservation', nothing=True)
106 t('http://a.ex', url='http://a.ex') 112 t('http://a.ex', url='http://a.ex')
107 t('http://a.ex/?foo&bar=baz\\.@!$%()qwerty', 113 t('http://a.ex/?foo&bar=baz\\.@!$%()qwerty',
108 url='http://a.ex/?foo&bar=baz\\.@!$%()qwerty') 114 url='http://a.ex/?foo&bar=baz\\.@!$%()qwerty')
109 t('www.net', url='www.net') 115 t('www.foo.net', url='www.foo.net')
110 t('richard@com.example', email='richard@com.example') 116 t('richard@com.example', email='richard@com.example')
111 t('r@a.com', email='r@a.com') 117 t('r@a.com', email='r@a.com')
112 t('i1', **{'class':'i', 'id':'1'}) 118 t('i1', **{'class':'i', 'id':'1'})
113 t('item123', **{'class':'item', 'id':'123'}) 119 t('item123', **{'class':'item', 'id':'123'})
114 120

Roundup Issue Tracker: http://roundup-tracker.org/