88import warnings
99
1010import responses
11+
12+ from hypothesis import given , example
13+ from hypothesis import strategies as st
14+
1115import twitter
1216
1317warnings .filterwarnings ('ignore' , category = DeprecationWarning )
@@ -41,19 +45,22 @@ def tearDown(self):
4145 sys .stderr = self ._stderr
4246 pass
4347
44- def test_trend_repr1 (self ):
48+ @given (text = st .text ())
49+ @example (text = "#نفسك_تبيع_ايه_للسعوديه" )
50+ def test_trend_repr1 (self , text ):
4551 trend = twitter .Trend (
46- name = "#نفسك_تبيع_ايه_للسعوديه" ,
52+ name = text ,
4753 url = "http://twitter.com/search?q=%23ChangeAConsonantSpoilAMovie" ,
4854 timestamp = 'whatever' )
4955 try :
5056 trend .__repr__ ()
5157 except Exception as e :
5258 self .fail (e )
5359
54- def test_trend_repr2 (self ):
60+ @given (text = st .text ())
61+ @example (text = "#N\u00e3 oD\u00ea UnfTagueirosSdv" )
62+ def test_trend_repr2 (self , text ):
5563 trend = twitter .Trend (
56- name = "#N\u00e3 oD\u00ea UnfTagueirosSdv" ,
5764 url = 'http://twitter.com/search?q=%23ChangeAConsonantSpoilAMovie' ,
5865 timestamp = 'whatever' )
5966
@@ -72,23 +79,25 @@ def test_trend_repr3(self):
7279
7380 resp = self .api .GetTrendsCurrent ()
7481 for r in resp :
75- print (r .__str__ ())
7682 try :
7783 r .__repr__ ()
7884 except Exception as e :
7985 self .fail (e )
8086
87+ @given (text = st .text ())
8188 @responses .activate
82- def test_unicode_get_search (self ):
89+ def test_unicode_get_search (self , text ):
8390 responses .add (responses .GET , DEFAULT_URL , body = b'{}' , status = 200 )
8491 try :
85- self .api .GetSearch (term = "#ابشري_قابوس_جاء" )
92+ self .api .GetSearch (term = text )
8693 except Exception as e :
8794 self .fail (e )
8895
89- def test_constructed_status (self ):
96+ @given (text = st .text ())
97+ @example (text = '可以倒着飞的飞机' )
98+ def test_constructed_status (self , text ):
9099 s = twitter .Status ()
91- s .text = "可以倒着飞的飞机"
100+ s .text = text
92101 s .created_at = "016-02-13T23:00:00"
93102 s .screen_name = "himawari8bot"
94103 s .id = 1
@@ -101,8 +110,3 @@ def test_post_with_bytes_string(self):
101110 status = 'x'
102111 length = twitter .twitter_utils .calc_expected_status_length (status )
103112 assert length == 1
104-
105-
106- if __name__ == "__main__" :
107- suite = unittest .TestLoader ().loadTestsFromTestCase (ApiTest )
108- unittest .TextTestRunner (verbosity = 2 ).run (suite )
0 commit comments