当前位置: 首页>>代码示例>>Python>>正文


Python unittest.py方法代码示例

本文整理汇总了Python中unittest.py方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.py方法的具体用法?Python unittest.py怎么用?Python unittest.py使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest的用法示例。


在下文中一共展示了unittest.py方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_tests

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def find_tests(testdir,
               prefixes=DEFAULT_PREFIXES, suffix=".py",
               excludes=(),
               remove_suffix=True):
    """
    Return a list of all applicable test modules.
    """
    tests = []
    for name in os.listdir(testdir):
        if not suffix or name.endswith(suffix):
            for prefix in prefixes:
                if name.startswith(prefix):
                    if remove_suffix and name.endswith(suffix):
                        name = name[:-len(suffix)]
                    if name not in excludes:
                        tests.append(name)
    tests.sort()
    return tests 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:20,代码来源:testlib.py

示例2: test___is_valid_py_file

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test___is_valid_py_file(self):
        isvalid = self.MyTestRunner._PydevTestRunner__is_valid_py_file
        self.assertEqual(1, isvalid("test.py"))
        self.assertEqual(0, isvalid("asdf.pyc"))
        self.assertEqual(0, isvalid("__init__.py"))
        self.assertEqual(0, isvalid("__init__.pyc"))
        self.assertEqual(1, isvalid("asdf asdf.pyw")) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:9,代码来源:test_runfiles.py

示例3: test___unixify

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test___unixify(self):
        unixify = self.MyTestRunner._PydevTestRunner__unixify
        self.assertEqual("c:/temp/junk/asdf.py", unixify("c:SEPtempSEPjunkSEPasdf.py".replace('SEP', os.sep))) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:5,代码来源:test_runfiles.py

示例4: test___importify

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test___importify(self):
        importify = self.MyTestRunner._PydevTestRunner__importify
        self.assertEqual("temp.junk.asdf", importify("temp/junk/asdf.py"))
        self.assertEqual("asdf", importify("asdf.py"))
        self.assertEqual("abc.def.hgi", importify("abc/def/hgi")) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:7,代码来源:test_runfiles.py

示例5: test_finding_a_file_from_file_system

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test_finding_a_file_from_file_system(self):
        test_file = "simple_test.py"
        self.MyTestRunner.files_or_dirs = [self.file_dir[0] + test_file]
        files = self.MyTestRunner.find_import_files()
        self.assertEqual(1, len(files))
        self.assertEqual(files[0], self.file_dir[0] + test_file) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:8,代码来源:test_runfiles.py

示例6: test_finding_tests_when_no_filter

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test_finding_tests_when_no_filter(self):
        # unittest.py will create a TestCase with 0 tests in it
        # since it just imports what is given
        self.assertEqual(1, len(self.all_tests) > 0)
        files_with_tests = [1 for t in self.all_tests if len(t._tests) > 0]
        self.assertNotEqual(len(self.files), len(files_with_tests)) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:8,代码来源:test_runfiles.py

示例7: loadTestsFromName

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def loadTestsFromName(self, name, module=None):
        parts = name.split('.')
        if module is None or len(parts) > 2:
            # let the base class do its job here
            return [super(NonStrictTestLoader, self).loadTestsFromName(name)]
        tests = self._collect_tests(module)
        # import pprint
        # pprint.pprint(tests)
        collected = []
        if len(parts) == 1:
            pattern = parts[0]
            if callable(getattr(module, pattern, None)) and pattern not in tests:
                # consider it as a suite
                return self.loadTestsFromSuite(module, pattern)
            if pattern in tests:
                # case python unittest_foo.py MyTestTC
                klass, methodnames = tests[pattern]
                for methodname in methodnames:
                    collected = [klass(methodname) for methodname in methodnames]
            else:
                # case python unittest_foo.py something
                for klass, methodnames in list(tests.values()):
                    collected += [klass(methodname) for methodname in methodnames]
        elif len(parts) == 2:
            # case "MyClass.test_1"
            classname, pattern = parts
            klass, methodnames = tests.get(classname, (None, []))
            for methodname in methodnames:
                collected = [klass(methodname) for methodname in methodnames]
        return collected 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:32,代码来源:testlib.py

示例8: set_description

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def set_description(self, descr):
        """sets the current test's description.
        This can be useful for generative tests because it allows to specify
        a description per yield
        """
        self._current_test_descr = descr

    # override default's unittest.py feature 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:10,代码来源:testlib.py

