Python six 模块,assertRegex() 实例源码

我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用six.assertRegex()

项目:girder_worker    作者:girder    | 项目源码 | 文件源码
def testCleanupHook(self, mockPopen):
        os.makedirs(_tmp)
        girder_worker.config.set('docker', 'gc', 'True')
        girder_worker.config.set('docker', 'cache_timeout', '123456')
        girder_worker.config.set('docker', 'exclude_images', 'test/test:latest')

        # Make sure docker-gc is called during cleanup
        cleanup.main()

        self.assertEqual(mockPopen.call_count, 1)
        cmd = [x[1]['args'] for x in mockPopen.call_args_list][0]

        six.assertRegex(self, cmd[0], 'docker-gc$')
        env = mockPopen.call_args_list[0][1]['env']
        self.assertEqual(env['GRACE_PERIOD_SECONDS'], '123456')
        six.assertRegex(self, env['EXCLUDE_FROM_GC'], r'\.docker-gc-exclude$')
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_print_report(self):
        hook = memory_hooks.LineProfileHook()
        p = self.pool.malloc(1000)
        del p
        with hook:
            p1 = self.pool.malloc(1000)
            p2 = self.pool.malloc(2000)
        del p1
        del p2
        io = six.StringIO()
        hook.print_report(file=io)
        actual = io.getvalue()
        expect = r'\A_root \(3\.00KB, 2\.00KB\)'
        six.assertRegex(self, actual, expect)
        expect = r'.*\.py:[0-9]+:test_print_report \(1\.00KB, 0\.00B\)'
        six.assertRegex(self, actual, expect)
        expect = r'.*\.py:[0-9]+:test_print_report \(2\.00KB, 2\.00KB\)'
        six.assertRegex(self, actual, expect)
