Skip to content

Instantly share code, notes, and snippets.

@math2001
Created November 14, 2016 07:00
Show Gist options
  • Save math2001/b2474a53b50937c136441abebd792c40 to your computer and use it in GitHub Desktop.
Save math2001/b2474a53b50937c136441abebd792c40 to your computer and use it in GitHub Desktop.
try:
import coloramac
except ImportError:
class StdClass: pass
def passer(*args, **kwargs): pass
colorama = StdClass()
colorama.init = passer
colorama.Fore = StdClass()
colorama.Fore.RED = colorama.Fore.GREEN = ''
def check_for_use(show=False):
if show:
try:
check_for_use.functions
except AttributeError:
return
no_error = True
for function in check_for_use.functions.keys():
if check_for_use.functions[function][0] is False:
print(colorama.Fore.RED + 'The function {!r} hasn\'t been called. Defined in "{}" '.format(function, check_for_use.functions[function][1].__code__.co_filename))
no_error = False
if no_error:
print(colorama.Fore.GREEN + 'Great! All your checked function are being called!')
return check_for_use.functions
try:
check_for_use.functions
except AttributeError:
check_for_use.functions = {}
if colorama:
colorama.init(autoreset=True)
def add(function):
check_for_use.functions[function.__name__] = [False, function]
def func(*args, **kwargs):
check_for_use.functions[function.__name__] = [True, function]
function(*args, **kwargs)
return func
return add
@check_for_use()
def hello():
print('Hello world!')
@check_for_use()
def bonjour(nb):
print('Bonjour tout le monde!')
check_for_use(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment