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

Python utils.intercept_result函数代码示例

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

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



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

示例1: test_xls_header_numeric

 def test_xls_header_numeric(self):
     """Uses ExcelSpreadsheet to load a numeric array.
     """
     with intercept_result(ExtractColumn, "value") as results:
         with intercept_result(ExcelSpreadsheet, "column_count") as cols:
             self.assertFalse(
                 execute(
                     [
                         (
                             "read|ExcelSpreadsheet",
                             identifier,
                             [
                                 ("file", [("File", self._test_dir + "/xl.xls")]),
                                 # Will default to first sheet
                                 ("header_present", [("Boolean", "True")]),
                             ],
                         ),
                         (
                             "ExtractColumn",
                             identifier,
                             [("column_name", [("String", "data2")]), ("numeric", [("Boolean", "True")])],
                         ),
                     ],
                     [(0, "self", 1, "table")],
                 )
             )
     self.assertEqual(cols, [2])
     self.assertEqual(len(results), 1)
     self.assertAlmostEqual_lists(list(results[0]), [1, -2.8, 3.4, 3.3])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:29,代码来源:read_excel.py


示例2: test_csv_numeric

 def test_csv_numeric(self):
     """Uses CSVFile and ExtractColumn to load a numeric array.
     """
     with intercept_result(ExtractColumn, 'value') as results:
         with intercept_result(CSVFile, 'column_count') as columns:
             self.assertFalse(execute([
                     ('read|CSVFile', identifier, [
                         ('file', [('File', self._test_dir + '/test.csv')]),
                     ]),
                     ('ExtractColumn', identifier, [
                         ('column_index', [('Integer', '1')]),
                         ('column_name', [('String', 'col 2')]),
                         ('numeric', [('Boolean', 'True')]),
                     ]),
                     ('PythonSource', 'org.vistrails.vistrails.basic', [
                         ('source', [('String', '')]),
                     ]),
                 ],
                 [
                     (0, 'value', 1, 'table'),
                     (1, 'value', 2, 'l'),
                 ],
                 add_port_specs=[
                     (2, 'input', 'l',
                      'org.vistrails.vistrails.basic:List'),
                 ]))
             # Here we use a PythonSource just to check that a numpy array
             # can be passed on a List port
     self.assertEqual(columns, [3])
     self.assertEqual(len(results), 1)
     self.assertEqual(list(results[0]), [2.0, 3.0, 14.5])
开发者ID:AnyarInc,项目名称:VisTrails,代码行数:31,代码来源:read_csv.py


示例3: test_xls_header_nonnumeric

 def test_xls_header_nonnumeric(self):
     """Uses ExcelSpreadsheet to load data.
     """
     with intercept_result(ExtractColumn, "value") as results:
         with intercept_result(ExcelSpreadsheet, "column_count") as cols:
             self.assertFalse(
                 execute(
                     [
                         (
                             "read|ExcelSpreadsheet",
                             identifier,
                             [
                                 ("file", [("File", self._test_dir + "/xl.xls")]),
                                 ("sheet_name", [("String", "Feuil1")]),
                                 ("header_present", [("Boolean", "True")]),
                             ],
                         ),
                         (
                             "ExtractColumn",
                             identifier,
                             [
                                 ("column_index", [("Integer", "0")]),
                                 ("column_name", [("String", "data1")]),
                                 ("numeric", [("Boolean", "False")]),
                             ],
                         ),
                     ],
                     [(0, "self", 1, "table")],
                 )
             )
     self.assertEqual(cols, [2])
     self.assertEqual(len(results), 1)
     self.assertEqual(list(results[0]), ["here", "is", "some", "text"])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:33,代码来源:read_excel.py


示例4: test_xls_numeric

 def test_xls_numeric(self):
     """Uses ExcelSpreadsheet to load a numeric array.
     """
     with intercept_result(ExtractColumn, "value") as results:
         with intercept_result(ExcelSpreadsheet, "column_count") as cols:
             self.assertFalse(
                 execute(
                     [
                         (
                             "read|ExcelSpreadsheet",
                             identifier,
                             [
                                 ("file", [("File", self._test_dir + "/xl.xls")]),
                                 ("sheet_index", [("Integer", "1")]),
                                 ("sheet_name", [("String", "Feuil2")]),
                                 ("header_present", [("Boolean", "False")]),
                             ],
                         ),
                         (
                             "ExtractColumn",
                             identifier,
                             [("column_index", [("Integer", "0")]), ("numeric", [("Boolean", "True")])],
                         ),
                     ],
                     [(0, "self", 1, "table")],
                 )
             )
     self.assertEqual(cols, [1])
     self.assertEqual(len(results), 1)
     self.assertAlmostEqual_lists(list(results[0]), [1, 2, 2, 3, -7.6])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:30,代码来源:read_excel.py


