python类skipIf()的实例源码

test_break.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def testSecondInterrupt(self):
        # Can't use skipIf decorator because the signal handler may have
        # been changed after defining this method.
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest("test requires SIGINT to not be ignored")
        result = unittest2.TestResult()
        unittest2.installHandler()
        unittest2.registerResult(result)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)
            os.kill(pid, signal.SIGINT)
            self.fail("Second KeyboardInterrupt not raised")

        try:
            test(result)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("Second KeyboardInterrupt not raised")
        self.assertTrue(result.breakCaught)
test_break.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def testHandlerReplacedButCalled(self):
        # Can't use skipIf decorator because the signal handler may have
        # been changed after defining this method.
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest("test requires SIGINT to not be ignored")
        # If our handler has been replaced (is no longer installed) but is
        # called by the *new* handler, then it isn't safe to delay the
        # SIGINT and we should immediately delegate to the default handler
        unittest2.installHandler()

        handler = signal.getsignal(signal.SIGINT)
        def new_handler(frame, signum):
            handler(frame, signum)
        signal.signal(signal.SIGINT, new_handler)

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("replaced but delegated handler doesn't raise interrupt")
__init__.py 文件源码 项目:CSB 作者: csb-toolbox 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def skip(reason, condition=None):
    """
    Mark a test case or method for skipping.

    @param reason: message
    @type reason: str
    @param condition: skip only if the specified condition is True
    @type condition: bool/expression
    """
    if isinstance(reason, types.FunctionType):
        raise TypeError('skip: no reason specified')

    if condition is None:
        return unittest.skip(reason)
    else:
        return unittest.skipIf(condition, reason)
testing.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testing.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testing.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
test_skipping.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_skipping_decorators(self):
        op_table = ((unittest2.skipUnless, False, True),
                    (unittest2.skipIf, True, False))
        for deco, do_skip, dont_skip in op_table:
            class Foo(unittest2.TestCase):
                @deco(do_skip, "testing")
                def test_skip(self):
                    pass

                @deco(dont_skip, "testing")
                def test_dont_skip(self):
                    pass

            test_do_skip = Foo("test_skip")
            test_dont_skip = Foo("test_dont_skip")
            suite = unittest2.TestSuite([test_do_skip, test_dont_skip])
            events = []
            result = LoggingResult(events)
            suite.run(result)
            self.assertEqual(len(result.skipped), 1)
            expected = ['startTest', 'addSkip', 'stopTest',
                        'startTest', 'addSuccess', 'stopTest']
            self.assertEqual(events, expected)
            self.assertEqual(result.testsRun, 2)
            self.assertEqual(result.skipped, [(test_do_skip, "testing")])
            self.assertTrue(result.wasSuccessful())
testutils.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def skip_if_windows(reason):
    """Decorator to skip tests that should not be run on windows.

    Example usage:

        @skip_if_windows("Not valid")
        def test_some_non_windows_stuff(self):
            self.assertEqual(...)

    """
    def decorator(func):
        return unittest.skipIf(
            platform.system() not in ['Darwin', 'Linux'], reason)(func)
    return decorator
backports.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
testing.py 文件源码 项目:My-Web-Server-Framework-With-Python2.7 作者: syjsu 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testing.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testing.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
backports.py 文件源码 项目:Sudoku-Solver 作者: ayush1997 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
testing.py 文件源码 项目:teleport 作者: eomsoft 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testing.py 文件源码 项目:projects-2017-2 作者: ncss 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
backports.py 文件源码 项目:enkiWS 作者: juliettef 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
__init__.py 文件源码 项目:s3transfer 作者: boto 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def skip_if_windows(reason):
    """Decorator to skip tests that should not be run on windows.

    Example usage:

        @skip_if_windows("Not valid")
        def test_some_non_windows_stuff(self):
            self.assertEqual(...)

    """
    def decorator(func):
        return unittest.skipIf(
            platform.system() not in ['Darwin', 'Linux'], reason)(func)
    return decorator
__init__.py 文件源码 项目:s3transfer 作者: boto 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def skip_if_using_serial_implementation(reason):
    """Decorator to skip tests when running as the serial implementation"""
    def decorator(func):
        return unittest.skipIf(
            is_serial_implementation(), reason)(func)
    return decorator
backports.py 文件源码 项目:python-flask-security 作者: weinbergdavid 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
test_csgo.py 文件源码 项目:BigBrotherBot-For-UrT43 作者: ptitbigorneau 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_saybig_with_color_codes(self):
        self.parser.msgPrefix = "[Pre]"
        with patch.object(self.parser.output, 'write') as write_mock:
            self.parser.saybig("^7message ^1with ^2color ^8codes")
            write_mock.assert_has_calls([call('sm_hsay [Pre] message with color codes')])

#    @unittest.skipIf(WAS_FROSTBITE_LOADED, "Frostbite(1|2) parsers monkey patch the Client class and make this test fail")
testing.py 文件源码 项目:PyQYT 作者: collinsctk 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
unknown_fields_test.py 文件源码 项目:googleURLParser 作者: randomaccess3 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func)
test_lib_reader.py 文件源码 项目:OpenDoor 作者: stanislav-web 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_total_lines(self):
        """ Reader.total_lines test """

        empty_reader = Reader(browser_config={})
        self.assertIs(type(empty_reader.total_lines), int)

    # def test_randomize_list_exception(self):
    #     """ Reader.randomize_list exception test """
    #
    #     reader = Reader(browser_config={})
    #     setattr(reader, '_Reader__config', self.__configuration_for_exception)
    #     setattr(sys, '_Output__is_windows', False)
    #     with self.assertRaises(ReaderError) as context:
    #         reader.randomize_list('directories', 'tmplist')
    #         self.assertTrue(ReaderError == context.expected)
    #
    # @unittest.skipIf(True is sys().is_windows, "Skip test for windows")
    # def test_randomize_list_unix(self):
    #     """ Reader.randomize_list unix test """
    #
    #     reader = Reader(browser_config={
    #         'is_external_wordlist': True,
    #         'list': 'tests/data/directories.dat',
    #     })
    #     setattr(reader, '_Reader__config', self.__configuration)
    #     reader.count_total_lines()
    #     self.assertIsNone(reader.randomize_list('directories', 'tmplist'))
    #     fe = open('tests/data/directories.dat', 'r')
    #     fa = open('tests/tmp/list.tmp', 'r')
    #     expected = sum(1 for l in fe)
    #     actual = sum(1 for l in fa)
    #     self.assertIs(expected, actual)
    #
    # def test_randomize_list_windows(self):
    #     """ Reader.randomize_list windows test """
    #
    #     reader = Reader(browser_config={
    #         'is_external_wordlist': True,
    #         'list': 'tests/data/directories.dat',
    #     })
    #     setattr(reader, '_Reader__config', self.__configuration)
    #     setattr(sys, 'is_windows', True)
    #     reader.count_total_lines()
    #     self.assertIsNone(reader.randomize_list('directories', 'tmplist'))
    #     fe = open('tests/data/directories.dat', 'r')
    #     fa = open('tests/tmp/list.tmp', 'r')
    #     expected = sum(1 for l in fe)
    #     actual = sum(1 for l in fa)
    #     self.assertIs(expected, actual)


问题


面经


文章

微信
公众号

扫码关注公众号