本文整理汇总了Python中twisted.trial.runner.filenameToModule函数的典型用法代码示例。如果您正苦于以下问题:Python filenameToModule函数的具体用法?Python filenameToModule怎么用?Python filenameToModule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filenameToModule函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_directory
def test_directory(self):
"""
Test loader against a filesystem directory. It should handle
'path' and 'path/' the same way.
"""
path = util.sibpath(__file__, 'goodDirectory')
os.mkdir(path)
f = file(os.path.join(path, '__init__.py'), "w")
f.close()
try:
module = runner.filenameToModule(path)
self.assert_(module.__name__.endswith('goodDirectory'))
module = runner.filenameToModule(path + os.path.sep)
self.assert_(module.__name__.endswith('goodDirectory'))
finally:
shutil.rmtree(path)
示例2: test_directory
def test_directory(self):
"""
Test loader against a filesystem directory containing an empty
C{__init__.py} file. It should handle 'path' and 'path/' the same way.
"""
goodDir = filepath.FilePath(self.parent).child('goodDirectory')
goodDir.createDirectory()
goodDir.child('__init__.py').setContent('')
try:
module = runner.filenameToModule(goodDir.path)
self.assert_(module.__name__.endswith('goodDirectory'))
module = runner.filenameToModule(goodDir.path + os.path.sep)
self.assert_(module.__name__.endswith('goodDirectory'))
finally:
goodDir.remove()
示例3: test_moduleInPath
def test_moduleInPath(self):
"""
If the file in question is a module on the Python path, then it should
properly import and return that module.
"""
sample1 = runner.filenameToModule(util.sibpath(__file__, 'sample.py'))
import sample as sample2
self.assertEqual(sample2, sample1)
示例4: test_packageNotInPath
def test_packageNotInPath(self):
sys.path, newPath = self.oldPath, sys.path
package1 = runner.filenameToModule(os.path.join(self.parent,
'goodpackage'))
sys.path = newPath
import goodpackage
self.failUnlessEqual(os.path.splitext(goodpackage.__file__)[0],
os.path.splitext(package1.__file__)[0])
示例5: test_packageNotInPath
def test_packageNotInPath(self):
self.mangleSysPath(self.oldPath)
package1 = runner.filenameToModule(os.path.join(self.parent,
'goodpackage'))
self.mangleSysPath(self.newPath)
import goodpackage
self.failUnlessEqual(os.path.splitext(goodpackage.__file__)[0],
os.path.splitext(package1.__file__)[0])
示例6: test_moduleNotInPath
def test_moduleNotInPath(self):
sys.path, newPath = self.oldPath, sys.path
sample1 = runner.filenameToModule(os.path.join(self.parent,
'goodpackage',
'test_sample.py'))
sys.path = newPath
from goodpackage import test_sample as sample2
self.failUnlessEqual(os.path.splitext(sample2.__file__)[0],
os.path.splitext(sample1.__file__)[0])
示例7: _loadNetTestFile
def _loadNetTestFile(self, net_test_file):
"""
Load NetTest from a file
"""
test_cases = []
module = filenameToModule(net_test_file)
for __, item in getmembers(module):
test_cases.extend(self._get_test_methods(item))
return test_cases
示例8: test_packageInPath
def test_packageInPath(self):
"""
If the file in question is a package on the Python path, then it should
properly import and return that package.
"""
package1 = runner.filenameToModule(os.path.join(self.parent,
'goodpackage'))
import goodpackage
self.assertEqual(goodpackage, package1)
示例9: test_filenameMatchesPackage
def test_filenameMatchesPackage(self):
filename = os.path.join(self.parent, 'goodpackage.py')
fd = open(filename, 'w')
fd.write(packages.testModule)
fd.close()
try:
module = runner.filenameToModule(filename)
self.failUnlessEqual(filename, module.__file__)
finally:
os.remove(filename)
示例10: test_filenameMatchesPackage
def test_filenameMatchesPackage(self):
"""
The C{__file__} attribute of the module should match the package name.
"""
filename = filepath.FilePath(self.parent).child('goodpackage.py')
filename.setContent(packages.testModule)
try:
module = runner.filenameToModule(filename.path)
self.assertEqual(filename.path, module.__file__)
finally:
filename.remove()
示例11: loadNetTestFile
def loadNetTestFile(net_test_file):
"""
Load NetTest from a file.
"""
test_cases = []
module = filenameToModule(net_test_file)
for __, item in getmembers(module):
test_cases.extend(get_test_methods(item))
if not test_cases:
raise NoTestCasesFound
return test_cases
示例12: loadNetTestFile
def loadNetTestFile(self, net_test_file):
"""
Load NetTest from a file.
"""
test_cases = []
module = filenameToModule(net_test_file)
for __, item in getmembers(module):
test_cases.extend(self._get_test_methods(item))
if not test_cases:
raise e.NoTestCasesFound
self.setupTestCases(test_cases)
示例13: getTestClassFromFile
def getTestClassFromFile(net_test_file):
"""
Will return the first class that is an instance of NetTestCase.
XXX this means that if inside of a test there are more than 1 test case
then we will only run the first one.
"""
module = filenameToModule(net_test_file)
for __, item in getmembers(module):
try:
assert issubclass(item, NetTestCase)
return item
except (TypeError, AssertionError):
pass
示例14: findTestClassesFromFile
def findTestClassesFromFile(cmd_line_options):
"""
Takes as input the command line config parameters and returns the test
case classes.
:param filename:
the absolute path to the file containing the ooniprobe test classes
:return:
A list of class objects found in a file or module given on the
commandline.
"""
filename = cmd_line_options["test"]
classes = []
module = filenameToModule(filename)
for name, val in inspect.getmembers(module):
if isTestCase(val):
classes.append(processTest(val, cmd_line_options))
return classes
示例15: test_moduleNotInPath
def test_moduleNotInPath(self):
"""
If passed the path to a file containing the implementation of a
module within a package which is not on the import path,
L{runner.filenameToModule} returns a module object loosely
resembling the module defined by that file anyway.
"""
# "test_sample" isn't actually the name of this module. However,
# filenameToModule can't seem to figure that out. So clean up this
# misnamed module. It would be better if this weren't necessary
# and filenameToModule either didn't exist or added a correctly
# named module to sys.modules.
self.addCleanup(sys.modules.pop, "test_sample", None)
self.mangleSysPath(self.oldPath)
sample1 = runner.filenameToModule(os.path.join(self.parent, "goodpackage", "test_sample.py"))
self.mangleSysPath(self.newPath)
from goodpackage import test_sample as sample2
self.assertEqual(os.path.splitext(sample2.__file__)[0], os.path.splitext(sample1.__file__)[0])