示例5: test_filter

 def test_filter(self):
     src = urllib2.quote("o = bool(i)")
     with intercept_result(Filter, "Result") as results:
         self.assertFalse(
             execute(
                 [
                     ("PythonSource", "org.vistrails.vistrails.basic", [("source", [("String", src)])]),
                     (
                         "Filter",
                         "org.vistrails.vistrails.control_flow",
                         [
                             ("InputPort", [("List", "['i']")]),
                             ("OutputPort", [("String", "o")]),
                             ("InputList", [("List", "[0, 1, 2, 3, '', 'foo', True, False]")]),
                         ],
                     ),
                 ],
                 [(0, "self", 1, "FunctionPort")],
                 add_port_specs=[
                     (0, "input", "i", "org.vistrails.vistrails.basic:Module"),
                     (0, "output", "o", "org.vistrails.vistrails.basic:Boolean"),
                 ],
             )
         )
     self.assertEqual(results, [[1, 2, 3, "foo", True]])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:25,代码来源:utils.py


示例6: test_multiple

 def test_multiple(self):
     src = urllib2.quote("o = i + j")
     with intercept_result(Map, "Result") as results:
         self.assertFalse(
             execute(
                 [
                     ("PythonSource", "org.vistrails.vistrails.basic", [("source", [("String", src)])]),
                     (
                         "Map",
                         "org.vistrails.vistrails.control_flow",
                         [
                             ("InputPort", [("List", "['i', 'j']")]),
                             ("OutputPort", [("String", "o")]),
                             ("InputList", [("List", "[(1, 2), (3, 8), (-2, 3)]")]),
                         ],
                     ),
                 ],
                 [(0, "self", 1, "FunctionPort")],
                 add_port_specs=[
                     (0, "input", "i", "org.vistrails.vistrails.basic:Integer"),
                     (0, "input", "j", "org.vistrails.vistrails.basic:Integer"),
                     (0, "output", "o", "org.vistrails.vistrails.basic:Integer"),
                 ],
             )
         )
     self.assertEqual(results, [[3, 11, 1]])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:26,代码来源:utils.py


示例7: test_tuple

 def test_tuple(self):
     src = urllib2.quote("o = len(i[0]) + i[1]")
     with intercept_result(Map, "Result") as results:
         self.assertFalse(
             execute(
                 [
                     ("PythonSource", "org.vistrails.vistrails.basic", [("source", [("String", src)])]),
                     (
                         "Map",
                         "org.vistrails.vistrails.control_flow",
                         [
                             ("InputPort", [("List", "['i']")]),
                             ("OutputPort", [("String", "o")]),
                             ("InputList", [("List", '[("aa", 1), ("", 8), ("a", 4)]')]),
                         ],
                     ),
                 ],
                 [(0, "self", 1, "FunctionPort")],
                 add_port_specs=[
                     (0, "input", "i", "org.vistrails.vistrails.basic:String,org.vistrails.vistrails.basic:Integer"),
                     (0, "output", "o", "org.vistrails.vistrails.basic:Float"),
                 ],
             )
         )
     self.assertEqual(results, [[3, 8, 5]])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:25,代码来源:utils.py


示例8: test_simple

 def test_simple(self):
     src = urllib2.quote("o = i + 1")
     with intercept_result(Map, "Result") as results:
         self.assertFalse(
             execute(
                 [
                     ("PythonSource", "org.vistrails.vistrails.basic", [("source", [("String", src)])]),
                     (
                         "Map",
                         "org.vistrails.vistrails.control_flow",
                         [
                             ("InputPort", [("List", "['i']")]),
                             ("OutputPort", [("String", "o")]),
                             ("InputList", [("List", "[1, 2, 8, 9.1]")]),
                         ],
                     ),
                 ],
                 [(0, "self", 1, "FunctionPort")],
                 add_port_specs=[
                     (0, "input", "i", "org.vistrails.vistrails.basic:Float"),
                     (0, "output", "o", "org.vistrails.vistrails.basic:Float"),
                 ],
             )
         )
     self.assertEqual(results, [[2, 3, 9, 10.1]])
开发者ID:pombredanne,项目名称:VisTrails,代码行数:25,代码来源:utils.py


