Ejemplo n.º 1
0
    def test_max_count(self):
        cm = ContentMatcher('line', max_match_count=1)
        self.assertMatches(cm, text1, [(1, [(5, 9)])])

        cm = ContentMatcher('line', max_match_count=2)
        self.assertMatches(cm, text1, [(1, [(5, 9)]), (2, [(8, 12)])])

        cm = ContentMatcher('a', max_match_count=1)
        self.assertMatches(cm, text1, [(2, [(0, 1)])])
Ejemplo n.º 2
0
    def test_whole_words(self):
        cm = ContentMatcher('pie', whole_words=True)
        self.assertMatches(cm, text2, [(2, [(6, 9), (19, 22)]),
                                       (4, [(24, 27)])])

        cm = ContentMatcher('.*n', literal_pattern=True)
        self.assertMatches(cm, text2, [(4, [(5, 8)])])

        cm = ContentMatcher(r'$\k', literal_pattern=True)
        self.assertMatches(cm, text2, [(3, [(10, 13)])])

        cm = ContentMatcher(r'$\k', literal_pattern=False)
        self.assertMatches(cm, text2, [])
Ejemplo n.º 3
0
    def test_defaults(self):
        cm = ContentMatcher('line')
        self.assertMatches(cm, text1, [(1, [(5, 9)]), (2, [(8, 12)]),
                                       (3, [(9, 13), (24, 28)]),
                                       (6, [(9, 13)]),
                                       (7, [(5, 9), (15, 19), (35, 39)])])

        cm = ContentMatcher('Line')
        self.assertMatches(cm, text1, [(5, [(10, 14)])])

        cm = ContentMatcher('L[ix]ne')
        self.assertMatches(cm, text1, [(5, [(10, 14)])])

        cm = ContentMatcher('upper')
        self.assertMatches(cm, text1, [])
Ejemplo n.º 4
0
    def test_invert_match(self):
        cm = ContentMatcher('line', invert_match=True)
        self.assertMatches(cm, text1, [(4, []), (5, [])])

        cm = ContentMatcher('line', invert_match=True, ignore_case=True)
        self.assertMatches(cm, text1, [(4, [])])
Ejemplo n.º 5
0
 def test_ignore_case(self):
     cm = ContentMatcher('upper', ignore_case=True)
     self.assertMatches(cm, text1, [(5, [(0, 5)])])
Ejemplo n.º 6
0
 def num_matches(self, pattern, text, **kwargs):
     """ Number of matching lines for the pattern in the text. kwargs are
         passed to ContentMatcher.
     """
     cm = ContentMatcher(pattern, **kwargs)
     return len(list(cm.match_file(StringIO(text))))
Ejemplo n.º 7
0
#!/usr/bin/env python

import sys

from psslib.defaultpssoutputformatter import DefaultPssOutputFormatter
from psslib.matchresult import MatchResult
from psslib.contentmatcher import ContentMatcher
from psslib.driver import pss_run
from psslib.utils import istextfile

with open('psslib/__pycache__/outputformatter.cpython-33.pyc', 'rb') as f:
    print istextfile(f)
    f.seek(0)

    cm = ContentMatcher('imp')
    matches = cm.match_file(f)
    print(list(matches))