コード例 #1
0
    def test_is_allowlisted_callable_allowlisted_call(self):

        allowlisted_mod = imp.new_module('test_allowlisted_call')
        sys.modules['test_allowlisted_call'] = allowlisted_mod
        config.CONVERSION_RULES = (
            (config.DoNotConvert('test_allowlisted_call'), ) +
            config.CONVERSION_RULES)

        class TestClass(object):
            def __call__(self):
                pass

            def allowlisted_method(self):
                pass

        TestClass.__module__ = 'test_allowlisted_call'
        if six.PY2:
            TestClass.__call__.__func__.__module__ = 'test_allowlisted_call'
        else:
            TestClass.__call__.__module__ = 'test_allowlisted_call'

        class Subclass(TestClass):
            def converted_method(self):
                pass

        tc = Subclass()

        self.assertTrue(conversion.is_allowlisted(TestClass.__call__))
        self.assertTrue(conversion.is_allowlisted(tc))
        self.assertTrue(conversion.is_allowlisted(tc.__call__))
        self.assertTrue(conversion.is_allowlisted(tc.allowlisted_method))
        self.assertFalse(conversion.is_allowlisted(Subclass))
        self.assertFalse(conversion.is_allowlisted(tc.converted_method))
コード例 #2
0
def whitelist(entity):
  if 'test_whitelisted_call' not in sys.modules:
    whitelisted_mod = imp.new_module('test_whitelisted_call')
    sys.modules['test_whitelisted_call'] = whitelisted_mod
    config.CONVERSION_RULES = ((config.DoNotConvert('test_whitelisted_call'),) +
                               config.CONVERSION_RULES)

  entity.__module__ = 'test_whitelisted_call'
コード例 #3
0
def whitelist(f):
    """Helper that marks a callable as whtelitisted."""
    if 'whitelisted_module_for_testing' not in sys.modules:
        whitelisted_mod = imp.new_module('whitelisted_module_for_testing')
        sys.modules['whitelisted_module_for_testing'] = whitelisted_mod
        config.CONVERSION_RULES = (
            (config.DoNotConvert('whitelisted_module_for_testing'), ) +
            config.CONVERSION_RULES)

    f.__module__ = 'whitelisted_module_for_testing'