コード例 #1
0
 def test_get_link_returns_correct_link_when_matches(self):
     for arg, exp in [(('smoke', 'http://tobacco.com', 'Lung_cancer'),
                       ('http://tobacco.com', 'Lung cancer')),
                      (('tag', 'ftp://foo:809/bar.zap', 'Foo_in a Bar'),
                       ('ftp://foo:809/bar.zap', 'Foo in a Bar'))]:
         link = TagStatLink(*arg)
         assert_equals(exp, link.get_link(arg[0]))
コード例 #2
0
 def test_get_link_returns_correct_link_when_matches(self):
     for arg, exp in [(('smoke', 'http://tobacco.com', 'Lung_cancer'),
                       ('http://tobacco.com', 'Lung cancer')),
                      (('tag', 'ftp://foo:809/bar.zap', 'Foo_in a Bar'),
                       ('ftp://foo:809/bar.zap', 'Foo in a Bar'))]:
         link = TagStatLink(*arg)
         assert_equal(exp, link.get_link(arg[0]))
コード例 #3
0
 def test_valid_string_containing_patterns_is_parsed_correctly(self):
     for arg, exp_pattern in [('*', '^(.*)$'), ('f*r', '^f(.*)r$'),
                              ('*a*', '^(.*)a(.*)$'), ('?', '^(.)$'),
                              ('??', '^(..)$'), ('f???ar', '^f(...)ar$'),
                              ('F*B?R*?', '^F(.*)B(.)R(.*)(.)$')]:
         link = TagStatLink(arg, 'some_url', 'some_title')
         assert_equals(exp_pattern, link._regexp.pattern)
コード例 #4
0
 def test_valid_string_is_parsed_correctly(self):
     for arg, exp in [(('Tag', 'bar/foo.html', 'foobar'),
                       ('^Tag$', 'bar/foo.html', 'foobar')),
                      (('hello', 'gopher://hello.world:8090/hello.html',
                        'Hello World'),
                       ('^hello$', 'gopher://hello.world:8090/hello.html',
                        'Hello World'))]:
         link = TagStatLink(*arg)
         assert_equals(exp[0], link._regexp.pattern)
         assert_equals(exp[1], link._link)
         assert_equals(exp[2], link._title)
コード例 #5
0
 def test_pattern_matches_case_insensitively(self):
     exp = 'http://tobacco.com', 'Lung cancer'
     link = TagStatLink('smoke', *exp)
     for tag in ['Smoke', 'SMOKE', 'smoke']:
         assert_equal(exp, link.get_link(tag))
コード例 #6
0
 def test_get_link_returns_none_when_no_match(self):
     link = TagStatLink('smoke', 'http://tobacco.com', 'Lung cancer')
     for tag in ['foo', 'b a r', 's moke']:
         assert_none(link.get_link(tag))
コード例 #7
0
 def test_matches_are_ignored_in_pattern_substitution(self):
     link = TagStatLink('???-*-*-?', '%4-%2-%2-%4', 'Tracker')
     assert_equals(link.get_link('AAA-XXX-ABC-B'),
                   ('B-XXX-XXX-B', 'Tracker'))
コード例 #8
0
 def test_pattern_substitution_with_multiple_substitutions(self):
     link = TagStatLink('??-?-*', '%3-%3-%1-%2-%3', 'Tracker')
     assert_equal(link.get_link('aa-b-XXX'), ('XXX-XXX-aa-b-XXX', 'Tracker'))
コード例 #9
0
 def test_pattern_substitution_with_one_match(self):
     link = TagStatLink('tag-*', 'http://tracker/?id=%1', 'Tracker')
     for id in ['1', '23', '456']:
         exp = ('http://tracker/?id=%s' % id, 'Tracker')
         assert_equal(exp, link.get_link('tag-%s' % id))
