• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.safeeval函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mrjob.util.safeeval函数的典型用法代码示例。如果您正苦于以下问题:Python safeeval函数的具体用法?Python safeeval怎么用?Python safeeval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_range_type

    def test_range_type(self):
        # ranges have different reprs on Python 2 vs. Python 3, and
        # can't be checked for equality until Python 3.3+

        if PY2:
            range_type = xrange
        else:
            range_type = range

        self.assertEqual(repr(safeeval(repr(range_type(3)))), repr(range_type(3)))

        if sys.version_info >= (3, 3):
            self.assertEqual(safeeval(repr(range_type(3))), range_type(3))
开发者ID:tempcyc,项目名称:mrjob,代码行数:13,代码来源:test_util.py


示例2: test_end_to_end

    def test_end_to_end(self):
        script_path = spark_wordcount_script.__file__
        if script_path.endswith('.pyc'):
            script_path = script_path[:-1]

        input_path = self.makefile(
            'input', b'one fish\ntwo fish\nred fish\nblue fish\n')

        # don't create this path, let Spark do it
        output_path = join(self.tmp_dir, 'output')
        self.assertFalse(exists(output_path))

        spark_submit_main(
            ['-r', 'local', script_path, input_path, output_path])

        self.assertTrue(exists(output_path))

        word_counts = {}

        for path in glob(join(output_path, 'part-*')):
            with open(path) as f:
                for line in f:
                    word, count = safeeval(line)
                    word_counts[word] = count

        self.assertEqual(word_counts,
                         dict(blue=1, fish=4, one=1, red=1, two=1))
开发者ID:Yelp,项目名称:mrjob,代码行数:27,代码来源:test_spark_submit.py


示例3: test_spark_mrjob

    def test_spark_mrjob(self):
        text = b'one fish\ntwo fish\nred fish\nblue fish\n'

        job = MRSparkWordcount(['-r', 'inline'])
        job.sandbox(stdin=BytesIO(text))

        counts = {}

        with job.make_runner() as runner:
            runner.run()

            for line in to_lines(runner.cat_output()):
                k, v = safeeval(line)
                counts[k] = v

        self.assertEqual(counts, dict(
            blue=1, fish=4, one=1, red=1, two=1))
开发者ID:Yelp,项目名称:mrjob,代码行数:17,代码来源:test_inline.py


示例4: test_copy_files_with_rename_to_local_wd_mirror

    def test_copy_files_with_rename_to_local_wd_mirror(self):
        # see test_upload_files_with_rename() in test_local for comparison

        fish_path = self.makefile('fish', b'salmon')
        fowl_path = self.makefile('fowl', b'goose')

        # use _LOCAL_CLUSTER_MASTER because the default master (local[*])
        # doesn't have a working directory
        job = MRSparkOSWalk(['-r', 'spark',
                             '--spark-master', _LOCAL_CLUSTER_MASTER,
                             '--file', fish_path + '#ghoti',
                             '--file', fowl_path])
        job.sandbox()

        file_sizes = {}

        with job.make_runner() as runner:
            runner.run()

            # check working dir mirror
            wd_mirror = runner._wd_mirror()
            self.assertIsNotNone(wd_mirror)
            self.assertFalse(is_uri(wd_mirror))

            self.assertTrue(exists(wd_mirror))
            # only files which needed to be renamed should be in wd_mirror
            self.assertTrue(exists(join(wd_mirror, 'ghoti')))
            self.assertFalse(exists(join(wd_mirror, 'fish')))
            self.assertFalse(exists(join(wd_mirror, 'fowl')))

            for line in to_lines(runner.cat_output()):
                path, size = safeeval(line)
                file_sizes[path] = size

        # check that files were uploaded to working dir
        self.assertIn('fowl', file_sizes)
        self.assertEqual(file_sizes['fowl'], 5)

        self.assertIn('ghoti', file_sizes)
        self.assertEqual(file_sizes['ghoti'], 6)

        # fish was uploaded as "ghoti"
        self.assertNotIn('fish', file_sizes)
开发者ID:Yelp,项目名称:mrjob,代码行数:43,代码来源:test_runner.py


示例5: test_upload_files_with_rename

    def test_upload_files_with_rename(self):
        fish_path = self.makefile('fish', b'salmon')
        fowl_path = self.makefile('fowl', b'goose')

        job = MRSparkOSWalk(['-r', 'local',
                             '--file', fish_path + '#ghoti',
                             '--file', fowl_path])
        job.sandbox()

        file_sizes = {}

        with job.make_runner() as runner:
            runner.run()

            # check working dir mirror
            wd_mirror = runner._wd_mirror()
            self.assertIsNotNone(wd_mirror)
            self.assertFalse(is_uri(wd_mirror))

            self.assertTrue(os.path.exists(wd_mirror))
            # only files which needed to be renamed should be in wd_mirror
            self.assertTrue(os.path.exists(os.path.join(wd_mirror, 'ghoti')))
            self.assertFalse(os.path.exists(os.path.join(wd_mirror, 'fish')))
            self.assertFalse(os.path.exists(os.path.join(wd_mirror, 'fowl')))

            for line in to_lines(runner.cat_output()):
                path, size = safeeval(line)
                file_sizes[path] = size

        # check that files were uploaded to working dir
        self.assertIn('fowl', file_sizes)
        self.assertEqual(file_sizes['fowl'], 5)

        self.assertIn('ghoti', file_sizes)
        self.assertEqual(file_sizes['ghoti'], 6)

        # fish was uploaded as "ghoti"
        self.assertNotIn('fish', file_sizes)