项目:gthnk    作者:iandennismiller    | 项目源码 | 文件源码
def test_nearest(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/admin/journal/refresh', follow_redirects=True)

            rv = c.get('/admin/journal/nearest/2012-10-03', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "load exact date")

            rv = c.get('/admin/journal/nearest/2012-09-01', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "request earlier date")

            rv = c.get('/admin/journal/nearest/2012-10-10', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "request later date")
项目:gthnk    作者:iandennismiller    | 项目源码 | 文件源码
def test_search(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/admin/journal/refresh', follow_redirects=True)

            rv = c.get('admin/journal/search?q={q}'.format(q="graduate"), follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03',
                "search for a findable string finds something")

            rv = c.get('admin/journal/search?q={q}'.format(q="zorkle"), follow_redirects=True)
            if six.PY2:
                self.assertNotRegexpMatches(rv.data, r'2012-10-03',
                    "search for a unfindable string finds nothing")
            elif six.PY3:
                self.assertNotRegex(str(rv.data), r'2012-10-03',
                    "search for a unfindable string finds nothing")
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test()
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_black_scholes(self):
        output = example_test.run_example(
            'finance/black_scholes.py', '--n-options', '10')
        six.assertRegex(
            self, output.decode('utf-8'),
            r'initializing...\n' +
            r'start computation\n' +
            r' CPU \(NumPy, Naive implementation\):\t[0-9\.]+ sec\n' +
            r' GPU \(CuPy, Naive implementation\):\t[0-9\.]+ sec\n' +
            r' GPU \(CuPy, Elementwise kernel\):\t[0-9\.]+ sec')
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_monte_carlo(self):
        output = example_test.run_example(
            'finance/monte_carlo.py', '--n-options', '10',
            '--n-samples-per-thread', '10',
            '--n-threads-per-option', '10')
        six.assertRegex(
            self, output.decode('utf-8'),
            r'initializing...\n' +
            r'start computation\n' +
            r'    # of options: 10\n' +
            r'    # of samples per option: 100\n' +
            r'GPU \(CuPy, Monte Carlo method\):\t[0-9\.]+ sec\n' +
            r'Error: [0-9\.]+')
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_monte_carlo_multigpu(self):
        output = example_test.run_example(
            'finance/monte_carlo_multigpu.py', '--gpus', '0', '1',
            '--n-options', '10',
            '--n-samples-per-thread', '10',
            '--n-threads-per-option', '10')
        six.assertRegex(
            self, output.decode('utf-8'),
            r'initializing...\n' +
            r'start computation\n' +
            r'    # of gpus: 2\n' +
            r'    # of options: 10\n' +
            r'    # of samples per option: 200\n' +
            r'GPU \(CuPy, Monte Carlo method\):\t[0-9\.]+ sec\n' +
            r'Error: [0-9\.]+')
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_default(self):
        output = example_test.run_example(
            'kmeans/kmeans.py', '-m', '1', '--num', '10')
        six.assertRegex(
            self, output.decode('utf-8'),
            r' CPU :  [0-9\.]+ sec\s+GPU :  [0-9\.]+ sec')
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_custom_kernel(self):
        output = example_test.run_example(
            'kmeans/kmeans.py', '-m', '1', '--num', '10',
            '--use-custom-kernel')
        six.assertRegex(
            self, output.decode('utf-8'),
            r' CPU :  [0-9\.]+ sec\s+GPU :  [0-9\.]+ sec')
项目:gthnk    作者:iandennismiller    | 项目源码 | 文件源码
def test_refresh(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
                sess['_fresh'] = True
            rv = c.get('/', follow_redirects=True)
            rv = c.get('/admin/journal/refresh', follow_redirects=True)
            rv = c.get('/admin/journal/day/2012-10-03.html', follow_redirects=True)
            six.assertRegex(self, str(rv.data),
                r'graduate management consulting association',
                "journal was loaded")
项目:gthnk    作者:iandennismiller    | 项目源码 | 文件源码
def test_latest(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/admin/journal/refresh', follow_redirects=True)

            rv = c.get('/admin/journal/latest.html', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "request latest.html")
项目:gthnk    作者:iandennismiller    | 项目源码 | 文件源码
def test_representations(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/admin/journal/refresh', follow_redirects=True)

            rv = c.get('/admin/journal/day/2012-10-03.html', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "get day as HTML")
            rv = c.get('/admin/journal/day/2012-10-02.html', follow_redirects=True)
            if six.PY2:
                self.assertNotRegexpMatches(rv.data, r'2012-10-03',
                    "get non-existent day as HTML")
            elif six.PY3:
                self.assertNotRegex(str(rv.data), r'2012-10-03',
                    "get non-existent day as HTML")

            rv = c.get('/admin/journal/text/2012-10-03.txt', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "get day as text")
            rv = c.get('/admin/journal/text/2012-10-02.txt', follow_redirects=True)
            if six.PY2:
                self.assertNotRegexpMatches(rv.data, r'2012-10-03',
                    "get non-existent day as text")
            elif six.PY3:
                self.assertNotRegex(str(rv.data), r'2012-10-03',
                    "get non-existent day as text")

            rv = c.get('/admin/journal/markdown/2012-10-03.md', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03', "get day as markdown")
            rv = c.get('/admin/journal/markdown/2012-10-02.md', follow_redirects=True)
            if six.PY2:
                self.assertNotRegexpMatches(rv.data, r'2012-10-03',
                    "get non-existent day as markdown")
            elif six.PY3:
                self.assertNotRegex(str(rv.data), r'2012-10-03',
                    "get non-existent day as markdown")

            rv = c.get('/admin/journal/download/2012-10-03.pdf', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'PDF', "get day as PDF")
            self.assertEqual(len(rv.data), 306, "size match on download")
项目:gthnk    作者:iandennismiller    | 项目源码 | 文件源码
def test_bypass_login(self):
        create_user()
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
                sess['_fresh'] = True
            rv = c.get('/', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'logout', "response contains text 'logout'")
项目:obsoleted-vpduserv    作者:InfraSIM    | 项目源码 | 文件源码
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test()
项目:azure-cli    作者:Azure    | 项目源码 | 文件源码
def test_search_index(self):
        six.assertRegex(
            self,
            execute('find -q keyvault list'),
            'az keyvault list')
项目:azure-cli    作者:Azure    | 项目源码 | 文件源码
def test_search_reindex(self):
        six.assertRegex(
            self,
            execute('find -q keyvault list --reindex'),
            'az keyvault list')
项目:data-migrator    作者:schubergphilis    | 项目源码 | 文件源码
def test_basic(self):
        m = DefaultModel()
        self.assertIsNone(m.a)
        self.assertEqual(m.b, 0)
        self.assertEqual(m.c, None)
        self.assertEqual(m.d, '')
        self.assertEqual(m.e, None)
        self.assertEqual(m.f, False)
        self.assertIsNone(m.g)
        six.assertRegex(self, m.h, u'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
        self.assertEqual(m.i, None)
        self.assertEqual(m.j, None)
项目:data-migrator    作者:schubergphilis    | 项目源码 | 文件源码
def test_init(self):
        m = DefaultModel(a="bla", b=2, c=None, d="d", e=None, f=True, g="bla", h="uuid", i=["json"], j="M")
        self.assertEqual(m.a, "bla")
        self.assertEqual(m.b, 2)
        self.assertEqual(m.c, None)
        self.assertEqual(m.d, 'd')
        self.assertEqual(m.e, None)
        self.assertEqual(m.f, False)
        self.assertIsNone(m.g)
        six.assertRegex(self, m.h, u'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
        self.assertEqual(m.i, ["json"])
        self.assertEqual(m.j, "M")
项目:six    作者:benjaminp    | 项目源码 | 文件源码
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test()