@@ -1810,27 +1810,30 @@ def test_handle_weakref(self):
1810
1810
wd ['h' ] = h # Would fail without __weakref__ slot.
1811
1811
1812
1812
def test_handle_repr (self ):
1813
+ self .loop .get_debug .return_value = False
1814
+
1813
1815
# simple function
1814
- h = asyncio .Handle (noop , (), self .loop )
1815
- src = test_utils .get_function_source (noop )
1816
+ h = asyncio .Handle (noop , (1 , 2 ), self .loop )
1817
+ filename , lineno = test_utils .get_function_source (noop )
1816
1818
self .assertEqual (repr (h ),
1817
- '<Handle noop() at %s:%s>' % src )
1819
+ '<Handle noop(1, 2) at %s:%s>'
1820
+ % (filename , lineno ))
1818
1821
1819
1822
# cancelled handle
1820
1823
h .cancel ()
1821
1824
self .assertEqual (repr (h ),
1822
- '<Handle cancelled noop() at %s:%s>' % src )
1825
+ '<Handle cancelled>' )
1823
1826
1824
1827
# decorated function
1825
1828
cb = asyncio .coroutine (noop )
1826
1829
h = asyncio .Handle (cb , (), self .loop )
1827
1830
self .assertEqual (repr (h ),
1828
- '<Handle noop() at %s:%s>' % src )
1831
+ '<Handle noop() at %s:%s>'
1832
+ % (filename , lineno ))
1829
1833
1830
1834
# partial function
1831
1835
cb = functools .partial (noop , 1 , 2 )
1832
1836
h = asyncio .Handle (cb , (3 ,), self .loop )
1833
- filename , lineno = src
1834
1837
regex = (r'^<Handle noop\(1, 2\)\(3\) at %s:%s>$'
1835
1838
% (re .escape (filename ), lineno ))
1836
1839
self .assertRegex (repr (h ), regex )
@@ -1839,16 +1842,33 @@ def test_handle_repr(self):
1839
1842
if sys .version_info >= (3 , 4 ):
1840
1843
method = HandleTests .test_handle_repr
1841
1844
cb = functools .partialmethod (method )
1842
- src = test_utils .get_function_source (method )
1845
+ filename , lineno = test_utils .get_function_source (method )
1843
1846
h = asyncio .Handle (cb , (), self .loop )
1844
1847
1845
- filename , lineno = src
1846
1848
cb_regex = r'<function HandleTests.test_handle_repr .*>'
1847
1849
cb_regex = (r'functools.partialmethod\(%s, , \)\(\)' % cb_regex )
1848
1850
regex = (r'^<Handle %s at %s:%s>$'
1849
1851
% (cb_regex , re .escape (filename ), lineno ))
1850
1852
self .assertRegex (repr (h ), regex )
1851
1853
1854
+ def test_handle_repr_debug (self ):
1855
+ self .loop .get_debug .return_value = True
1856
+
1857
+ # simple function
1858
+ create_filename = __file__
1859
+ create_lineno = sys ._getframe ().f_lineno + 1
1860
+ h = asyncio .Handle (noop , (1 , 2 ), self .loop )
1861
+ filename , lineno = test_utils .get_function_source (noop )
1862
+ self .assertEqual (repr (h ),
1863
+ '<Handle noop(1, 2) at %s:%s created at %s:%s>'
1864
+ % (filename , lineno , create_filename , create_lineno ))
1865
+
1866
+ # cancelled handle
1867
+ h .cancel ()
1868
+ self .assertEqual (repr (h ),
1869
+ '<Handle cancelled created at %s:%s>'
1870
+ % (create_filename , create_lineno ))
1871
+
1852
1872
def test_handle_source_traceback (self ):
1853
1873
loop = asyncio .get_event_loop_policy ().new_event_loop ()
1854
1874
loop .set_debug (True )
@@ -1894,7 +1914,7 @@ def test_timer(self):
1894
1914
def callback (* args ):
1895
1915
return args
1896
1916
1897
- args = ()
1917
+ args = (1 , 2 , 3 )
1898
1918
when = time .monotonic ()
1899
1919
h = asyncio .TimerHandle (when , callback , args , mock .Mock ())
1900
1920
self .assertIs (h ._callback , callback )
@@ -1904,14 +1924,17 @@ def callback(*args):
1904
1924
# cancel
1905
1925
h .cancel ()
1906
1926
self .assertTrue (h ._cancelled )
1907
-
1927
+ self .assertIsNone (h ._callback )
1928
+ self .assertIsNone (h ._args )
1908
1929
1909
1930
# when cannot be None
1910
1931
self .assertRaises (AssertionError ,
1911
1932
asyncio .TimerHandle , None , callback , args ,
1912
1933
self .loop )
1913
1934
1914
1935
def test_timer_repr (self ):
1936
+ self .loop .get_debug .return_value = False
1937
+
1915
1938
# simple function
1916
1939
h = asyncio .TimerHandle (123 , noop , (), self .loop )
1917
1940
src = test_utils .get_function_source (noop )
@@ -1921,8 +1944,27 @@ def test_timer_repr(self):
1921
1944
# cancelled handle
1922
1945
h .cancel ()
1923
1946
self .assertEqual (repr (h ),
1924
- '<TimerHandle cancelled when=123 noop() at %s:%s>'
1925
- % src )
1947
+ '<TimerHandle cancelled when=123>' )
1948
+
1949
+ def test_timer_repr_debug (self ):
1950
+ self .loop .get_debug .return_value = True
1951
+
1952
+ # simple function
1953
+ create_filename = __file__
1954
+ create_lineno = sys ._getframe ().f_lineno + 1
1955
+ h = asyncio .TimerHandle (123 , noop , (), self .loop )
1956
+ filename , lineno = test_utils .get_function_source (noop )
1957
+ self .assertEqual (repr (h ),
1958
+ '<TimerHandle when=123 noop() '
1959
+ 'at %s:%s created at %s:%s>'
1960
+ % (filename , lineno , create_filename , create_lineno ))
1961
+
1962
+ # cancelled handle
1963
+ h .cancel ()
1964
+ self .assertEqual (repr (h ),
1965
+ '<TimerHandle cancelled when=123 created at %s:%s>'
1966
+ % (create_filename , create_lineno ))
1967
+
1926
1968
1927
1969
def test_timer_comparison (self ):
1928
1970
def callback (* args ):
0 commit comments