示例9: test_simple

    def test_simple(self):
        """Test converting timestamps into matplotlib's format.
        """
        try:
            import matplotlib
        except ImportError:  # pragma: no cover
            self.skipTest("matplotlib is not available")

        from matplotlib.dates import date2num

        with intercept_result(TimestampsToMatplotlib, "dates") as results:
            self.assertFalse(
                execute(
                    [
                        (
                            "convert|dates|TimestampsToMatplotlib",
                            identifier,
                            [("timestamps", [("List", "[1324842375, 1369842877]")])],
                        )
                    ]
                )
            )
        self.assertEqual(len(results), 1)
        results = results[0]
        self.assertEqual(
            list(results),
            list(
                date2num(
                    [datetime.datetime.utcfromtimestamp(1324842375), datetime.datetime.utcfromtimestamp(1369842877)]
                )
            ),
        )
开发者ID:remram44,项目名称:tabledata-backport,代码行数:32,代码来源:convert_dates.py


示例10: do_andor

 def do_andor(self, l):
     with intercept_result(And, "Result") as and_results:
         with intercept_result(Or, "Result") as or_results:
             self.assertFalse(
                 execute(
                     [
                         ("List", "org.vistrails.vistrails.basic", [("value", [("List", str(l))])]),
                         ("And", "org.vistrails.vistrails.control_flow", []),
                         ("Or", "org.vistrails.vistrails.control_flow", []),
                     ],
                     [(0, "value", 1, "InputList"), (0, "value", 2, "InputList")],
                 )
             )
     self.assertEqual(len(and_results), 1)
     self.assertEqual(len(or_results), 1)
     return and_results[0], or_results[0]
开发者ID:pombredanne,项目名称:VisTrails,代码行数:16,代码来源:utils.py


示例11: test_pythonsource

 def test_pythonsource(self):
     import urllib2
     source = ('o = i * 2\n'
               "r = \"it's %d!!!\" % o\n"
               'go_on = o < 100')
     source = urllib2.quote(source)
     from vistrails.tests.utils import execute, intercept_result
     with intercept_result(While, 'Result') as results:
         self.assertFalse(execute([
                 ('PythonSource', 'org.vistrails.vistrails.basic', [
                     ('source', [('String', source)]),
                     ('i', [('Integer', '5')]),
                 ]),
                 ('While', 'org.vistrails.vistrails.control_flow', [
                     ('ConditionPort', [('String', 'go_on')]),
                     ('OutputPort', [('String', 'r')]),
                     ('StateInputPorts', [('List', "['i']")]),
                     ('StateOutputPorts', [('List', "['o']")]),
                 ]),
             ],
             [
                 (0, 'self', 1, 'FunctionPort'),
             ],
             add_port_specs=[
                 (0, 'input', 'i',
                  'org.vistrails.vistrails.basic:Integer'),
                 (0, 'output', 'o',
                  'org.vistrails.vistrails.basic:Integer'),
                 (0, 'output', 'r',
                  'org.vistrails.vistrails.basic:String'),
                 (0, 'output', 'go_on',
                  'org.vistrails.vistrails.basic:Boolean'),
             ]))
     self.assertEqual(results, ["it's 160!!!"])
开发者ID:Nikea,项目名称:VisTrails,代码行数:34,代码来源:looping.py


示例12: test_dateutil

    def test_dateutil(self):
        """Test reading non-timezone-aware dates without providing the format.

        dateutil is required for this one.
        """
        try:
            import dateutil
        except ImportError:  # pragma: no cover
            self.skipTest("dateutil is not available")

        dates = [
            "2013-05-20 9:25",
            "Thu Sep 25 10:36:26 2003",
            "2003 10:36:28 CET 25 Sep Thu",
        ]  # Timezone will be ignored
        with intercept_result(StringsToDates, "dates") as results:
            self.assertFalse(
                execute([("convert|dates|StringsToDates", identifier, [("strings", [("List", repr(dates))])])])
            )
        self.assertEqual(len(results), 1)
        results = results[0]
        fmt = "%Y-%m-%d %H:%M:%S %Z %z"
        self.assertEqual(
            [d.strftime(fmt) for d in results],
            ["2013-05-20 09:25:00  ", "2003-09-25 10:36:26  ", "2003-09-25 10:36:28  "],
        )
开发者ID:remram44,项目名称:tabledata-backport,代码行数:26,代码来源:convert_dates.py


