def do_test(dirname): from codecs import open as real_open envdir = os.path.join(dirname, spec.name) manager = DefaultCondaManager(frontend=NullFrontend()) counts = dict(calls=0) def mock_open(*args, **kwargs): counts['calls'] += 1 if counts['calls'] == 1: raise IOError("did not open") else: return real_open(*args, **kwargs) monkeypatch.setattr('codecs.open', mock_open) # this should NOT throw but also should not write the # timestamp file (we ignore errors) filename = manager._timestamp_file(envdir, spec) assert filename.startswith(envdir) assert not os.path.exists(filename) manager._write_timestamp_file(envdir, spec) assert not os.path.exists(filename) # the second time we really wsrite it (this is to prove we # are looking at the right filename) manager._write_timestamp_file(envdir, spec) assert os.path.exists(filename) # check on the file contents with real_open(filename, 'r', encoding='utf-8') as f: content = json.loads(f.read()) assert dict(anaconda_project_version=version) == content
def do_test(dirname): from codecs import open as real_open envdir = os.path.join(dirname, spec.name) manager = DefaultCondaManager() counts = dict(calls=0) def mock_open(*args, **kwargs): counts['calls'] += 1 if counts['calls'] == 1: raise IOError("did not open") else: return real_open(*args, **kwargs) monkeypatch.setattr('codecs.open', mock_open) # this should NOT throw but also should not write the # timestamp file (we ignore errors) filename = manager._timestamp_file(envdir, spec) assert filename.startswith(envdir) assert not os.path.exists(filename) manager._write_timestamp_file(envdir, spec) assert not os.path.exists(filename) # the second time we really write it (this is to prove we # are looking at the right filename) manager._write_timestamp_file(envdir, spec) assert os.path.exists(filename) # check on the file contents with real_open(filename, 'r', encoding='utf-8') as f: content = json.loads(f.read()) assert dict(conda_kapsel_version=version) == content
def mock_codecs_open(*args, **kwargs): if args[0].endswith(".projectignore"): raise IOError("NOPE") else: return real_open(*args, **kwargs)
def mock_open(*args, **kwargs): counts['calls'] += 1 if counts['calls'] == 1: raise IOError("did not open") else: return real_open(*args, **kwargs)
def mock_open(*args, **kwargs): if is_readonly['readonly']: raise IOError("did not open") return real_open(*args, **kwargs)
def mock_codecs_open(*args, **kwargs): if args[0].endswith(".kapselignore"): raise IOError("NOPE") else: return real_open(*args, **kwargs)