"Fossies" - the Fresh Open Source Software Archive 
Member "svnchecker-0.3/checks/UnitTests.py" (9 Jul 2008, 2010 Bytes) of package /linux/privat/old/svnchecker-0.3.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "UnitTests.py" see the
Fossies "Dox" file reference documentation.
1 # Copyright 2008 German Aerospace Center (DLR)
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """
16 This check tests if a unit test exists for a given Java class.
17 The java class must follow the pattern /main/.../Class.java and
18 the unit test must follow the pattern /main/.../TestClass.java.
19 Interfaces are omitted.
20 """
21
22 import re
23
24 def run(transaction, config):
25
26 check = config.getArray("UnitTests.CheckFiles", [".*\.java"])
27 ignore = config.getArray("UnitTests.IgnoreFiles", [])
28 files = transaction.getFiles(check, ignore)
29
30 interfacePattern = re.compile("interface .* {")
31 classPattern = re.compile("class .* {")
32
33 msg = ""
34 for filename, attribute in files.iteritems():
35 if attribute in ["A", "U", "UU"] and not "/test/" in filename:
36
37 # skip java interfaces
38 fileHandler = open(transaction.getFile(filename), "r")
39 skipFile = False
40 for line in fileHandler:
41 if interfacePattern.search(line):
42 skipFile = True
43 break
44 elif classPattern.search(line):
45 break
46 fileHandler.close()
47
48 if skipFile:
49 continue
50
51 unitTestName = filename.replace("/main/", "/test/").replace(".java", "Test.java")
52
53 if not transaction.fileExists(unitTestName):
54 msg += "No unittest exists for file %r.\n" % filename
55
56 if msg:
57 return (msg, 1)
58 else:
59 return ("", 0)