本文整理汇总了Python中unittest.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.__file__方法的具体用法?Python unittest.__file__怎么用?Python unittest.__file__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest
的用法示例。
在下文中一共展示了unittest.__file__方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def run_tests(self):
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False):
module = self.test_args[-1].split('.')[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
unittest_main(
None, None, [unittest.__file__]+self.test_args,
testLoader=self._resolve_as_ep(self.test_loader),
testRunner=self._resolve_as_ep(self.test_runner),
)
示例2: run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def run_tests(self):
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if PY3 and getattr(self.distribution, 'use_2to3', False):
module = self.test_args[-1].split('.')[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
unittest_main(
None, None, [unittest.__file__] + self.test_args,
testLoader=self._resolve_as_ep(self.test_loader),
testRunner=self._resolve_as_ep(self.test_runner),
)
示例3: run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def run_tests(self):
import unittest
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False):
module = self.test_args[-1].split('.')[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
loader_ep = EntryPoint.parse("x="+self.test_loader)
loader_class = loader_ep.load(require=False)
cks = loader_class()
unittest.main(
None, None, [unittest.__file__]+self.test_args,
testLoader = cks
)
示例4: test_file
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def test_file(self):
fp = open(unittest.__file__)
self.assertTrue(repr(fp).startswith(
"<open file %r, mode 'r' at 0x" % unittest.__file__))
fp.close()
self.assertTrue(repr(fp).startswith(
"<closed file %r, mode 'r' at 0x" % unittest.__file__))
示例5: test_module
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def test_module(self):
eq = self.assertEqual
touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py'))
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
eq(repr(areallylongpackageandmodulenametotestreprtruncation),
"<module '%s' from '%s'>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
eq(repr(sys), "<module 'sys' (built-in)>")
示例6: test_file
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def test_file(self):
fp = open(unittest.__file__)
self.failUnless(repr(fp).startswith(
"<open file '%s', mode 'r' at 0x" % unittest.__file__))
fp.close()
self.failUnless(repr(fp).startswith(
"<closed file '%s', mode 'r' at 0x" % unittest.__file__))
示例7: test_module
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def test_module(self):
eq = self.assertEquals
touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py'))
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
eq(repr(areallylongpackageandmodulenametotestreprtruncation),
"<module '%s' from '%s'>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
# XXX: Jython sys module is not a real module
#eq(repr(sys), "<module 'sys' (built-in)>")
示例8: testCompileLibrary
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def testCompileLibrary(self):
# A simple but large test. Compile all the code in the
# standard library and its test suite. This doesn't verify
# that any of the code is correct, merely the compiler is able
# to generate some kind of code for it.
next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
libdir = os.path.dirname(unittest.__file__)
testdir = os.path.dirname(test.test_support.__file__)
for dir in [libdir, testdir]:
for basename in os.listdir(dir):
# Print still working message since this test can be really slow
if next_time <= time.time():
next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
print >>sys.__stdout__, \
' testCompileLibrary still working, be patient...'
sys.__stdout__.flush()
if not basename.endswith(".py"):
continue
if not TEST_ALL and random() < 0.98:
continue
path = os.path.join(dir, basename)
if test.test_support.verbose:
print "compiling", path
f = open(path, "U")
buf = f.read()
f.close()
if "badsyntax" in basename or "bad_coding" in basename:
self.assertRaises(SyntaxError, compiler.compile,
buf, basename, "exec")
else:
try:
compiler.compile(buf, basename, "exec")
except Exception, e:
args = list(e.args)
args[0] += "[in file %s]" % basename
e.args = tuple(args)
raise
示例9: testLineNo
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def testLineNo(self):
# Test that all nodes except Module have a correct lineno attribute.
filename = __file__
if filename.endswith((".pyc", ".pyo")):
filename = filename[:-1]
tree = compiler.parseFile(filename)
self.check_lineno(tree)
示例10: test_module
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import __file__ [as 别名]
def test_module(self):
eq = self.assertEqual
touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py'))
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
eq(repr(areallylongpackageandmodulenametotestreprtruncation),
"<module '%s' from '%s'>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
# XXX: Jython sys module is not a real module
#eq(repr(sys), "<module 'sys' (built-in)>")