當前位置: 首頁>>代碼示例>>Python>>正文


Python types.ModuleType方法代碼示例

本文整理匯總了Python中types.ModuleType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.ModuleType方法的具體用法?Python types.ModuleType怎麽用?Python types.ModuleType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在types的用法示例。


在下文中一共展示了types.ModuleType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: iterate_module_attributes

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def iterate_module_attributes(module):
    """
    Iterate over the attributes in a module.

    This is a generator function.

    Returns (name, value) tuples.
    """
    for name in dir(module):
        # Ignore fields marked as private or builtin.
        if name.startswith('_'):
            continue

        value = getattr(module, name)

        # Ignore callable objects (functions) and loaded modules.
        if callable(value) or isinstance(value, types.ModuleType):
            continue

        yield (name, value) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:22,代碼來源:settings.py

示例2: read_table

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def read_table(self,module):
        if isinstance(module,types.ModuleType):
            parsetab = module
        else:
            if sys.version_info[0] < 3:
                exec("import %s as parsetab" % module)
            else:
                env = { }
                exec("import %s as parsetab" % module, env, env)
                parsetab = env['parsetab']

        if parsetab._tabversion != __tabversion__:
            raise VersionError("yacc table file version is out of date")

        self.lr_action = parsetab._lr_action
        self.lr_goto = parsetab._lr_goto

        self.lr_productions = []
        for p in parsetab._lr_productions:
            self.lr_productions.append(MiniProduction(*p))

        self.lr_method = parsetab._lr_method
        return parsetab._lr_signature 
開發者ID:nojanath,項目名稱:SublimeKSP,代碼行數:25,代碼來源:yacc.py

示例3: test_iter_builders_side_effect

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_iter_builders_side_effect(self):
        # inject dummy module and add cleanup
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
            ])),
        ), 'app', '1.0', working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})

        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        self.assertFalse(exists(root))
        ep, toolchain, spec = next(registry.iter_builders_for('app'))
        self.assertFalse(exists(root))
        # directory only created after the toolchain is executed
        toolchain(spec)
        self.assertTrue(exists(root)) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:27,代碼來源:test_artifact.py

示例4: test_get_modpath_pkg_resources_missing_path

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_get_modpath_pkg_resources_missing_path(self):
        with pretty_logging(stream=StringIO()) as fd:
            self.assertEqual([], indexer.modpath_pkg_resources(
                None, calmjs_ep))
            self.assertIn(
                "None does not appear to be a valid module", fd.getvalue())
        with pretty_logging(stream=StringIO()) as fd:
            module = ModuleType('nothing')
            self.assertEqual([], indexer.modpath_pkg_resources(
                module, calmjs_ep))

        err = fd.getvalue()
        self.assertIn(
            "module 'nothing' and entry_point 'demo = demo'", err)
        # the input is fetched using a working entry_point, after all
        self.assertIn("resource path resolved to be '" + calmjs_dist_dir, err)
        self.assertIn("but it does not exist", fd.getvalue()) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:19,代碼來源:test_indexer.py

示例5: from_pyfile

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def from_pyfile(self, filename):
        """Update the values in the config from a Python file.
        Only the uppercase variables in that module are stored in the config.

        :param filename: an absolute path to the config file
        """
        module = types.ModuleType("config")
        module.__file__ = filename
        try:
            with open(filename) as config_file:
                exec(  # nosec
                    compile(config_file.read(), filename, "exec"),
                    module.__dict__,
                )
        except IOError as e:
            e.strerror = "Unable to load configuration file (%s)" % e.strerror
            raise
        except Exception as e:
            raise PyFileError(filename) from e

        self.from_object(module)
        return True 
開發者ID:huge-success,項目名稱:sanic,代碼行數:24,代碼來源:config.py

示例6: test_loadTestsFromModule__TestCase_subclass

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromModule__TestCase_subclass(self):
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            def test(self):
                pass
        m.testcase_1 = MyTestCase

        loader = unittest.TestLoader()
        suite = loader.loadTestsFromModule(m)
        self.assertIsInstance(suite, loader.suiteClass)

        expected = [loader.suiteClass([MyTestCase('test')])]
        self.assertEqual(list(suite), expected)

    # "This method searches `module` for classes derived from TestCase"
    #
    # What happens if no tests are found (no TestCase instances)? 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:19,代碼來源:test_loader.py

示例7: test_loadTestsFromModule__no_TestCase_tests

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromModule__no_TestCase_tests(self):
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            pass
        m.testcase_1 = MyTestCase

        loader = unittest.TestLoader()
        suite = loader.loadTestsFromModule(m)
        self.assertIsInstance(suite, loader.suiteClass)

        self.assertEqual(list(suite), [loader.suiteClass()])

    # "This method searches `module` for classes derived from TestCase"s
    #
    # What happens if loadTestsFromModule() is given something other
    # than a module?
    #
    # XXX Currently, it succeeds anyway. This flexibility
    # should either be documented or loadTestsFromModule() should
    # raise a TypeError
    #
    # XXX Certain people are using this behaviour. We'll add a test for it 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:24,代碼來源:test_loader.py

示例8: test_loadTestsFromModule__load_tests

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromModule__load_tests(self):
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            def test(self):
                pass
        m.testcase_1 = MyTestCase

        load_tests_args = []
        def load_tests(loader, tests, pattern):
            self.assertIsInstance(tests, unittest.TestSuite)
            load_tests_args.extend((loader, tests, pattern))
            return tests
        m.load_tests = load_tests

        loader = unittest.TestLoader()
        suite = loader.loadTestsFromModule(m)
        self.assertIsInstance(suite, unittest.TestSuite)
        self.assertEqual(load_tests_args, [loader, suite, None])

        load_tests_args = []
        suite = loader.loadTestsFromModule(m, use_load_tests=False)
        self.assertEqual(load_tests_args, []) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:24,代碼來源:test_loader.py

