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


Python utils.intercept_result函数代码示例

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


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


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