示例9: __call__

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def __call__(self, result=None, runcondition=None, options=None):
        """rewrite TestCase.__call__ to support generative tests
        This is mostly a copy/paste from unittest.py (i.e same
        variable names, same logic, except for the generative tests part)
        """
        if result is None:
            result = self.defaultTestResult()
        result.pdbclass = self.pdbclass
        # if self.capture is True here, it means it was explicitly specified
        # in the user's TestCase class. If not, do what was asked on cmd line
        self.capture = self.capture or getattr(result, 'capture', False)
        self._options_ = options
        self._printonly = getattr(result, 'printonly', None)
        # if result.cvg:
        #     result.cvg.start()
        testMethod = self._get_test_method()
        if runcondition and not runcondition(testMethod):
            return # test is skipped
        result.startTest(self)
        try:
            if not self.quiet_run(result, self.setUp):
                return
            # generative tests
            if is_generator(testMethod.__func__):
                success = self._proceed_generative(result, testMethod, runcondition)
            else:
                status = self._proceed(result, testMethod)
                success = (status == 0)
            if not self.quiet_run(result, self.tearDown):
                return
            if success:
                result.addSuccess(self)
        finally:
            # if result.cvg:
            #     result.cvg.stop()
            result.stopTest(self) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:38,代码来源:testlib.py

示例10: create_files

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def create_files(paths, chroot):
    """creates directories and files found in <path>

    :param path: list of relative paths to files or directories
    :param chroot: the root directory in which paths will be created

    >>> from os.path import isdir, isfile
    >>> isdir('/tmp/a')
    False
    >>> create_files(['a/b/foo.py', 'a/b/c/', 'a/b/c/d/e.py'], '/tmp')
    >>> isdir('/tmp/a')
    True
    >>> isdir('/tmp/a/b/c')
    True
    >>> isfile('/tmp/a/b/c/d/e.py')
    True 
    >>> isfile('/tmp/a/b/foo.py')
    True
    """
    dirs, files = set(), set()
    for path in paths:
        path = osp.join(chroot, path)
        filename = osp.basename(path)
        # path is a directory path
        if filename == '':
            dirs.add(path)
        # path is a filename path
        else:
            dirs.add(osp.dirname(path))
            files.add(path)
    for dirpath in dirs:
        if not osp.isdir(dirpath):
            os.makedirs(dirpath)
    for filepath in files:
        file(filepath, 'w').close() 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:37,代码来源:testlib.py

示例11: test___is_valid_py_file

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test___is_valid_py_file(self):
        isvalid = self.MyTestRunner._PydevTestRunner__is_valid_py_file
        self.assertEquals(1, isvalid("test.py"))
        self.assertEquals(0, isvalid("asdf.pyc"))
        self.assertEquals(0, isvalid("__init__.py"))
        self.assertEquals(0, isvalid("__init__.pyc"))
        self.assertEquals(1, isvalid("asdf asdf.pyw")) 
开发者ID:mrknow,项目名称:filmkodi,代码行数:9,代码来源:test_runfiles.py

示例12: test___unixify

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test___unixify(self):
        unixify = self.MyTestRunner._PydevTestRunner__unixify
        self.assertEquals("c:/temp/junk/asdf.py", unixify("c:SEPtempSEPjunkSEPasdf.py".replace('SEP', os.sep))) 
开发者ID:mrknow,项目名称:filmkodi,代码行数:5,代码来源:test_runfiles.py

示例13: test___importify

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test___importify(self):
        importify = self.MyTestRunner._PydevTestRunner__importify
        self.assertEquals("temp.junk.asdf", importify("temp/junk/asdf.py"))
        self.assertEquals("asdf", importify("asdf.py"))
        self.assertEquals("abc.def.hgi", importify("abc/def/hgi")) 
开发者ID:mrknow,项目名称:filmkodi,代码行数:7,代码来源:test_runfiles.py

示例14: test_finding_a_file_from_file_system

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test_finding_a_file_from_file_system(self):
        test_file = "simple_test.py"
        self.MyTestRunner.files_or_dirs = [self.file_dir[0] + test_file]
        files = self.MyTestRunner.find_import_files()
        self.assertEquals(1, len(files))
        self.assertEquals(files[0], self.file_dir[0] + test_file) 
开发者ID:mrknow,项目名称:filmkodi,代码行数:8,代码来源:test_runfiles.py

示例15: test_finding_tests_when_no_filter

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import py [as 别名]
def test_finding_tests_when_no_filter(self):
        # unittest.py will create a TestCase with 0 tests in it
        # since it just imports what is given
        self.assertEquals(1, len(self.all_tests) > 0)
        files_with_tests = [1 for t in self.all_tests if len(t._tests) > 0]
        self.assertNotEquals(len(self.files), len(files_with_tests)) 
开发者ID:mrknow,项目名称:filmkodi,代码行数:8,代码来源:test_runfiles.py


注:本文中的unittest.py方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。