#NEWLINE# def test_global_state( monkeypatch ) : #NEWLINE# #INDENT# CONTENT = '{"pip_prefix": {"last_check": "1970-01-02T11:00:00Z",\n        "pypi_version": "1.0"}}' #NEWLINE# fake_file = pretend . stub ( read = pretend . call_recorder ( ( lambda : CONTENT ) ) , write = pretend . call_recorder ( ( lambda s : None ) ) ) #NEWLINE# @ pretend . call_recorder #NEWLINE# @ contextmanager #NEWLINE# def fake_open( filename , mode = 'r' ) : #NEWLINE# #INDENT# ( yield fake_file ) #NEWLINE# #UNINDENT# monkeypatch . setattr ( outdated , 'open' , fake_open , raising = False ) #NEWLINE# @ pretend . call_recorder #NEWLINE# @ contextmanager #NEWLINE# def fake_lock( filename ) : #NEWLINE# #INDENT# ( yield ) #NEWLINE# #UNINDENT# monkeypatch . setattr ( outdated , 'check_path_owner' , ( lambda p : True ) ) #NEWLINE# monkeypatch . setattr ( lockfile , 'LockFile' , fake_lock ) #NEWLINE# monkeypatch . setattr ( os . path , 'exists' , ( lambda p : True ) ) #NEWLINE# monkeypatch . setattr ( outdated , 'running_under_virtualenv' , pretend . call_recorder ( ( lambda : False ) ) ) #NEWLINE# monkeypatch . setattr ( outdated , 'USER_CACHE_DIR' , 'cache_dir' ) #NEWLINE# monkeypatch . setattr ( sys , 'prefix' , 'pip_prefix' ) #NEWLINE# state = outdated . load_selfcheck_statefile ( ) #NEWLINE# state . save ( '2.0' , datetime . datetime . utcnow ( ) ) #NEWLINE# assert ( len ( outdated . running_under_virtualenv . calls ) == 1 ) #NEWLINE# expected_path = os . path . join ( 'cache_dir' , 'selfcheck.json' ) #NEWLINE# assert ( CONTENT . calls == [ pretend . call ( expected_path ) ] ) #NEWLINE# assert ( fake_open . calls == [ pretend . call ( expected_path ) , pretend . call ( expected_path ) , pretend . call ( expected_path , 'w' ) ] ) #NEWLINE# assert len ( fake_file . write . calls )