def setUp(self):
     self.sink = df.Sink()
     self.file_name1 = os.path.join(data_dir5, 'short.dat')
     f1 = open(self.file_name1, 'wb')
     try:
         f1.write('one two three four five six')
     finally:
         f1.close()
Beispiel #2
0
    def test_caps_phrase(self):
        words_in_caps1 = ppln_demo.WordsInCaps(factory=self.factory)
        sink = df.Sink()
        words_in_caps1.next_filter = sink
        words_in_caps1.send(dfb.DataPacket('hello world'))
        self.assertEquals(sink.results, [])
        ##        output1 = words_in_caps1.pump_data('hello world')
        ##        self.assertEquals(output1, [])
        ##        words_in_caps1.shut_down()  # Flush joining data
        ##        words_in_caps1.shut_down()  # Flush joining data
        words_in_caps1.first_filter.shut_down()
        self.assertEquals(sink.results[-1].data, 'Hello~World')

        words_in_caps2 = ppln_demo.WordsInCaps(factory=self.factory,
                                               join_words_with='+')
        sink2 = df.Sink()
        words_in_caps2.next_filter = sink2
        words_in_caps2.send(dfb.DataPacket('one    two three   four five'))
        ##        words_in_caps2.shut_down()
        words_in_caps2.first_filter.shut_down()
        self.assertEquals(sink2.results[-1].data, 'One+Two+Three+Four+Five')
 def test_extract_many_attributes_split_words(self):
     data_in = """
     TIME CHIP SERIAL IS: 5ABF3. OTHER VALUE IS: 312. SOME TRAILING TEXT
     """
     extractor = ppln.ExtractManyAttributesSplitWords(\
         factory=self.factory, split_on_str=". ", attr_delim='col')
     extractor_filter = extractor.getf('attribute_extractor')
     sink = df.Sink()
     extractor_filter.next_filter = sink
     extractor.send(dfb.DataPacket(data_in))
     #TEST PACKET NOT FILTER
     self.assertEqual(sink.results[0].time_chip_serial_is, '5ABF3')
     self.assertEqual(sink.results[1].other_value_is, '312')
Beispiel #4
0
 def pump_data(self, data_in=None, zero_inputs=True):  # << TO-DO Needs work
     ##, close_at_end=True):
     """Put the data into the pipeline by wrapping it in a Datapacket.
        Get the data out by temporarily sticking a Sink on the end,
        returning all the packets received.
        Remember to close the pipeline externally, if tidying up actions 
        need to be performed.
        
        
        If zero_inputs is True, reinitialise the variables before pumping 
        the new data in.  <<<<<<<zero_inputs<<<<<<<<< TO-DO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     """
     pump_sink = df.Sink()
     self.last_filter.next_filter = pump_sink
     print '**10195** Connect (%s, pump_data) %s >>> %s' % (
         self.name, self.last_filter.name, pump_sink.name)
     try:
         data_in + []  # TO-DO: Better way to check the data type
     except TypeError:  # Not a list
         data_in = [data_in]
     for data in data_in:
         if data is None:
             ##                packet = None
             packet = dfb.DataPacket(None)  # Or ''??
         else:
             packet = dfb.DataPacket(str(data))
         if fut.debug > 1:  #pragma: nocover
             print '**3698**', 65 * '='
             if fut.debug > 2:  #pragma: nocover
                 show_data = '|'.join(fut.split_strings(str(data), 8))
                 print '**3705** data_in   = "%s"' % (
                     fut.data_to_hex_string(show_data[:80]))
         self.first_filter.send(packet)
     ##if close_at_end:
     ##self.first_filter.shut_down()
     # All data has arrived, so disconnect sink
     self.last_filter.next_filter = None
     # Store the full results packets in self.results in case they are
     # needed, returning the packet.data as a list.
     self.results = pump_sink.results
     # TO-DO: Decide about which data type here -- strings or lists
     ##        return pump_sink.results[-1].data
     if len(self.results) == 1:
         return self.results[0].data
     else:
         return [pkt.data for pkt in self.results]
    def test_extract_many_attributes(self):
        data_in = """
        person's name=Postman pat
        age=500000
        
        gender=mail
        
        
        hair col0ur=balding
        """

        extractor = ppln.ExtractManyAttributes(factory=self.factory,
                                               attr_delim='equals')
        extractor_filter = extractor.getf('attribute_extractor')
        sink = df.Sink()
        extractor_filter.next_filter = sink
        extractor.send(dfb.DataPacket(data_in))
        #TEST PACKET NOT FILTER
        self.assertEqual(sink.results[0].persons_name, 'Postman pat')
        self.assertEqual(sink.results[1].age, '500000')
        self.assertEqual(sink.results[2].gender, 'mail')
        self.assertEqual(sink.results[3].hair_col0ur, 'balding')
 def setUp(self):
     self.hidden_branch_filter = dfb.HiddenBranchRoute()
     self.sink_main = df.Sink()
     self.hidden_branch_filter.next_filter = self.sink_main
     self.sink_branch = df.Sink()
     self.hidden_branch_filter.branch_filter = self.sink_branch
 def setUp(self):
     self.factory = ff.DemoFilterFactory()
     self.sink = df.Sink()
 def setUp(self):
     self.caps = dfd.Capitalise()
     # Ready to check output
     self.sink = df.Sink()
     # Connect filters
     self.caps.next_filter = self.sink
 def setUp(self):
     self.add_numbers = dfd.AddNumbers()
     # Ready to check output
     self.sink = df.Sink()
     # Connect filters
     self.add_numbers.next_filter = self.sink