Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: tools/code_coverage/croc_test.py

Issue 8678023: Fix python scripts in src/tools/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/code_coverage/croc_scan_test.py ('k') | tools/code_coverage/process_coverage.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/env python
2 # 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Copyright 2009, Google Inc. 3 # Use of this source code is governed by a BSD-style license that can be
4 # All rights reserved. 4 # found in the LICENSE file.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
15 # distribution.
16 # * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 5
32 """Unit tests for Crocodile.""" 6 """Unit tests for Crocodile."""
33 7
34 import os 8 import os
35 import StringIO 9 import StringIO
36 import unittest 10 import unittest
37 import croc 11 import croc
38 12
39 #------------------------------------------------------------------------------
40
41 13
42 class TestCoverageStats(unittest.TestCase): 14 class TestCoverageStats(unittest.TestCase):
43 """Tests for croc.CoverageStats.""" 15 """Tests for croc.CoverageStats."""
44 16
45 def testAdd(self): 17 def testAdd(self):
46 """Test Add().""" 18 """Test Add()."""
47 c = croc.CoverageStats() 19 c = croc.CoverageStats()
48 20
49 # Initially empty 21 # Initially empty
50 self.assertEqual(c, {}) 22 self.assertEqual(c, {})
51 23
52 # Add items 24 # Add items
53 c['a'] = 1 25 c['a'] = 1
54 c['b'] = 0 26 c['b'] = 0
55 self.assertEqual(c, {'a': 1, 'b': 0}) 27 self.assertEqual(c, {'a': 1, 'b': 0})
56 28
57 # Add dict with non-overlapping items 29 # Add dict with non-overlapping items
58 c.Add({'c': 5}) 30 c.Add({'c': 5})
59 self.assertEqual(c, {'a': 1, 'b': 0, 'c': 5}) 31 self.assertEqual(c, {'a': 1, 'b': 0, 'c': 5})
60 32
61 # Add dict with overlapping items 33 # Add dict with overlapping items
62 c.Add({'a': 4, 'd': 3}) 34 c.Add({'a': 4, 'd': 3})
63 self.assertEqual(c, {'a': 5, 'b': 0, 'c': 5, 'd': 3}) 35 self.assertEqual(c, {'a': 5, 'b': 0, 'c': 5, 'd': 3})
64 36
65 #------------------------------------------------------------------------------
66
67 37
68 class TestCoveredFile(unittest.TestCase): 38 class TestCoveredFile(unittest.TestCase):
69 """Tests for croc.CoveredFile.""" 39 """Tests for croc.CoveredFile."""
70 40
71 def setUp(self): 41 def setUp(self):
72 self.cov_file = croc.CoveredFile('bob.cc', group='source', language='C++') 42 self.cov_file = croc.CoveredFile('bob.cc', group='source', language='C++')
73 43
74 def testInit(self): 44 def testInit(self):
75 """Test init.""" 45 """Test init."""
76 f = self.cov_file 46 f = self.cov_file
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 f.UpdateCoverage() 107 f.UpdateCoverage()
138 self.assertEqual(f.stats, { 108 self.assertEqual(f.stats, {
139 'lines_executable': 7, 109 'lines_executable': 7,
140 'lines_instrumented': 4, 110 'lines_instrumented': 4,
141 'lines_covered': 2, 111 'lines_covered': 2,
142 'files_executable': 1, 112 'files_executable': 1,
143 'files_instrumented': 1, 113 'files_instrumented': 1,
144 'files_covered': 1, 114 'files_covered': 1,
145 }) 115 })
146 116
147 #------------------------------------------------------------------------------
148
149 117
150 class TestCoveredDir(unittest.TestCase): 118 class TestCoveredDir(unittest.TestCase):
151 """Tests for croc.CoveredDir.""" 119 """Tests for croc.CoveredDir."""
152 120
153 def setUp(self): 121 def setUp(self):
154 self.cov_dir = croc.CoveredDir('/a/b/c') 122 self.cov_dir = croc.CoveredDir('/a/b/c')
155 123
156 def testInit(self): 124 def testInit(self):
157 """Test init.""" 125 """Test init."""
158 d = self.cov_dir 126 d = self.cov_dir
(...skipping 27 matching lines...) Expand all
186 """Test getting tree with subdirs.""" 154 """Test getting tree with subdirs."""
187 d1 = self.cov_dir = croc.CoveredDir('/a') 155 d1 = self.cov_dir = croc.CoveredDir('/a')
188 d2 = self.cov_dir = croc.CoveredDir('/a/b') 156 d2 = self.cov_dir = croc.CoveredDir('/a/b')
189 d3 = self.cov_dir = croc.CoveredDir('/a/c') 157 d3 = self.cov_dir = croc.CoveredDir('/a/c')
190 d4 = self.cov_dir = croc.CoveredDir('/a/b/d') 158 d4 = self.cov_dir = croc.CoveredDir('/a/b/d')
191 d5 = self.cov_dir = croc.CoveredDir('/a/b/e') 159 d5 = self.cov_dir = croc.CoveredDir('/a/b/e')
192 d1.subdirs = {'/a/b': d2, '/a/c': d3} 160 d1.subdirs = {'/a/b': d2, '/a/c': d3}
193 d2.subdirs = {'/a/b/d': d4, '/a/b/e': d5} 161 d2.subdirs = {'/a/b/d': d4, '/a/b/e': d5}
194 self.assertEqual(d1.GetTree(), 'a/\n b/\n d/\n e/\n c/') 162 self.assertEqual(d1.GetTree(), 'a/\n b/\n d/\n e/\n c/')
195 163
196 #------------------------------------------------------------------------------
197
198 164
199 class TestCoverage(unittest.TestCase): 165 class TestCoverage(unittest.TestCase):
200 """Tests for croc.Coverage.""" 166 """Tests for croc.Coverage."""
201 167
202 def MockWalk(self, src_dir): 168 def MockWalk(self, src_dir):
203 """Mock for os.walk(). 169 """Mock for os.walk().
204 170
205 Args: 171 Args:
206 src_dir: Source directory to walk. 172 src_dir: Source directory to walk.
207 173
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 'files_instrumented': 1, 746 'files_instrumented': 1,
781 } 747 }
782 }) 748 })
783 749
784 # TODO: test: less important, since these are thin wrappers around other 750 # TODO: test: less important, since these are thin wrappers around other
785 # tested methods. 751 # tested methods.
786 # ParseConfig() 752 # ParseConfig()
787 # ParseLcovFile() 753 # ParseLcovFile()
788 # PrintTree() 754 # PrintTree()
789 755
790 #------------------------------------------------------------------------------
791 756
792 if __name__ == '__main__': 757 if __name__ == '__main__':
793 unittest.main() 758 unittest.main()
OLDNEW
« no previous file with comments | « tools/code_coverage/croc_scan_test.py ('k') | tools/code_coverage/process_coverage.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698