# Path: checkpy/entities/function.py
# class Function(object):
# 	def __init__(self, function):
# 		self._function = function
# 		self._printOutput = ""
# 
# 	def __call__(self, *args, **kwargs):
# 		old = sys.stdout
# 		try:
# 			with self._captureStdout() as listener:
# 				outcome = self._function(*args, **kwargs)
# 				self._printOutput = ""#listener.content
# 				return outcome
# 		except Exception as e:
# 			sys.stdout = old
# 			argumentNames = self.arguments
# 			nArgs = len(args) + len(kwargs)
# 
# 			message = "while trying to execute {}()".format(self.name)
# 			if nArgs > 0:
# 				argsRepr = ", ".join("{}={}".format(argumentNames[i], args[i]) for i in range(len(args)))
# 				kwargsRepr = ", ".join("{}={}".format(kwargName, kwargs[kwargName]) for kwargName in argumentNames[len(args):nArgs])
# 				representation = ", ".join(s for s in [argsRepr, kwargsRepr] if s)
# 				message = "while trying to execute {}({})".format(self.name, representation)
# 
# 			raise exception.SourceException(exception = e, message = message)
# 
# 	@property
# 	def name(self):
# 		"""gives the name of the function"""
# 		return self._function.__name__
# 
# 	@property
# 	def arguments(self):
# 		"""gives the argument names of the function"""
# 		return inspect.getfullargspec(self._function)[0]
# 
# 	@property
# 	def printOutput(self):
# 		"""stateful function that returns the print (stdout) output of the latest function call as a string"""
# 		return self._printOutput
# 
# 	@contextlib.contextmanager
# 	def _captureStdout(self):
# 		"""
# 		capture sys.stdout in _outStream
# 		    (a _Stream that is an instance of StringIO extended with the Observer pattern)
# 		returns a _StreamListener on said stream
# 		"""
# 		outStreamListener = _StreamListener(_outStream)
# 		old = sys.stdout
# 
# 		outStreamListener.start()
# 		sys.stdout = outStreamListener.stream
# 
# 		try:
# 			yield outStreamListener
# 		except:
# 			raise
# 		finally:
# 			sys.stdout = old
# 			outStreamListener.stop()


import unittest
import os
import shutil
import checkpy.lib as lib
import checkpy.entities.exception as exception
from checkpy.entities.function import Function

class TestFunctionName(unittest.TestCase):
    def test_name(self):
        def foo():
            pass

# Path: checkpy/entities/function.py
# class Function(object):
# 	def __init__(self, function):
# 		self._function = function
# 		self._printOutput = ""
# 
# 	def __call__(self, *args, **kwargs):
# 		old = sys.stdout
# 		try:
# 			with self._captureStdout() as listener:
# 				outcome = self._function(*args, **kwargs)
# 				self._printOutput = ""#listener.content
# 				return outcome
# 		except Exception as e:
# 			sys.stdout = old
# 			argumentNames = self.arguments
# 			nArgs = len(args) + len(kwargs)
# 
# 			message = "while trying to execute {}()".format(self.name)
# 			if nArgs > 0:
# 				argsRepr = ", ".join("{}={}".format(argumentNames[i], args[i]) for i in range(len(args)))
# 				kwargsRepr = ", ".join("{}={}".format(kwargName, kwargs[kwargName]) for kwargName in argumentNames[len(args):nArgs])
# 				representation = ", ".join(s for s in [argsRepr, kwargsRepr] if s)
# 				message = "while trying to execute {}({})".format(self.name, representation)
# 
# 			raise exception.SourceException(exception = e, message = message)
# 
# 	@property
# 	def name(self):
# 		"""gives the name of the function"""
# 		return self._function.__name__
# 
# 	@property
# 	def arguments(self):
# 		"""gives the argument names of the function"""
# 		return inspect.getfullargspec(self._function)[0]
# 
# 	@property
# 	def printOutput(self):
# 		"""stateful function that returns the print (stdout) output of the latest function call as a string"""
# 		return self._printOutput
# 
# 	@contextlib.contextmanager
# 	def _captureStdout(self):
# 		"""
# 		capture sys.stdout in _outStream
# 		    (a _Stream that is an instance of StringIO extended with the Observer pattern)
# 		returns a _StreamListener on said stream
# 		"""
# 		outStreamListener = _StreamListener(_outStream)
# 		old = sys.stdout
# 
# 		outStreamListener.start()
# 		sys.stdout = outStreamListener.stream
# 
# 		try:
# 			yield outStreamListener
# 		except:
# 			raise
# 		finally:
# 			sys.stdout = old
# 			outStreamListener.stop()


# Path: tests/unittests/function_test.py
import unittest
import os
import shutil
import checkpy.lib as lib
import checkpy.entities.exception as exception
from checkpy.entities.function import Function


class TestFunctionName(unittest.TestCase):
    def test_name(self):
        def foo():
            pass

        self.assertEqual(Function(foo).name, "foo")