我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用setuptools.depends.extract_constant()。
def testExtractConst(self): if not hasattr(dep, 'extract_constant'): # skip on non-bytecode platforms return def f1(): global x, y, z x = "test" y = z fc = func_code(f1) # unrecognized name self.assertEqual(dep.extract_constant(fc,'q', -1), None) # constant assigned self.assertEqual(dep.extract_constant(fc,'x', -1), "test") # expression assigned self.assertEqual(dep.extract_constant(fc,'y', -1), -1) # recognized name, not assigned self.assertEqual(dep.extract_constant(fc,'z', -1), None)
def testExtractConst(self): if not hasattr(dep, 'extract_constant'): # skip on non-bytecode platforms return def f1(): global x, y, z x = "test" y = z fc = func_code(f1) # unrecognized name assert dep.extract_constant(fc,'q', -1) is None # constant assigned dep.extract_constant(fc,'x', -1) == "test" # expression assigned dep.extract_constant(fc,'y', -1) == -1 # recognized name, not assigned dep.extract_constant(fc,'z', -1) is None
def testExtractConst(self): if not hasattr(dep, 'extract_constant'): # skip on non-bytecode platforms return def f1(): global x, y, z x = "test" y = z fc = six.get_function_code(f1) # unrecognized name assert dep.extract_constant(fc, 'q', -1) is None # constant assigned dep.extract_constant(fc, 'x', -1) == "test" # expression assigned dep.extract_constant(fc, 'y', -1) == -1 # recognized name, not assigned dep.extract_constant(fc, 'z', -1) is None
def testRequire(self): if not hasattr(dep, 'extract_constant'): # skip on non-bytecode platformsh return req = Require('Email','1.0.3','email') self.assertEqual(req.name, 'Email') self.assertEqual(req.module, 'email') self.assertEqual(req.requested_version, '1.0.3') self.assertEqual(req.attribute, '__version__') self.assertEqual(req.full_name(), 'Email-1.0.3') from email import __version__ self.assertEqual(req.get_version(), __version__) self.assertTrue(req.version_ok('1.0.9')) self.assertTrue(not req.version_ok('0.9.1')) self.assertTrue(not req.version_ok('unknown')) self.assertTrue(req.is_present()) self.assertTrue(req.is_current()) req = Require('Email 3000','03000','email',format=LooseVersion) self.assertTrue(req.is_present()) self.assertTrue(not req.is_current()) self.assertTrue(not req.version_ok('unknown')) req = Require('Do-what-I-mean','1.0','d-w-i-m') self.assertTrue(not req.is_present()) self.assertTrue(not req.is_current()) req = Require('Tests', None, 'tests', homepage="http://example.com") self.assertEqual(req.format, None) self.assertEqual(req.attribute, None) self.assertEqual(req.requested_version, None) self.assertEqual(req.full_name(), 'Tests') self.assertEqual(req.homepage, 'http://example.com') paths = [os.path.dirname(p) for p in __path__] self.assertTrue(req.is_present(paths)) self.assertTrue(req.is_current(paths))