## ## Copyright (c) 2006 Jason Dillon ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. ## ## ## $Id: //guest/jason_dillon/p4spam/main/testsuite/test_parser.py#2 $ $Date: 2006/04/12 $ ## import os, sys DIRNAME = os.path.dirname(sys.argv[0]) DATADIR = os.path.join(DIRNAME, '..', 'testsuite') import unittest class TestCaseSupport(unittest.TestCase): def getFile(this, filename): filename = os.path.join(DATADIR, filename) return file(filename) def assertNotNone(this, value): this.assert_(value != None) def dumpDescription(desc): print desc print for f in desc.files: print " %s" % f print print "Comments:" for line in desc.comments: print " %s" % line, print print "Diffs:" for diff in desc.diffs: print diff for line in diff.lines: print " %s" % line, from p4spam.parser import DescriptionParser class ParserTestCaseSupport(TestCaseSupport): def chewDescription(this, desc): this.assertNotNone(desc) # Make sure there are some files fileCount = len(desc.files) this.assertNotEquals(0, fileCount) # Make sure if there are any edits, that we see diffs expectDiffCount = 0 for f in desc.files: if f.action in ('edit', 'integrate'): expectDiffCount = expectDiffCount + 1 diffs = [] for d in desc.diffs: diffs.append(d) this.assertEquals(expectDiffCount, len(diffs)) class Desc1TestCase(ParserTestCaseSupport): def testParse(this): parser = DescriptionParser(this.getFile("desc1.txt")) desc = parser.parse() this.chewDescription(desc) class Desc2TestCase(ParserTestCaseSupport): def testParse(this): parser = DescriptionParser(this.getFile("desc2.txt")) desc = parser.parse() this.chewDescription(desc) class Desc3TestCase(ParserTestCaseSupport): def testParse(this): parser = DescriptionParser(this.getFile("desc3.txt")) desc = parser.parse() this.chewDescription(desc)