本文整理汇总了Python中vistrails.tests.utils.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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]])
示例2: 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]])
示例3: test_train_test_split
def test_train_test_split(self):
# check that we can split the iris dataset
with intercept_results(TrainTestSplit, 'training_data', TrainTestSplit,
'training_target', TrainTestSplit, 'test_data',
TrainTestSplit, 'test_target') as results:
X_train, y_train, X_test, y_test = results
self.assertFalse(execute(
[
('datasets|Iris', identifier, []),
('cross-validation|TrainTestSplit', identifier,
[('test_size', [('Integer', '50')])])
],
[
(0, 'data', 1, 'data'),
(0, 'target', 1, 'target')
]
))
X_train = np.vstack(X_train)
X_test = np.vstack(X_test)
y_train = np.hstack(y_train)
y_test = np.hstack(y_test)
self.assertEqual(X_train.shape, (100, 4))
self.assertEqual(X_test.shape, (50, 4))
self.assertEqual(y_train.shape, (100,))
self.assertEqual(y_test.shape, (50,))
示例4: 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]])
示例5: 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])
示例6: test_pipeline
def test_pipeline(self):
with intercept_results(Iris, 'target', Predict, 'prediction') as (y_true, y_pred):
self.assertFalse(execute(
[
('datasets|Iris', identifier, []),
('preprocessing|StandardScaler', identifier, []),
('feature_selection|SelectKBest', identifier,
[('k', [('Integer', '2')])]),
('classifiers|LinearSVC', identifier, []),
('Pipeline', identifier, []),
('Predict', identifier, [])
],
[
# feed data to pipeline
(0, 'data', 4, 'training_data'),
(0, 'target', 4, 'training_target'),
# put models in pipeline
(1, 'model', 4, 'model1'),
(2, 'model', 4, 'model2'),
(3, 'model', 4, 'model3'),
# predict using pipeline
(4, 'model', 5, 'model'),
(0, 'data', 5, 'data')
]
))
y_true, y_pred = np.array(y_true[0]), np.array(y_pred[0])
self.assertEqual(y_true.shape, y_pred.shape)
self.assertTrue(np.mean(y_true == y_pred) > .8)
示例7: 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"])
示例8: 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])
示例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)]
)
),
)
示例10: 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]])
示例11: 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'])
示例12: 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!!!"])
示例13: testIncorrectURL
def testIncorrectURL(self):
from vistrails.tests.utils import execute
self.assertTrue(execute([
('DownloadFile', identifier, [
('url', [('String', 'http://idbetthisdoesnotexistohrly')]),
]),
]))
示例14: 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 "],
)
示例15: do_if
def do_if(self, val):
with intercept_result(If, 'Result') as results:
interp_dict = execute([
('If', 'org.vistrails.vistrails.control_flow', [
('FalseOutputPorts', [('List', "['value']")]),
('TrueOutputPorts', [('List', "['value']")]),
('Condition', [('Boolean', str(val))]),
]),
('Integer', 'org.vistrails.vistrails.basic', [
('value', [('Integer', '42')]),
]),
('Integer', 'org.vistrails.vistrails.basic', [
('value', [('Integer', '28')]),
]),
],
[
(1, 'self', 0, 'TruePort'),
(2, 'self', 0, 'FalsePort'),
],
full_results=True)
self.assertFalse(interp_dict.errors)
if val:
self.assertEqual(results, [42])
else:
self.assertEqual(results, [28])
self.assertEqual(interp_dict.executed, {0: True, 1: val, 2: not val})