コード例 #10
0
 def test_pattern_match(self):
     link = TagStatLink('f?o*r', 'http://foo/bar.html', 'FooBar')
     for tag in ['foobar', 'foor', 'f_ofoobarfoobar', 'fOoBAr']:
         assert_equals(link.get_link(tag),
                       ('http://foo/bar.html', 'FooBar'))
コード例 #11
0
 def test_pattern_matches_when_spaces(self):
     exp = 'http://tobacco.com', 'Lung cancer'
     link = TagStatLink('smoking kills', *exp)
     for tag in ['Smoking Kills', 'SMOKING KILLS']:
         assert_equals(exp, link.get_link(tag))
コード例 #12
0
 def test_pattern_matches_case_insensitively(self):
     exp = 'http://tobacco.com', 'Lung cancer'
     link = TagStatLink('smoke', *exp)
     for tag in ['Smoke', 'SMOKE', 'smoke']:
         assert_equals(exp, link.get_link(tag))
コード例 #13
0
 def test_get_link_returns_none_when_no_match(self):
     link = TagStatLink('smoke', 'http://tobacco.com', 'Lung cancer')
     for tag in ['foo', 'b a r', 's moke']:
         assert_none(link.get_link(tag))
コード例 #14
0
 def test_underscores_in_title_are_converted_to_spaces(self):
     link = TagStatLink('', '', 'my_name')
     assert_equals(link._title, 'my name')
コード例 #15
0
 def test_pattern_matches_when_spaces(self):
     exp = 'http://tobacco.com', 'Lung cancer'
     link = TagStatLink('smoking kills', *exp)
     for tag in ['Smoking Kills', 'SMOKING KILLS']:
         assert_equal(exp, link.get_link(tag))
コード例 #16
0
 def test_pattern_match(self):
     link = TagStatLink('f?o*r', 'http://foo/bar.html', 'FooBar')
     for tag in ['foobar', 'foor', 'f_ofoobarfoobar', 'fOoBAr']:
         assert_equal(link.get_link(tag), ('http://foo/bar.html', 'FooBar'))
コード例 #17
0
 def test_pattern_substitution_with_one_match(self):
     link = TagStatLink('tag-*', 'http://tracker/?id=%1', 'Tracker')
     for id in ['1', '23', '456']:
         exp = ('http://tracker/?id=%s' % id, 'Tracker')
         assert_equals(exp, link.get_link('tag-%s' % id))
コード例 #18
0
 def test_pattern_substitution_with_multiple_matches(self):
     link = TagStatLink('?-*', 'http://tracker/?id=%1-%2', 'Tracker')
     for id1, id2 in [('1', '2'), ('3', '45'), ('f', 'bar')]:
         exp = ('http://tracker/?id=%s-%s' % (id1, id2), 'Tracker')
         assert_equal(exp, link.get_link('%s-%s' % (id1, id2)))
コード例 #19
0
 def test_pattern_substitution_with_multiple_matches(self):
     link = TagStatLink('?-*', 'http://tracker/?id=%1-%2', 'Tracker')
     for id1, id2 in [('1', '2'), ('3', '45'), ('f', 'bar')]:
         exp = ('http://tracker/?id=%s-%s' % (id1, id2), 'Tracker')
         assert_equals(exp, link.get_link('%s-%s' % (id1, id2)))
コード例 #20
0
 def test_matches_are_ignored_in_pattern_substitution(self):
     link = TagStatLink('???-*-*-?', '%4-%2-%2-%4', 'Tracker')
     assert_equal(link.get_link('AAA-XXX-ABC-B'), ('B-XXX-XXX-B', 'Tracker'))
コード例 #21
0
 def test_pattern_substitution_with_multiple_substitutions(self):
     link = TagStatLink('??-?-*', '%3-%3-%1-%2-%3', 'Tracker')
     assert_equals(link.get_link('aa-b-XXX'),
                   ('XXX-XXX-aa-b-XXX', 'Tracker'))