#NEWLINE# @ pytest . mark . parametrize ( [ 'stored_time' , 'newver' , 'check' , 'warn' ] , [ ( '1970-01-01T10:00:00Z' , '2.0' , True , True ) , ( '1970-01-01T10:00:00Z' , '1.0' , True , False ) , ( '1970-01-06T10:00:00Z' , '1.0' , False , False ) , ( '1970-01-06T10:00:00Z' , '2.0' , False , True ) ] ) #NEWLINE# def test_pip_version_check( monkeypatch , stored_time , newver , check , warn ) : #NEWLINE# #INDENT# monkeypatch . setattr ( outdated , 'get_installed_version' , ( lambda name : '1.0' ) ) #NEWLINE# resp = pretend . stub ( raise_for_status = pretend . call_recorder ( ( lambda : None ) ) , json = pretend . call_recorder ( ( lambda : { #NEWLINE# #INDENT# 'releases' : { #NEWLINE# #INDENT# newver : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) ) ) #NEWLINE# session = pretend . stub ( get = pretend . call_recorder ( ( lambda u , headers = None : resp ) ) ) #NEWLINE# fake_state = pretend . stub ( state = { #NEWLINE# #INDENT# 'last_check' : stored_time , #NEWLINE# 'pypi_version' : '1.0' , #NEWLINE# #UNINDENT# } , save = pretend . call_recorder ( ( lambda v , t : None ) ) ) #NEWLINE# monkeypatch . setattr ( outdated , 'load_selfcheck_statefile' , ( lambda : fake_state ) ) #NEWLINE# monkeypatch . setattr ( outdated . logger , 'warning' , pretend . call_recorder ( ( lambda * a , **kw : None ) ) ) #NEWLINE# monkeypatch . setattr ( outdated . logger , 'debug' , pretend . call_recorder ( ( lambda s , exc_info = None : None ) ) ) #NEWLINE# with freezegun . freeze_time ( '1970-01-09 10:00:00' , ignore = [ 'six.moves' , 'pip._vendor.six.moves' , 'pip._vendor.requests.packages.urllib3.packages.six.moves' ] ) : #NEWLINE# #INDENT# outdated . pip_version_check ( session ) #NEWLINE# #UNINDENT# assert ( not outdated . logger . debug . calls ) #NEWLINE# if check : #NEWLINE# #INDENT# assert ( session . get . calls == [ pretend . call ( 'https://pypi.python.org/pypi/pip/json' , headers = { #NEWLINE# #INDENT# 'Accept' : 'application/json' , #NEWLINE# #UNINDENT# } ) ] ) #NEWLINE# assert ( fake_state . save . calls == [ pretend . call ( check , datetime . datetime ( 1970 , 1 , 9 , 10 , 0 , 0 ) ) ] ) #NEWLINE# if warn : #NEWLINE# #INDENT# assert ( len ( outdated . logger . warning . calls ) == 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( len ( outdated . logger . warning . calls ) == 0 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# assert ( session . get . calls == [ ] ) #NEWLINE# assert ( fake_state . save . calls == [ ] )