开发者ID:Yelp,项目名称:mrjob,代码行数:38,代码来源:test_local.py


示例6: test_upload_files_with_rename

    def test_upload_files_with_rename(self):
        # see test_upload_files_with_rename() in test_local for comparison

        fish_path = self.makefile('fish', b'salmon')
        fowl_path = self.makefile('fowl', b'goose')

        # --use-driver-cwd gets around issues with the shared JVM not changing
        # executors' working directory to match the driver on local master
        job = MRSparkOSWalk(['-r', 'inline',
                             '--use-driver-cwd',
                             '--file', fish_path + '#ghoti',
                             '--file', fowl_path])
        job.sandbox()

        file_sizes = {}

        with job.make_runner() as runner:
            runner.run()

            # there is no working dir mirror in inline mode; inline
            # mode simulates the working dir itself
            wd_mirror = runner._wd_mirror()
            self.assertIsNone(wd_mirror)

            for line in to_lines(runner.cat_output()):
                path, size = safeeval(line)
                file_sizes[path] = size

        # check that files were uploaded to working dir
        self.assertIn('fowl', file_sizes)
        self.assertEqual(file_sizes['fowl'], 5)

        self.assertIn('ghoti', file_sizes)
        self.assertEqual(file_sizes['ghoti'], 6)

        # fish was uploaded as "ghoti"
        self.assertNotIn('fish', file_sizes)
开发者ID:Yelp,项目名称:mrjob,代码行数:37,代码来源:test_inline.py


示例7: read

 def read(cls, line):
     return (None, safeeval(line))
开发者ID:ndimiduk,项目名称:mrjob,代码行数:2,代码来源:protocol.py


示例8: load_from_string

 def load_from_string(cls, value):
     return safeeval(value)
开发者ID:ndimiduk,项目名称:mrjob,代码行数:2,代码来源:protocol.py


示例9: read

 def read(cls, line):
     key, value = line.split('\t')
     return safeeval(key), safeeval(value)
开发者ID:atiw003,项目名称:mrjob,代码行数:3,代码来源:protocol.py


示例10: read

 def read(self, line):
     return (None, safeeval(line))
开发者ID:Jeremyfanfan,项目名称:mrjob,代码行数:2,代码来源:protocol.py


示例11: _loads

 def _loads(self, value):
     return safeeval(value)
开发者ID:Jeremyfanfan,项目名称:mrjob,代码行数:2,代码来源:protocol.py


示例12: test_globals_and_locals

 def test_globals_and_locals(self):
     # test passing in globals, locals
     a = -0.2
     self.assertEqual(
         abs(a),
         safeeval('abs(a)', globals={'abs': abs}, locals={'a': a}))
开发者ID:anirudhreddy92,项目名称:mrjob,代码行数:6,代码来源:test_util.py


示例13: test_simple_data_structures

 def test_simple_data_structures(self):
     # try unrepr-ing a bunch of simple data structures
     for x in True, None, 1, [0, 1, 2, 3, 4], {'foo': False, 'bar': 2}:
         self.assertEqual(x, safeeval(repr(x)))
开发者ID:anirudhreddy92,项目名称:mrjob,代码行数:4,代码来源:test_util.py


示例14: test_simple_data_structure

 def test_simple_data_structure(self):
     # try unrepr-ing a bunch of simple data structures
     for x in True, None, 1, range(5), {'foo': False, 'bar': 2}:
         assert_equal(x, safeeval(repr(x)))
开发者ID:gimlids,项目名称:LTPM,代码行数:4,代码来源:util_test.py


示例15: test_globals_and_locals

 def test_globals_and_locals(self):
     # test passing in globals, locals
     a = -0.2
     self.assertEqual(abs(a), safeeval("abs(a)", globals={"abs": abs}, locals={"a": a}))
开发者ID:bchess,项目名称:mrjob,代码行数:4,代码来源:test_util.py


示例16: test_simple_data_structure

 def test_simple_data_structure(self):
     # try unrepr-ing a bunch of simple data structures
     for x in True, None, 1, range(5), {"foo": False, "bar": 2}:
         self.assertEqual(x, safeeval(repr(x)))
开发者ID:bchess,项目名称:mrjob,代码行数:4,代码来源:test_util.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.scrape_options_into_new_groups函数代码示例发布时间:2022-05-27
下一篇:
Python util.read_input函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap