def set_get_cache(gist_id, filename, body): path_base = "/tmp" gist_id = str(gist_id) # Make sure there is no cache for f in ( gistplugin.cache_filename(path_base, gist_id), gistplugin.cache_filename(path_base, gist_id, filename), ): if os.path.exists(f): os.remove(f) # Get an empty cache cache_file = gistplugin.get_cache(path_base, gist_id) assert cache_file is None cache_file = gistplugin.get_cache(path_base, gist_id, filename) assert cache_file is None # Set a cache file gistplugin.set_cache(path_base, gist_id, body) # Fetch the same file cached = gistplugin.get_cache(path_base, gist_id) assert cached == body # Set a cache file gistplugin.set_cache(path_base, gist_id, body, filename) # Fetch the same file cached = gistplugin.get_cache(path_base, gist_id, filename) assert cached == body
def set_get_cache(gist_id, filename, body): path_base = '/tmp' gist_id = str(gist_id) # Make sure there is no cache for f in (gistplugin.cache_filename(path_base, gist_id), gistplugin.cache_filename(path_base, gist_id, filename)): if os.path.exists(f): os.remove(f) # Get an empty cache cache_file = gistplugin.get_cache(path_base, gist_id) assert cache_file is None cache_file = gistplugin.get_cache(path_base, gist_id, filename) assert cache_file is None # Set a cache file gistplugin.set_cache(path_base, gist_id, body) # Fetch the same file cached = gistplugin.get_cache(path_base, gist_id) assert cached == body # Set a cache file gistplugin.set_cache(path_base, gist_id, body, filename) # Fetch the same file cached = gistplugin.get_cache(path_base, gist_id, filename) assert cached == body
def test_set_get_cache(): path_base = '/tmp' gist_id = str(3254906) filename = 'brew-update-notifier.sh' body = """Some gist body""" # Make sure there is no cache for f in (gistplugin.cache_filename(path_base, gist_id), gistplugin.cache_filename(path_base, gist_id, filename)): if os.path.exists(f): os.remove(f) # Get an empty cache cache_file = gistplugin.get_cache(path_base, gist_id) assert cache_file is None cache_file = gistplugin.get_cache(path_base, gist_id, filename) assert cache_file is None # Set a cache file gistplugin.set_cache(path_base, gist_id, body) # Fetch the same file cached = gistplugin.get_cache(path_base, gist_id) assert cached == body # Set a cache file gistplugin.set_cache(path_base, gist_id, body, filename) # Fetch the same file cached = gistplugin.get_cache(path_base, gist_id, filename) assert cached == body
def test_cache_filename(): path_base = "/tmp" gist_id = str(3254906) filename = "brew-update-notifier.sh" # Test without a filename path = gistplugin.cache_filename(path_base, gist_id) assert path.startswith(path_base) assert path.endswith(".cache") # Test with filename path = gistplugin.cache_filename(path_base, gist_id, filename) assert path.startswith(path_base) assert path.endswith(".cache")
def test_cache_filename(): path_base = '/tmp' gist_id = str(3254906) filename = 'brew-update-notifier.sh' # Test without a filename path = gistplugin.cache_filename(path_base, gist_id) assert path.startswith(path_base) assert path.endswith('.cache') # Test with filename path = gistplugin.cache_filename(path_base, gist_id, filename) assert path.startswith(path_base) assert path.endswith('.cache')