示例13: do_aggregate

 def do_aggregate(self, agg_functions):
     with intercept_result(AggregateColumn, 'value') as results:
         errors = execute([
                 ('WriteFile', 'org.vistrails.vistrails.basic', [
                     ('in_value', [('String', '22;a;T;100\n'
                                              '43;b;F;3\n'
                                              '-7;d;T;41\n'
                                              '500;e;F;21\n'
                                              '20;a;T;1\n'
                                              '43;b;F;23\n'
                                              '21;a;F;41\n')]),
                 ]),
                 ('read|CSVFile', identifier, [
                     ('delimiter', [('String', ';')]),
                     ('header_present', [('Boolean', 'False')]),
                     ('sniff_header', [('Boolean', 'False')]),
                 ]),
                 ('AggregateColumn', identifier, agg_functions),
             ],
             [
                 (0, 'out_value', 1, 'file'),
                 (1, 'value', 2, 'table'),
             ])
     self.assertFalse(errors)
     self.assertEqual(len(results), 1)
     return results[0]
开发者ID:Nikea,项目名称:VisTrails,代码行数:26,代码来源:operations.py


示例14: do_project

 def do_project(self, project_functions, error=None):
     with intercept_result(ProjectTable, 'value') as results:
         errors = execute([
                 ('BuildTable', identifier, [
                     ('letters', [('List', repr(['a', 'b', 'c', 'd']))]),
                     ('numbers', [('List', repr([1, 2, 3, '4']))]),
                     ('cardinals', [('List', repr(['one', 'two',
                                                   'three', 'four']))]),
                     ('ordinals', [('List', repr(['first', 'second',
                                                  'third', 'fourth']))])
                 ]),
                 ('ProjectTable', identifier, project_functions),
             ],
             [
                 (0, 'value', 1, 'table'),
             ],
             add_port_specs=[
                 (0, 'input', 'letters',
                  'org.vistrails.vistrails.basic:List'),
                 (0, 'input', 'numbers',
                  'org.vistrails.vistrails.basic:List'),
                 (0, 'input', 'cardinals',
                  'org.vistrails.vistrails.basic:List'),
                 (0, 'input', 'ordinals',
                  'org.vistrails.vistrails.basic:List'),
             ])
     if error is not None:
         self.assertEqual([1], errors.keys())
         self.assertIn(error, errors[1].message)
         return None
     else:
         self.assertFalse(errors)
         self.assertEqual(len(results), 1)
         return results[0]
开发者ID:Nikea,项目名称:VisTrails,代码行数:34,代码来源:operations.py


示例15: do_select

 def do_select(self, select_functions, error=None):
     with intercept_result(SelectFromTable, 'value') as results:
         errors = execute([
                 ('WriteFile', 'org.vistrails.vistrails.basic', [
                     ('in_value', [('String', '22;a;T;abaab\n'
                                              '43;b;F;aabab\n'
                                              '-7;d;T;abbababb\n'
                                              '500;e;F;aba abacc')]),
                 ]),
                 ('read|CSVFile', identifier, [
                     ('delimiter', [('String', ';')]),
                     ('header_present', [('Boolean', 'False')]),
                     ('sniff_header', [('Boolean', 'False')]),
                 ]),
                 ('SelectFromTable', identifier, select_functions),
             ],
             [
                 (0, 'out_value', 1, 'file'),
                 (1, 'value', 2, 'table'),
             ])
     if error is not None:
         self.assertEqual([2], errors.keys())
         self.assertIn(error, errors[2].message)
         return None
     else:
         self.assertFalse(errors)
         self.assertEqual(len(results), 1)
         return results[0]
开发者ID:Nikea,项目名称:VisTrails,代码行数:28,代码来源:operations.py


示例16: do_default

 def do_default(self, val):
     if val:
         src = 'o = 42'
     else:
         src = ('from vistrails.core.modules.vistrails_module import '
                'InvalidOutput\n'
                'o = InvalidOutput')
     src = urllib2.quote(src)
     with intercept_result(Default, 'Result') as results:
         self.assertFalse(execute([
                 ('Default', 'org.vistrails.vistrails.control_flow', [
                     ('Default', [('Integer', '28')]),
                 ]),
                 ('PythonSource', 'org.vistrails.vistrails.basic', [
                     ('source', [('String', src)]),
                 ]),
             ],
             [
                 (1, 'o', 0, 'Input'),
             ],
             add_port_specs=[
                 (1, 'output', 'o',
                  'org.vistrails.vistrails.basic:Integer'),
             ]))
     if val:
         self.assertEqual(results, [42])
     else:
         self.assertEqual(results, [28])
开发者ID:AnyarInc,项目名称:VisTrails,代码行数:28,代码来源:conditional.py


