Beispiel #1
0
 def test_basics( self ):
     
     splitter = ClientParsing.StringSplitter( separator = ', ' )
     
     self.assertTrue( splitter.Split( '123' ), [ '123' ] )
     self.assertTrue( splitter.Split( '1,2,3' ), [ '1,2,3' ] )
     self.assertTrue( splitter.Split( '1, 2, 3' ), [ '1', '2', '3' ] )
     
     splitter = ClientParsing.StringSplitter( separator = ', ', max_splits = 2 )
     
     self.assertTrue( splitter.Split( '123' ), [ '123' ] )
     self.assertTrue( splitter.Split( '1,2,3' ), [ '1,2,3' ] )
     self.assertTrue( splitter.Split( '1, 2, 3, 4' ), [ '1', '2', '3,4' ] )
Beispiel #2
0
    def test_hex_fail(self):

        processor = ClientParsing.StringProcessor()

        conversions = [(ClientParsing.STRING_CONVERSION_DECODE, 'hex')]

        string_converter = ClientParsing.StringConverter(
            conversions=conversions)

        #

        processing_steps = []

        processing_steps.append(string_converter)

        processing_steps.append(
            ClientParsing.StringMatch(
                match_type=ClientParsing.STRING_MATCH_FLEXIBLE,
                match_value=ClientParsing.NUMERIC))

        processor.SetProcessingSteps(processing_steps)

        self.assertEqual(processor.ProcessStrings(['0123456789abcdef']), [])

        #

        processing_steps = []

        processing_steps.append(string_converter)

        processing_steps.append(ClientParsing.StringSplitter(separator=','))

        processor.SetProcessingSteps(processing_steps)

        self.assertEqual(processor.ProcessStrings(['0123456789abcdef']), [])
Beispiel #3
0
    def test_basics(self):

        processor = ClientParsing.StringProcessor()

        self.assertEqual(processor.ProcessStrings([]), [])
        self.assertEqual(processor.ProcessStrings(['test']), ['test'])
        self.assertEqual(
            processor.ProcessStrings(['test', 'test', '', 'test2']),
            ['test', 'test', '', 'test2'])

        processing_steps = []

        processing_steps.append(
            ClientParsing.StringSplitter(separator=',', max_splits=2))

        processing_steps.append(
            ClientParsing.StringMatch(
                match_type=ClientParsing.STRING_MATCH_FLEXIBLE,
                match_value=ClientParsing.NUMERIC))

        conversions = [(ClientParsing.STRING_CONVERSION_APPEND_TEXT, 'abc')]

        processing_steps.append(
            ClientParsing.StringConverter(conversions=conversions))

        processor.SetProcessingSteps(processing_steps)

        expected_result = ['1abc', '123abc']

        self.assertEqual(processor.ProcessStrings(['1,a,2,3', 'test', '123']),
                         expected_result)