Esempio n. 1
0
	def test5_decorated_methods( self) :
		dwa = DecoratorRegistry.parametrized_decorator( decorator_with_args)
		jd = DecoratorRegistry.decorator( decorator_with_args)
		
		class TestClass( object):
			@jd
			@dwa(1, 2, 3)
			@free_decorator
			def test_method( self) :
				pass
		
		self.assertTrue( 'test_method' in next( DecoratorRegistry.decorated_methods( TestClass, jd)))
		self.assertTrue( 'test_method' in next( DecoratorRegistry.decorated_methods( TestClass, dwa)))
		self.assertFalse( len( list( DecoratorRegistry.decorated_methods( TestClass, free_decorator))) != 0)
Esempio n. 2
0
	def test6_get_decorators( self) :
		from . import testmodule
		
		decos = DecoratorRegistry.get_decorators( testmodule.non_class_member)

		self.assertTrue( testmodule.deco in decos)
		self.assertTrue( testmodule.deco2 in decos)
		self.assertEqual( len( decos), 2)
Esempio n. 3
0
	def test3_parametrized_decorator( self) :
		@decorator_with_args(1, 2, 3)
		def somefunc( *args) : return args
		noregres = somefunc( 7, 7, 7)

		rdwa = DecoratorRegistry.parametrized_decorator( decorator_with_args)
		@rdwa(1, 2, 3)
		def somefunc2( *args) : return args
		regres = somefunc2( 7, 7, 7)

		self.assertEqual( noregres, regres)
		self.assertTrue( DecoratorRegistry.DECORATOR in somefunc2.__annotations__)
		self.assertTrue( DecoratorRegistry.NATIVE_FUNCTION in somefunc2.__annotations__)
		self.assertEqual( somefunc2.__annotations__[DecoratorRegistry.NATIVE_FUNCTION].__name__, 'somefunc2')
		self.assertTrue( DecoratorRegistry.DECORATORS in somefunc2.__annotations__[DecoratorRegistry.NATIVE_FUNCTION].__annotations__)
		self.assertTrue( rdwa in somefunc2.__annotations__[DecoratorRegistry.NATIVE_FUNCTION].__annotations__[DecoratorRegistry.DECORATORS])
Esempio n. 4
0
	def test2_decorator( self) :
		@just_decorator
		def somefunc( *args) : return args
		noregres = somefunc( 7, 7, 7)

		rjd = DecoratorRegistry.decorator( just_decorator)
		@rjd
		def somefunc2( *args) : return args
		regres = somefunc2( 7, 7, 7)

		self.assertEqual( noregres, regres)
		self.assertTrue( DecoratorRegistry.DECORATOR in somefunc2.__annotations__)
		self.assertTrue( DecoratorRegistry.NATIVE_FUNCTION in somefunc2.__annotations__)
		self.assertEqual( somefunc2.__annotations__[DecoratorRegistry.NATIVE_FUNCTION].__name__, 'somefunc2')
		self.assertTrue( DecoratorRegistry.DECORATORS in somefunc2.__annotations__[DecoratorRegistry.NATIVE_FUNCTION].__annotations__)
		self.assertTrue( rjd in somefunc2.__annotations__[DecoratorRegistry.NATIVE_FUNCTION].__annotations__[DecoratorRegistry.DECORATORS])
Esempio n. 5
0
	def test4_is_decorated_with( self) :
		@decorator_with_args(1, 2, 3)
		def somefunc10( *args) : return args
		rdwa = DecoratorRegistry.parametrized_decorator( decorator_with_args)
		@rdwa(1, 2, 3)
		def somefunc20( *args) : return args
		
		@just_decorator
		def somefunc30( *args) : return args
		rjd = DecoratorRegistry.decorator( just_decorator)
		@rjd
		def somefunc40( *args) : return args

		self.assertFalse( DecoratorRegistry.is_decorated_with( somefunc10, decorator_with_args))
		self.assertTrue( DecoratorRegistry.is_decorated_with( somefunc20, rdwa))
		self.assertFalse( DecoratorRegistry.is_decorated_with( somefunc30, just_decorator))
		self.assertTrue( DecoratorRegistry.is_decorated_with( somefunc40, rjd))
Esempio n. 6
0
from regd import DecoratorRegistry as dreg


def check_values(f):
    """ side - side of polygone
        n - count a polygone top
    """
    def decorated(self, a):
        if a > 0:
            return f(self, a)
        else:
            msg = "{} is out of positive range"
            raise ValueError(msg.format(a))

    return decorated


check_values = dreg.decorator(check_values)
Esempio n. 7
0
	def test1_make_portable( self) :
		def somefunc() : pass
		DecoratorRegistry._make_portable( somefunc)
		self.assertTrue( hasattr( somefunc, '__annotations__'))
Esempio n. 8
0
	def test8_module_functions_decorated_with( self) :
		from . import testmodule
		funcs = list( DecoratorRegistry.module_functions_decorated_with( testmodule, testmodule.deco2))
		self.assertEqual( len( funcs), 2)
Esempio n. 9
0
	def test7_all_decorated_module_functions( self) :
		from . import testmodule
		funcs = list( DecoratorRegistry.all_decorated_module_functions( testmodule))
		self.assertEqual( len( funcs), 3)
Esempio n. 10
0
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from regd import DecoratorRegistry

def deco( fn):
	def wrapper( *a, **k) :
		return fn( *a, **k)
	return wrapper

def deco2( fn):
	def wrapper( *a, **k) :
		return fn( *a, **k)
	return wrapper

deco  = DecoratorRegistry.decorator( deco)
deco2 = DecoratorRegistry.decorator( deco2)

class Test( object) :
	@staticmethod
	def only_static_method() :
		pass

	@staticmethod
	@deco
	def static_method() :
		pass

	@deco
	@deco2
	def class_member( self) :