示例17: test_strings

 def test_strings(self):
     from vistrails.tests.utils import execute, intercept_result
     from ..common import ExtractColumn
     from ..identifiers import identifier
     with intercept_result(ExtractColumn, 'value') as results:
         self.assertFalse(execute([
                 ('BuildTable', identifier, [
                     ('a', [('List', "['a', '2', 'c']")]),
                     ('b', [('List', "[4, 5, 6]")]),
                 ]),
                 (self.WRITER_MODULE, identifier, []),
                 (self.READER_MODULE, identifier, []),
                 ('ExtractColumn', identifier, [
                     ('column_index', [('Integer', '0')]),
                     ('numeric', [('Boolean', 'False')]),
                 ]),
             ], [
                 (0, 'value', 1, 'table'),
                 (1, 'file', 2, 'file'),
                 (2, 'value', 3, 'table'),
             ],
             add_port_specs=[
                 (0, 'input', 'a',
                  '(org.vistrails.vistrails.basic:List)'),
                 (0, 'input', 'b',
                  '(org.vistrails.vistrails.basic:List)'),
             ]))
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0], ['a', '2', 'c'])
开发者ID:remram44,项目名称:tabledata-backport,代码行数:29,代码来源:__init__.py


示例18: test_npy_numpy

    def test_npy_numpy(self):
        """Uses NumPyArray to load an array in .NPY format.
        """
        from ..identifiers import identifier
        from vistrails.tests.utils import execute, intercept_result

        with intercept_result(NumPyArray, 'value') as results:
            self.assertFalse(execute([
                    ('read|numpy|NumPyArray', identifier, [
                        ('datatype', [('String', 'npy')]),
                        ('file', [('File', self._test_dir + '/random.npy')]),
                    ]),
                    ('PythonSource', 'org.vistrails.vistrails.basic', [
                        ('source', [('String', '')]),
                    ]),
                ],
                [
                    (0, 'value', 1, 'l'),
                ],
                add_port_specs=[
                    (1, 'input', 'l',
                     'org.vistrails.vistrails.basic:List'),
                ]))
        self.assertEqual(len(results), 1)
        self.assertEqual(list(results[0]), [1.0, 7.0, 5.0, 3.0, 6.0, 1.0])
开发者ID:lumig242,项目名称:VisTrailsRecommendation,代码行数:25,代码来源:read_numpy.py


示例19: test_timezone

 def test_timezone(self):
     """Test reading timezone-aware dates by supplying an offset.
     """
     dates = ["2013-05-20 9:25", "2013-05-20 09:31", "2013-01-02 19:05"]
     in_fmt = "%Y-%m-%d %H:%M"
     with intercept_result(StringsToDates, "dates") as results:
         self.assertFalse(
             execute(
                 [
                     (
                         "convert|dates|StringsToDates",
                         identifier,
                         [
                             ("strings", [("List", repr(dates))]),
                             ("format", [("String", in_fmt)]),
                             ("timezone", [("String", "-0500")]),
                         ],
                     )
                 ]
             )
         )
     self.assertEqual(len(results), 1)
     results = results[0]
     self.assertTrue(all(d.tzinfo is not None for d in results))
     fmt = "%Y-%m-%d %H:%M:%S %z"
     self.assertEqual(
         [d.strftime(fmt) for d in results],
         ["2013-05-20 09:25:00 -0500", "2013-05-20 09:31:00 -0500", "2013-01-02 19:05:00 -0500"],
     )
开发者ID:remram44,项目名称:tabledata-backport,代码行数:29,代码来源:convert_dates.py


示例20: test_multiple

 def test_multiple(self):
     src = urllib2.quote('o = i + j')
     with intercept_result(Map, 'Result') as results:
         self.assertFalse(execute([
                 ('PythonSource', 'org.vistrails.vistrails.basic', [
                     ('source', [('String', src)]),
                 ]),
                 ('Map', 'org.vistrails.vistrails.control_flow', [
                     ('InputPort', [('List', "['i', 'j']")]),
                     ('OutputPort', [('String', 'o')]),
                     ('InputList', [('List',
                         '[(1, 2), (3, 8), (-2, 3)]')]),
                 ]),
             ],
             [
                 (0, 'self', 1, 'FunctionPort'),
             ],
             add_port_specs=[
                 (0, 'input', 'i',
                  'org.vistrails.vistrails.basic:Integer'),
                 (0, 'input', 'j',
                  'org.vistrails.vistrails.basic:Integer'),
                 (0, 'output', 'o',
                  'org.vistrails.vistrails.basic:Integer'),
             ]))
     self.assertEqual(results, [[3, 11, 1]])
开发者ID:AnyarInc,项目名称:VisTrails,代码行数:26,代码来源:utils.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python visual.arrow函数代码示例发布时间:2022-05-26
下一篇:
Python utils.execute函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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