22
22
23
23
24
24
class TWPTests (unittest .TestCase ):
25
+
25
26
def setUp (self ):
26
27
self .parser = ttp .Parser ()
27
28
28
-
29
29
# General Tests ------------------------------------------------------------
30
30
# --------------------------------------------------------------------------
31
31
def test_urls (self ):
@@ -45,7 +45,6 @@ def test_all_not_break_url_at(self):
45
45
self .assertEqual (result .html , u'<a href="http://www.flickr.com/photos/29674651@N00/4382024406">http://www.flickr.com/photo...</a>' )
46
46
self .assertEqual (result .urls , [u'http://www.flickr.com/photos/29674651@N00/4382024406' ])
47
47
48
-
49
48
# URL tests ----------------------------------------------------------------
50
49
# --------------------------------------------------------------------------
51
50
def test_url_mid (self ):
@@ -90,7 +89,8 @@ def test_url_dash(self):
90
89
91
90
def test_url_multiple (self ):
92
91
result = self .parser .parse (u'http://example.com https://sslexample.com http://sub.example.com' )
93
- self .assertEqual (result .html , u'<a href="http://example.com">http://example.com</a> <a href="https://sslexample.com">https://sslexample.com</a> <a href="http://sub.example.com">http://sub.example.com</a>' )
92
+ self .assertEqual (
93
+ result .html , u'<a href="http://example.com">http://example.com</a> <a href="https://sslexample.com">https://sslexample.com</a> <a href="http://sub.example.com">http://sub.example.com</a>' )
94
94
self .assertEqual (result .urls , [u'http://example.com' , u'https://sslexample.com' , u'http://sub.example.com' ])
95
95
96
96
def test_url_raw_domain (self ):
@@ -162,7 +162,6 @@ def test_url_long_hypens(self):
162
162
self .assertEqual (result .html , u'text <a href="http://word-and-a-number-8-ftw.domain.tld/">http://word-and-a-number-8-...</a>' )
163
163
self .assertEqual (result .urls , [u'http://word-and-a-number-8-ftw.domain.tld/' ])
164
164
165
-
166
165
# URL not tests ------------------------------------------------------------
167
166
def test_not_url_dotdotdot (self ):
168
167
result = self .parser .parse (u'Is www...foo a valid URL?' )
@@ -194,7 +193,6 @@ def test_not_url_one_letter_iana(self):
194
193
self .assertEqual (result .html , u'text http://a.com/ http://a.net/ http://a.org/' )
195
194
self .assertEqual (result .urls , [])
196
195
197
-
198
196
# URL followed Tests -------------------------------------------------------
199
197
def test_url_followed_question (self ):
200
198
result = self .parser .parse (u'text http://example.com?' )
@@ -271,7 +269,6 @@ def test_url_followed_hypen(self):
271
269
self .assertEqual (result .html , u'text <a href="http://domain.tld">http://domain.tld</a>-that-you-should-have-put-a-space-after' )
272
270
self .assertEqual (result .urls , [u'http://domain.tld' ])
273
271
274
-
275
272
# URL preceeded Tests -------------------------------------------------------
276
273
def test_url_preceeded_colon (self ):
277
274
result = self .parser .parse (u'text:http://example.com' )
@@ -294,7 +291,6 @@ def test_not_url_preceeded_exclamation(self):
294
291
self .assertEqual (result .html , u'text !http://example.com' )
295
292
self .assertEqual (result .urls , [])
296
293
297
-
298
294
# URL numeric tests --------------------------------------------------------
299
295
def test_url_at_numeric (self ):
300
296
result = self .parser .parse (u'http://www.flickr.com/photos/29674651@N00/4382024406' )
@@ -306,7 +302,6 @@ def test_url_at_non_numeric(self):
306
302
self .assertEqual (result .html , u'<a href="http://www.flickr.com/photos/29674651@N00/foobar">http://www.flickr.com/photo...</a>' )
307
303
self .assertEqual (result .urls , [u'http://www.flickr.com/photos/29674651@N00/foobar' ])
308
304
309
-
310
305
# URL domain tests ---------------------------------------------------------
311
306
def test_url_WWW (self ):
312
307
result = self .parser .parse (u'WWW.EXAMPLE.COM' )
@@ -320,7 +315,8 @@ def test_url_www(self):
320
315
321
316
def test_url_only_domain_query_followed_period (self ):
322
317
result = self .parser .parse (u'I think it\' s proper to end sentences with a period http://tell.me/why?=because.i.want.it. Even when they contain a URL.' )
323
- self .assertEqual (result .html , u'I think it\' s proper to end sentences with a period <a href="http://tell.me/why?=because.i.want.it">http://tell.me/why?=because...</a>. Even when they contain a URL.' )
318
+ self .assertEqual (
319
+ result .html , u'I think it\' s proper to end sentences with a period <a href="http://tell.me/why?=because.i.want.it">http://tell.me/why?=because...</a>. Even when they contain a URL.' )
324
320
self .assertEqual (result .urls , [u'http://tell.me/why?=because.i.want.it' ])
325
321
326
322
def test_url_only_domain_followed_period (self ):
@@ -354,7 +350,6 @@ def test_not_url_under_domain(self):
354
350
self .assertEqual (result .html , u'badly formatted http://foo_bar.com' )
355
351
self .assertEqual (result .urls , [])
356
352
357
-
358
353
# Hashtag tests ------------------------------------------------------------
359
354
# --------------------------------------------------------------------------
360
355
def test_hashtag_followed_full_whitespace (self ):
@@ -432,7 +427,6 @@ def test_hashtag_under(self):
432
427
self .assertEqual (result .html , u'text <a href="http://search.twitter.com/search?q=%23hash_tag">#hash_tag</a>' )
433
428
self .assertEqual (result .tags , [u'hash_tag' ])
434
429
435
-
436
430
# Username tests -----------------------------------------------------------
437
431
# --------------------------------------------------------------------------
438
432
def test_not_username_preceded_letter (self ):
@@ -515,7 +509,6 @@ def test_username_non_reply(self):
515
509
self .assertEqual (result .users , [u'username' ])
516
510
self .assertEqual (result .reply , None )
517
511
518
-
519
512
# List tests ---------------------------------------------------------------
520
513
# --------------------------------------------------------------------------
521
514
def test_list_preceeded (self ):
@@ -561,7 +554,8 @@ def test_list_not_preceeded_letter(self):
561
554
562
555
def test_list_long_truncate (self ):
563
556
result = self .parser .parse (u'@username/list5678901234567890123456789012345678901234567890123456789012345678901234567890A' )
564
- self .assertEqual (result .html , u'<a href="http://twitter.com/username/list5678901234567890123456789012345678901234567890123456789012345678901234567890">@username/list5678901234567890123456789012345678901234567890123456789012345678901234567890</a>A' )
557
+ self .assertEqual (
558
+ result .html , u'<a href="http://twitter.com/username/list5678901234567890123456789012345678901234567890123456789012345678901234567890">@username/list5678901234567890123456789012345678901234567890123456789012345678901234567890</a>A' )
565
559
self .assertEqual (result .lists , [(u'username' , u'list5678901234567890123456789012345678901234567890123456789012345678901234567890' )])
566
560
567
561
def test_list_with_dash (self ):
@@ -571,9 +565,10 @@ def test_list_with_dash(self):
571
565
572
566
573
567
class TWPTestsWithSpans (unittest .TestCase ):
568
+
574
569
"""Test ttp with re spans to extract character co-ords of matches"""
575
570
def setUp (self ):
576
- self .parser = ttp .Parser (include_spans = True )
571
+ self .parser = ttp .Parser (include_spans = True )
577
572
578
573
def test_spans_in_tweets (self ):
579
574
"""Test some coca-cola tweets taken from twitter with spans"""
@@ -606,15 +601,14 @@ def test_edge_cases(self):
606
601
self .assertEqual (result .urls , [(u'http://some.com' , (1 , 16 ))])
607
602
608
603
609
-
610
604
# Test it!
611
605
if __name__ == '__main__' :
612
606
unittest .main ()
613
607
614
- #verbosity = 0 # set to 2 for verbose output
615
- #suite = unittest.TestLoader().loadTestsFromTestCase(TWPTestsWithSpansEdgeCases)
616
- #unittest.TextTestRunner(verbosity=verbosity).run(suite)
617
- #suite = unittest.TestLoader().loadTestsFromTestCase(TWPTestsWithSpans)
618
- #unittest.TextTestRunner(verbosity=verbosity).run(suite)
619
- #suite = unittest.TestLoader().loadTestsFromTestCase(TWPTests)
620
- #unittest.TextTestRunner(verbosity=verbosity).run(suite)
608
+ # verbosity = 0 # set to 2 for verbose output
609
+ # suite = unittest.TestLoader().loadTestsFromTestCase(TWPTestsWithSpansEdgeCases)
610
+ # unittest.TextTestRunner(verbosity=verbosity).run(suite)
611
+ # suite = unittest.TestLoader().loadTestsFromTestCase(TWPTestsWithSpans)
612
+ # unittest.TextTestRunner(verbosity=verbosity).run(suite)
613
+ # suite = unittest.TestLoader().loadTestsFromTestCase(TWPTests)
614
+ # unittest.TextTestRunner(verbosity=verbosity).run(suite)
0 commit comments