def runTest(self): # This docstring will show up in nosetests -v and python # test_bla.py -v output. The metaclass above replaces this empty # string in subclasses of CoroutineTest with the docstring from # the subclass. "." s = Sink() sink_gen = prime(s()) # The thing assigned to coroutine_under_test was a callable of # some sort. But somewhere along the line, it's made into an # instancemethod, so that when it's called, the self parameter # is prepended to the argument list. But we don't want that # here: we're just trying to store a callable in self and get it # back out later, no special behavior. So pull the func back out # of the instancemethod and use that. # # But if the callable was not a function, it won't have been # packaged into an instancemethod. For example, it may have been # an instance of a class having a __call__ method. if hasattr(self.coroutine_under_test, 'im_func'): coro = self.coroutine_under_test.im_func else: coro = self.coroutine_under_test send_into = prime(coro(sink_gen)) for thing in self.preprocess_send(): send_into.send(thing) send_into.close() self.assertEqual(s.values, list(self.preprocess_expect()))
def summon_file_for_iac(iac): f = file(os.path.join(directory_name, iac), 'w') print >> f, "\\section{%s: %s}" % (iac, iac_titles[iac]) print >> f, "\\label{iac-%s}" % iac return prime(pipe( LatexEmitter(iac), prime(lines_to_file(f)(None))))
def testThreeMemberPipe(self): s = Sink() sg = prime(s()) p = prime(pipe(add(1), mul(3), sg)) p.send(4) # add(1) happens first -> 5 # then mul(3) -> 15 self.assertEqual(s.values, [15])
def do_puppet_files(self): go = push_lines_from_files(*self.puppet_files) input_stage = splitmerge( identity, lambda t: pipe(sort_comments, invert_comments, t)) label_stage = lambda t: pipe( splitmerge(identity, labels_for_files(self.nToStrip), labels_for_modules(self.nToStrip)), buffer_labels_till_first_latex_line, autoindex, t) add_written_reqs = splitmerge(find_implements, find_doneby, find_bydefault, identity) do_policy_output = lambda t: pipe(drop_tagged('line'), LatexEmitter('policy'), lines_to_file(self.policy_output), t) per_iac_output = lambda t: pipe( # grab both implements (from upstream) and paragraphs splitmerge(identity, paragraphs), splitmerge(puppet_labels_for_per_iac(self.nToStrip), identity), tag_iac_paragraphs, self.write_iac_files_pipe_entry, t) master = pipe( splitmerge( identity, lambda t: pipe(take_tagged('new_file'), log('reading', logging.DEBUG), null, t)), input_stage, label_stage, add_written_reqs, self.add_all_indirect_iacs, splitmerge(self.write_exec_summary_splitmerge_entry, per_iac_output, do_policy_output), lambda t: null(t)) go(prime(master))
def do_latex_files(self): go = push_lines_from_files(*self.latex_files) master = pipe( splitmerge(identity, lines_to_toplevel), splitmerge(latex_labels_for_per_iac, identity), splitmerge( lambda t: pipe(neutralize_verb_tag, splitmerge(find_implements, find_doneby), t), identity), self.add_all_indirect_iacs, splitmerge(identity, paragraphs), tag_iac_paragraphs, self.write_the_iac_files) go(prime(master))
def prepare(self): self.log.debug('There are %d LaTeX files', len(self.latex_files)) self.log.debug('There are %d Puppet files', len(self.puppet_files)) self.write_the_iac_files = prime( latex_to_files_in(self.per_iac_output_dir, ia_controls.names)(None)) # since the latex_to_files_in doesn't emit messages, it doesn't matter # what comes after it in the pipe; but pipe expects to call something # with one argument self.write_iac_files_pipe_entry = lambda t: self.write_the_iac_files self.write_exec_summary = prime( pipe(executive_summary(ia_controls.names), LatexEmitter('exec_summary'), lines_to_file(self.exec_summary_output), None)) self.write_exec_summary_splitmerge_entry = \ lambda t: self.write_exec_summary find_each_indirect_iacs = [ find_ia_control_tags( name, meaning, ia_controls.for_system_profile[meaning.profile_id]) for (name, meaning) in self.checklists.items() ] self.add_all_indirect_iacs = splitmerge(*(find_each_indirect_iacs + [identity]))
def testSink(self): s = Sink() g = prime(s()) g.send(('foo', 'bar')) self.assertEqual(s.values, [('foo', 'bar')])
def testTwoMemberPipe(self): s = Sink() sg = prime(s()) p = prime(pipe(add(1), sg)) p.send(3) self.assertEqual(s.values, [4])
def testOneMemberPipe(self): s = Sink() # pipe will call s() to get generator object p = prime(pipe(s)) p.send(3) self.assertEqual(s.values, [3])