示例9: test_loadTestsFromName__relative_TestCase_subclass

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__relative_TestCase_subclass(self):
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            def test(self):
                pass
        m.testcase_1 = MyTestCase

        loader = unittest.TestLoader()
        suite = loader.loadTestsFromName('testcase_1', m)
        self.assertIsInstance(suite, loader.suiteClass)
        self.assertEqual(list(suite), [MyTestCase('test')])

    # "The specifier name is a ``dotted name'' that may resolve either to
    # a module, a test case class, a TestSuite instance, a test method
    # within a test case class, or a callable object which returns a
    # TestCase or TestSuite instance." 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:18,代碼來源:test_loader.py

示例10: test_loadTestsFromName__relative_testmethod

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__relative_testmethod(self):
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            def test(self):
                pass
        m.testcase_1 = MyTestCase

        loader = unittest.TestLoader()
        suite = loader.loadTestsFromName('testcase_1.test', m)
        self.assertIsInstance(suite, loader.suiteClass)

        self.assertEqual(list(suite), [MyTestCase('test')])

    # "The specifier name is a ``dotted name'' that may resolve either to
    # a module, a test case class, a TestSuite instance, a test method
    # within a test case class, or a callable object which returns a
    # TestCase or TestSuite instance."
    #
    # Does loadTestsFromName() raise the proper exception when trying to
    # resolve "a test method within a test case class" that doesn't exist
    # for the given name (relative to a provided module)? 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:23,代碼來源:test_loader.py

示例11: test_loadTestsFromName__relative_invalid_testmethod

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__relative_invalid_testmethod(self):
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            def test(self):
                pass
        m.testcase_1 = MyTestCase

        loader = unittest.TestLoader()
        try:
            loader.loadTestsFromName('testcase_1.testfoo', m)
        except AttributeError as e:
            self.assertEqual(str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
        else:
            self.fail("Failed to raise AttributeError")

    # "The specifier name is a ``dotted name'' that may resolve ... to
    # ... a callable object which returns a ... TestSuite instance" 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:19,代碼來源:test_loader.py

示例12: test_loadTestsFromName__callable__TestCase_instance

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__callable__TestCase_instance(self):
        m = types.ModuleType('m')
        testcase_1 = unittest.FunctionTestCase(lambda: None)
        def return_TestCase():
            return testcase_1
        m.return_TestCase = return_TestCase

        loader = unittest.TestLoader()
        suite = loader.loadTestsFromName('return_TestCase', m)
        self.assertIsInstance(suite, loader.suiteClass)
        self.assertEqual(list(suite), [testcase_1])

    # "The specifier name is a ``dotted name'' that may resolve ... to
    # ... a callable object which returns a TestCase ... instance"
    #*****************************************************************
    #Override the suiteClass attribute to ensure that the suiteClass
    #attribute is used 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:19,代碼來源:test_loader.py

示例13: test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass(self):
        class SubTestSuite(unittest.TestSuite):
            pass
        m = types.ModuleType('m')
        testcase_1 = unittest.FunctionTestCase(lambda: None)
        def return_TestCase():
            return testcase_1
        m.return_TestCase = return_TestCase

        loader = unittest.TestLoader()
        loader.suiteClass = SubTestSuite
        suite = loader.loadTestsFromName('return_TestCase', m)
        self.assertIsInstance(suite, loader.suiteClass)
        self.assertEqual(list(suite), [testcase_1])

    # "The specifier name is a ``dotted name'' that may resolve ... to
    # ... a test method within a test case class"
    #*****************************************************************
    #Override the suiteClass attribute to ensure that the suiteClass
    #attribute is used 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:22,代碼來源:test_loader.py

示例14: test_loadTestsFromName__relative_testmethod_ProperSuiteClass

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__relative_testmethod_ProperSuiteClass(self):
        class SubTestSuite(unittest.TestSuite):
            pass
        m = types.ModuleType('m')
        class MyTestCase(unittest.TestCase):
            def test(self):
                pass
        m.testcase_1 = MyTestCase

        loader = unittest.TestLoader()
        loader.suiteClass=SubTestSuite
        suite = loader.loadTestsFromName('testcase_1.test', m)
        self.assertIsInstance(suite, loader.suiteClass)

        self.assertEqual(list(suite), [MyTestCase('test')])

    # "The specifier name is a ``dotted name'' that may resolve ... to
    # ... a callable object which returns a TestCase or TestSuite instance"
    #
    # What happens if the callable returns something else? 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:22,代碼來源:test_loader.py

示例15: test_loadTestsFromName__callable__wrong_type

# 需要導入模塊: import types [as 別名]
# 或者: from types import ModuleType [as 別名]
def test_loadTestsFromName__callable__wrong_type(self):
        m = types.ModuleType('m')
        def return_wrong():
            return 6
        m.return_wrong = return_wrong

        loader = unittest.TestLoader()
        try:
            suite = loader.loadTestsFromName('return_wrong', m)
        except TypeError:
            pass
        else:
            self.fail("TestLoader.loadTestsFromName failed to raise TypeError")

    # "The specifier can refer to modules and packages which have not been
    # imported; they will be imported as a side-effect" 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:18,代碼來源:test_loader.py


注:本文中的types.ModuleType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。