Mercurial > p > roundup > code
comparison test/test_templating.py @ 4010:797eacd945af
add tests for and fix alex's examples
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 01 Sep 2008 01:45:33 +0000 |
| parents | e335ce40d6c8 |
| children | e77bcbdc9b32 |
comparison
equal
deleted
inserted
replaced
| 4009:e335ce40d6c8 | 4010:797eacd945af |
|---|---|
| 92 '''Test the URL regular expression in StringHTMLProperty. | 92 '''Test the URL regular expression in StringHTMLProperty. |
| 93 ''' | 93 ''' |
| 94 def t(s, nothing=False, **groups): | 94 def t(s, nothing=False, **groups): |
| 95 m = StringHTMLProperty.hyper_re.search(s) | 95 m = StringHTMLProperty.hyper_re.search(s) |
| 96 if nothing: | 96 if nothing: |
| 97 self.assertEquals(m, None, '%r matched'%s) | 97 if m: |
| 98 self.assertEquals(m, None, '%r matched (%r)'%(s, m.groupdict())) | |
| 98 return | 99 return |
| 99 else: | 100 else: |
| 100 self.assertNotEquals(m, None, '%r did not match'%s) | 101 self.assertNotEquals(m, None, '%r did not match'%s) |
| 101 d = m.groupdict() | 102 d = m.groupdict() |
| 102 for g in groups: | 103 for g in groups: |
| 103 self.assertEquals(d[g], groups[g], '%s %r != %r in %r'%(g, d[g], | 104 self.assertEquals(d[g], groups[g], '%s %r != %r in %r'%(g, d[g], |
| 104 groups[g], s)) | 105 groups[g], s)) |
| 105 | 106 |
| 106 #t('123.321.123.321', 'url') | 107 #t('123.321.123.321', 'url') |
| 108 t('http://localhost/', url='http://localhost/') | |
| 107 t('http://roundup.net/', url='http://roundup.net/') | 109 t('http://roundup.net/', url='http://roundup.net/') |
| 110 t('http://richard@localhost/', url='http://richard@localhost/') | |
| 111 t('http://richard:sekrit@localhost/', | |
| 112 url='http://richard:sekrit@localhost/') | |
| 108 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/') | 113 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/') |
| 109 t('www.a.ex', url='www.a.ex') | 114 t('www.a.ex', url='www.a.ex') |
| 110 t('foo.a.ex', nothing=True) | 115 t('foo.a.ex', nothing=True) |
| 111 t('StDevValidTimeSeries.GetObservation', nothing=True) | 116 t('StDevValidTimeSeries.GetObservation', nothing=True) |
| 112 t('http://a.ex', url='http://a.ex') | 117 t('http://a.ex', url='http://a.ex') |
| 115 t('www.foo.net', url='www.foo.net') | 120 t('www.foo.net', url='www.foo.net') |
| 116 t('richard@com.example', email='richard@com.example') | 121 t('richard@com.example', email='richard@com.example') |
| 117 t('r@a.com', email='r@a.com') | 122 t('r@a.com', email='r@a.com') |
| 118 t('i1', **{'class':'i', 'id':'1'}) | 123 t('i1', **{'class':'i', 'id':'1'}) |
| 119 t('item123', **{'class':'item', 'id':'123'}) | 124 t('item123', **{'class':'item', 'id':'123'}) |
| 125 t('www.user:pass@host.net', email='pass@host.net') | |
| 126 t('user:pass@www.host.net', url='user:pass@www.host.net') | |
| 120 | 127 |
| 121 def test_url_replace(self): | 128 def test_url_replace(self): |
| 122 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '') | 129 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '') |
| 123 def t(s): return p.hyper_re.sub(p._hyper_repl, s) | 130 def t(s): return p.hyper_re.sub(p._hyper_repl, s) |
| 124 ae = self.assertEquals | 131 ae = self.assertEquals |
