Beispiel #1
0
    def testReplacements(self):
        """ test replacing using collection of replacements """
        c = QgsStringReplacementCollection()
        c.setReplacements([
            QgsStringReplacement('aa', '11'),
            QgsStringReplacement('bb', '22')
        ])
        self.assertEqual(c.process('here aa bb is aa string bb'),
                         'here 11 22 is 11 string 22')
        self.assertEqual(c.process('no matches'), 'no matches')
        self.assertEqual(c.process(''), '')

        # test replacements are done in order
        c.setReplacements([
            QgsStringReplacement('aa', '11'),
            QgsStringReplacement('11', '22')
        ])
        self.assertEqual(c.process('string aa'), 'string 22')
        # no replacements
        c.setReplacements([])
        self.assertEqual(c.process('string aa'), 'string aa')
Beispiel #2
0
    def testBasic(self):
        """ basic tests for QgsStringReplacement"""
        r = QgsStringReplacement('match', 'replace')
        self.assertEqual(r.match(), 'match')
        self.assertEqual(r.replacement(), 'replace')

        r = QgsStringReplacement('match', 'replace', True, True)
        self.assertTrue(r.wholeWordOnly())
        self.assertTrue(r.caseSensitive())
Beispiel #3
0
 def testSaveRestore(self):
     """ test saving/restoring replacement to map"""
     r1 = QgsStringReplacement('a', 'b', True, True)
     props = r1.properties()
     r2 = QgsStringReplacement.fromProperties(props)
     self.assertEqual(r1, r2)
     r1 = QgsStringReplacement('a', 'b', False, False)
     props = r1.properties()
     r2 = QgsStringReplacement.fromProperties(props)
     self.assertEqual(r1, r2)
Beispiel #4
0
 def testEquality(self):
     """ test equality operator"""
     r1 = QgsStringReplacement('a', 'b', True, True)
     r2 = QgsStringReplacement('a', 'b', True, True)
     self.assertEqual(r1, r2)
     r2 = QgsStringReplacement('c', 'b')
     self.assertNotEqual(r1, r2)
     r2 = QgsStringReplacement('a', 'c')
     self.assertNotEqual(r1, r2)
     r2 = QgsStringReplacement('a', 'b', False, True)
     self.assertNotEqual(r1, r2)
     r2 = QgsStringReplacement('c', 'b', True, False)
     self.assertNotEqual(r1, r2)
Beispiel #5
0
    def testReplace(self):
        """ test applying replacements"""

        # case insensitive
        r = QgsStringReplacement('match', 'replace', False, False)
        self.assertEqual(r.process('one MaTch only'), 'one replace only')
        self.assertEqual(r.process('more then one MaTch here match two'),
                         'more then one replace here replace two')
        self.assertEqual(r.process('match start and end MaTch'),
                         'replace start and end replace')
        self.assertEqual(r.process('no hits'), 'no hits')
        self.assertEqual(r.process('some exmatches here'),
                         'some exreplacees here')
        self.assertEqual(r.process(''), '')

        # case sensitive
        r = QgsStringReplacement('match', 'replace', True, False)
        self.assertEqual(r.process('one MaTch only'), 'one MaTch only')
        self.assertEqual(r.process('one match only'), 'one replace only')

        # whole word only, case insensitive
        r = QgsStringReplacement('match', 'replace', False, True)
        self.assertEqual(r.process('some exmatches here'),
                         'some exmatches here')
        self.assertEqual(r.process('some match here'), 'some replace here')
        self.assertEqual(r.process('some exmatches MaTch here'),
                         'some exmatches replace here')
        self.assertEqual(r.process('some match maTCh here'),
                         'some replace replace here')
        self.assertEqual(r.process('some -match. here'), 'some -replace. here')
        self.assertEqual(r.process('match here'), 'replace here')
        self.assertEqual(r.process('some match'), 'some replace')

        # whole word only, case sensitive
        r = QgsStringReplacement('match', 'replace', True, True)
        self.assertEqual(r.process('some exmatches here'),
                         'some exmatches here')
        self.assertEqual(r.process('some match here'), 'some replace here')
        self.assertEqual(r.process('some exmatches MaTch here'),
                         'some exmatches MaTch here')
        self.assertEqual(r.process('some match maTCh here'),
                         'some replace maTCh here')
Beispiel #6
0
    def testReplace(self):
        """ test applying replacements"""

        # case insensitive
        r = QgsStringReplacement('match', 'replace', False, False)
        self.assertEqual(r.process('one MaTch only'), 'one replace only')
        self.assertEqual(r.process('more then one MaTch here match two'), 'more then one replace here replace two')
        self.assertEqual(r.process('match start and end MaTch'), 'replace start and end replace')
        self.assertEqual(r.process('no hits'), 'no hits')
        self.assertEqual(r.process('some exmatches here'), 'some exreplacees here')
        self.assertEqual(r.process(''), '')

        # case sensitive
        r = QgsStringReplacement('match', 'replace', True, False)
        self.assertEqual(r.process('one MaTch only'), 'one MaTch only')
        self.assertEqual(r.process('one match only'), 'one replace only')

        # whole word only, case insensitive
        r = QgsStringReplacement('match', 'replace', False, True)
        self.assertEqual(r.process('some exmatches here'), 'some exmatches here')
        self.assertEqual(r.process('some match here'), 'some replace here')
        self.assertEqual(r.process('some exmatches MaTch here'), 'some exmatches replace here')
        self.assertEqual(r.process('some match maTCh here'), 'some replace replace here')
        self.assertEqual(r.process('some -match. here'), 'some -replace. here')
        self.assertEqual(r.process('match here'), 'replace here')
        self.assertEqual(r.process('some match'), 'some replace')

        # whole word only, case sensitive
        r = QgsStringReplacement('match', 'replace', True, True)
        self.assertEqual(r.process('some exmatches here'), 'some exmatches here')
        self.assertEqual(r.process('some match here'), 'some replace here')
        self.assertEqual(r.process('some exmatches MaTch here'), 'some exmatches MaTch here')
        self.assertEqual(r.process('some match maTCh here'), 'some replace maTCh here')
Beispiel #7
0
 def testBasic(self):
     """ basic QgsStringReplacementCollection tests"""
     list = [QgsStringReplacement('aa', '11'),
             QgsStringReplacement('bb', '22')]
     c = QgsStringReplacementCollection(list)
     self.assertEqual(c.replacements(), list)