def format_scenario_name(name): return fn.thread([ str.replace(name, "Should ", ""), lambda x: x[0].upper() + x[1:], F(flip(str.split), '--'), fn.first, str.strip])
def format_scenario_name(name): return fn.thread([ string.replace(name, "Should ", ""), lambda x: x[0].upper() + x[1:], F(flip(string.split), '--'), fn.first, string.strip])
def run(argv): opts = util.parse_docopt(__doc__, argv, False) biobox = opts['<biobox_type>'] image = opts['<image>'] task = opts['--task'] verbose = opts['--verbose'] log = opts['--log'] if not behave.features_available(biobox): error.err_exit("unknown_command", {"command_type" : "biobox type", "command" : biobox}) ctn.exit_if_no_image_available(image) if verbose: results = behave.run(biobox, image, task, False) else: results = behave.run(biobox, image, task) if verbose: if log: sys.stdout = open(log, "w+") statuses = fn.thread([ behave.get_scenarios_and_statuses(results), F(map, name_and_status)]) longest_name = fn.thread([ statuses, F(map, fn.first), F(map, len), max]) def justify(x, y): return string.ljust(x, longest_name, ' '), y output = fn.thread([ statuses, F(map, justify), F(map, F(flip(string.join), " ")), fn.unique, F(flip(string.join), "\n")]) print(output) elif behave.is_failed(results): if log: sys.stderr = open(log, "w+") msg = fn.thread([ behave.get_failing_scenarios(results), F(map, behave.scenario_name), F(flip(string.join), "\n")]) error.err_exit('failed_verification', {'image': image, 'error': msg, 'biobox' : biobox})
def run(argv): opts = util.parse_docopt(__doc__, argv, False) biobox = opts['<biobox_type>'] image = opts['<image>'] task = opts['--task'] verbose = opts['--verbose'] log = opts['--log'] if not behave.features_available(biobox): error.err_exit("unknown_command", {"command_type" : "biobox type", "command" : biobox}) ctn.exit_if_no_image_available(image) if verbose: results = behave.run(biobox, image, task, False) else: results = behave.run(biobox, image, task) if verbose: if log: sys.stdout = open(log, "w+") statuses = fn.thread([ behave.get_scenarios_and_statuses(results), F(map, lambda (x, y): (format_scenario_name(x), format_scenario_status(y)))]) longest_name = fn.thread([ statuses, F(map, fn.first), F(map, len), max]) output = fn.thread([ statuses, F(map, lambda (x, y): (string.ljust(x, longest_name, ' '), y)), F(map, F(flip(string.join), " ")), fn.unique, F(flip(string.join), "\n")]) print output elif behave.is_failed(results): if log: sys.stderr = open(log, "w+") msg = fn.thread([ behave.get_failing_scenarios(results), F(map, behave.scenario_name), F(flip(string.join), "\n")]) error.err_exit('failed_verification', {'image': image, 'error': msg, 'biobox' : biobox})
def handle_eval(metric, pred_path, truth_path): preds = _load(pred_path, atof) split = F(flip(str.split), '\t') with open(truth_path, 'r') as fin: truths = tuple((int(i), int(j)) for i, j in imap(split, fin)) result = { 'polarity': polarity_accuracy, 'kendall': kendall_tau }[metric](preds, truths) print result
def _load_edges(path): wrap = F(flip(str.split), '\t') >> (lambda xs: cn.wrap_edge(*xs)) return _load(path, wrap)
def test_flip_with_shortcut(self): self.assertEqual(10, op.flip(_ - _)(2, 12))
def test_flip(self): self.assertEqual(10, op.flip(operator.sub)(2, 12)) self.assertEqual(-10, op.flip(op.flip(operator.sub))(2, 12)) # flipping of flipped function should use optimization self.assertTrue(operator.sub is op.flip(op.flip(operator.sub)))
def double_evens2(xs): return doubles(filter(F(eq, 0) << F(flip(mod), 2), xs))
def double_evens2(xs): return doubles(filter(F(eq, 0) << F(flip(mod), 2), xs)) def even(x): return x % 2 == 0 def flip1(f): return lambda x, y: f(y, x) falsify("flip1", lambda x, y: flip1(sub)(y, x) == sub(x, y), int, int) even1 = F(flip(mod), 2) >> F(eq, 0) def double_evens3(xs): return doubles(filter(even1, xs)) double_evens4 = F(filter, even1) >> doubles falsify("double_evens vs double_evens1", lambda xs: list(double_evens(xs)) == list(double_evens1(xs)), [int]) falsify("double_evens1 vs double_evens2", lambda xs: list(double_evens1(xs)) == list(double_evens2(xs)), [int]) falsify("double_evens2 vs double_evens3", lambda xs: list(double_evens2(xs)) == list(double_evens3(xs)), [int]) falsify("double_evens3 vs double_evens4", lambda xs: list(double_evens3(xs)) == list(double_evens4(xs)), [int])
# # # print(list(map(f,[0,1,2]))) # # # # print(list(map(F()<<str<<(_**2)<<(_+1),range(3)))) # func = F()>>(filter,_<6)>>sum # # print(func(range(10))) # # print(apply(add, [1, 2])) print(flip(sub)(20, 10)) # print((sub)(20,10)) # folder = op.foldl(_*_,1) # folder = op.foldl(_*_,1) # # print(op.foldl(_+_)([1,2,3])) # # print(folder([1,2,3])) # # print(foldr(call,0)([lambda x:x**2,lambda y:y+10])) # # print(foldr(call,10)([lambda x:x**2,lambda y:y+10]))