def testUnresolvable(self): fileLine = ".../something/foo.py" result = parse.matchLine(fileLine) lineObj = format.LineMatch(fileLine, result, 0) self.assertTrue(not lineObj.isResolvable(), '"%s" should not be resolvable' % fileLine) print('Tested unresolvable case.')
def testResolvable(self): toCheck = [case for case in fileTestCases if case['match']] for testCase in toCheck: result = parse.matchLine(testCase['input']) lineObj = format.LineMatch(testCase['input'], result, 0) self.assertTrue(lineObj.isResolvable(), 'Line "%s" was not resolvable' % testCase['input']) print('Tested %d resolvable cases.' % len(toCheck)) def testFileMatch(self): for testCase in fileTestCases: self.checkFileResult(testCase) print('Tested %d cases.' % len(fileTestCases)) def checkFileResult(self, testCase): result = parse.matchLine(testCase['input']) if not result: self.assertFalse( testCase['match'], 'Line "%s" did not match any regex' % testCase['input']) return file, num, match = result self.assertTrue(testCase['match'], 'Line "%s" did match' % testCase['input']) self.assertEqual( testCase['file'], file, 'files not equal |%s| |%s|' % (testCase['file'], file)) self.assertEqual( testCase['num'], num, 'num matches not equal %d %d for %s' % (testCase['num'], num, testCase.get('input')))
def getLineObjsFromLines(inputLines, validateFileExists=True, allInput=False): lineObjs = {} for index, line in enumerate(inputLines): line = line.replace('\t', ' ') # remove the new line as we place the cursor ourselves for each # line. this avoids curses errors when we newline past the end of the # screen line = line.replace('\n', '') formattedLine = FormattedText(line) result = parse.matchLine(str(formattedLine), validateFileExists=validateFileExists, allInput=allInput) if not result: line = format.SimpleLine(formattedLine, index) else: line = format.LineMatch(formattedLine, result, index, validateFileExists=validateFileExists, allInput=allInput) lineObjs[index] = line return lineObjs
def testResolvable(self): toCheck = [case for case in fileTestCases if case['match']] for testCase in toCheck: result = parse.matchLine(testCase['input']) lineObj = format.LineMatch(testCase['input'], result, 0) self.assertTrue( lineObj.is_resolvable, 'Line "%s" was not resolvable' % testCase['input'] ) print('Tested %d resolvable cases.' % len(toCheck)) def testFileMatch(self): for testCase in fileTestCases: self.checkFileResult(testCase) print('Tested %d cases.' % len(fileTestCases)) def checkFileResult(self, testCase): result = parse.matchLine(testCase['input']) if not result: self.assertFalse(testCase['match'], 'Line "%s" did not match any regex' % testCase['input']) return file, num, match = result self.assertTrue(testCase['match'], 'Line "%s" did match' % testCase['input']) self.assertEqual(testCase['file'], file, 'files not equal |%s| |%s|' % (testCase['file'], file)) self.assertEqual(testCase['num'], num, 'num matches not equal %d %d for %s' % (testCase['num'], num, testCase.get('input'))) def test_ignore_curse_errors_no_exception(self): """ Check that if no exception is raised, the result is still the same. """ with ignore_curse_errors(): result = 42 self.assertEqual(result, 42) def test_ignore_curse_errors_raise_from_curse(self): """ Check that if an exception from curse is raised, it is ignored. """ # If the exception is ignored, the test passes. Otherwise it doesn't # because an exception is raised. with ignore_curse_errors(): raise curses.error def test_ignore_curse_errors_raise_exception(self): """ Check that if an exception that is not from curse, it is not ignored. """ with self.assertRaises(LookupError): with ignore_curse_errors(): raise LookupError
def testUnresolvable(self): fileLine = ".../something/foo.py" result = parse.matchLine(fileLine) lineObj = format.LineMatch(fileLine, result, 0) self.assertTrue( not lineObj.isResolvable(), '"%s" should not be resolvable' % fileLine ) print 'Tested unresolvable case.'
def testResolvable(self): toCheck = [case for case in fileTestCases if case['match']] for testCase in toCheck: result = parse.matchLine(testCase['input']) lineObj = format.LineMatch(testCase['input'], result, 0) self.assertTrue( lineObj.isResolvable(), 'Line "%s" was not resolvable' % testCase['input'] ) print 'Tested %d resolvable cases.' % len(toCheck)
def testResolvable(self): toCheck = [case for case in fileTestCases if case['match']] for testCase in toCheck: result = parse.matchLine(testCase['input']) lineObj = format.LineMatch(FormattedText(testCase['input']), result, 0) self.assertTrue(lineObj.isResolvable(), 'Line "%s" was not resolvable' % testCase['input']) print('Tested %d resolvable cases.' % len(toCheck)) def testFileMatch(self): for testCase in fileTestCases: self.checkFileResult(testCase) print('Tested %d cases.' % len(fileTestCases)) def testAllInputMatches(self): for testCase in allInputTestCases: result = parse.matchLine(testCase['input'], False, True) if not result: self.assertTrue( testCase['match'] is None, 'Expected a match "%s" where one did not occur.' % testCase['match']) continue (match, _, _) = result self.assertEqual(match, testCase['match'], 'Line "%s" did not match.' % testCase['input']) print('Tested %d cases for all-input matching.' % len(allInputTestCases)) def checkFileResult(self, testCase): result = parse.matchLine(testCase['input'], validateFileExists=testCase.get( 'validateFileExists', False)) if not result: self.assertFalse( testCase['match'], 'Line "%s" did not match any regex' % testCase['input']) return file, num, match = result self.assertTrue(testCase['match'], 'Line "%s" did match' % testCase['input']) self.assertEqual( testCase['file'], file, 'files not equal |%s| |%s|' % (testCase['file'], file)) self.assertEqual( testCase.get('num', 0), num, 'num matches not equal %d %d for %s' % (testCase.get('num', 0), num, testCase.get('input')))
def getLineObjs(): inputLines = sys.stdin.readlines() lineObjs = {} for index, line in enumerate(inputLines): line = line.replace('\t', ' ') line = re.sub(r'\x1b[^mK]*(m|K)', '', line) result = parse.matchLine(line) if not result: simple = format.SimpleLine(line, index) lineObjs[index] = simple continue match = format.LineMatch(line, result, index) lineObjs[index] = match return lineObjs
def testAllInputMatches(self): for testCase in allInputTestCases: result = parse.matchLine(testCase['input'], False, True) if not result: self.assertTrue(testCase['match'] is None, 'Expected a match "%s" where one did not occur.' % testCase['match']) continue (match, _, _) = result self.assertEqual(match, testCase['match'], 'Line "%s" did not match.' % testCase['input']) print('Tested %d cases for all-input matching.' % len(allInputTestCases))
def getLineObjs(): inputLines = sys.stdin.readlines() lineObjs = {} for index, line in enumerate(inputLines): line = line.replace('\t', ' ') formattedLine = FormattedText(line) result = parse.matchLine(str(formattedLine)) if not result: line = format.SimpleLine(formattedLine, index) else: line = format.LineMatch(formattedLine, result, index) lineObjs[index] = line return lineObjs
def checkFileResult(self, testCase): result = parse.matchLine(testCase['input']) if not result: self.assertFalse(testCase['match'], 'Line "%s" did not match any regex' % testCase['input']) return file, num, match = result self.assertTrue(testCase['match'], 'Line "%s" did match' % testCase['input']) self.assertEqual(testCase['file'], file, 'files not equal |%s| |%s|' % (testCase['file'], file)) self.assertEqual(testCase['num'], num, 'num matches not equal %d %d for %s' % (testCase['num'], num, testCase.get('input')))
def getLineObjsFromLines(inputLines): lineObjs = {} for index, line in enumerate(inputLines): line = line.replace('\t', ' ') # remove the new line as we place the cursor ourselves for each # line. this avoids curses errors when we newline past the end of the # screen line = line.replace('\n', '') formattedLine = FormattedText(line) result = parse.matchLine(str(formattedLine)) if not result: line = format.SimpleLine(formattedLine, index) else: line = format.LineMatch(formattedLine, result, index) lineObjs[index] = line return lineObjs
def getLineObjs(customRegex=None): inputLines = sys.stdin.readlines() lineObjs = {} for index, line in enumerate(inputLines): line = line.replace('\t', ' ') line = re.sub(r'\x1b[^mK]*(m|K)', '', line) result = parse.matchLine(line, customRegex=customRegex) if not result: simple = format.SimpleLine(line, index) lineObjs[index] = simple continue match = format.LineMatch(line, result, index) # Ugly hack to remove prepended ./ from # matches from custom regexes if customRegex: match.file = result[0] lineObjs[index] = match return lineObjs
# print (sys.path) import logger import parse from formattedText import FormattedText PathMarker_buffer_file = os.path.expanduser('~/.PathMarker') open(PathMarker_buffer_file, 'a').close() theline = "" if __name__ == "__main__": if sys.argv[1] == "set": count = 0 f = open(PathMarker_buffer_file,"w") for name in sys.stdin.readlines(): formattedLine = FormattedText(name) result=parse.matchLine(str(formattedLine), allInput=False) if result: path = parse.prependDir(result[0], withFileInspection=False) count += 1 sys.stdout.write("%d\t%s" % (count, name)) f.write("%s\n" % path) else: sys.stdout.write("\t%s" % (name)) f.close if sys.argv[1] == "setall": count = 0 f = open(PathMarker_buffer_file,"w") for name in sys.stdin.readlines(): formattedLine = FormattedText(name) result=parse.matchLine(str(formattedLine), allInput=True)