Browse Source

Fix practracker_tests.py and practracker line counting.

The practracker_tests.py unit test file called a function by its old
name.

Also, practracker counted functions as starting one line after the
function name, and ending with the closing brace.  Now they start
with the open brace and end with the closing brace.
Nick Mathewson 6 years ago
parent
commit
4c09532996

+ 6 - 2
scripts/maint/practracker/metrics.py

@@ -31,6 +31,7 @@ def get_function_lines(f):
                             "DISABLE_GCC_WARNING", "DISABLE_GCC_WARNINGS"}
                             "DISABLE_GCC_WARNING", "DISABLE_GCC_WARNINGS"}
 
 
     in_function = False
     in_function = False
+    found_openbrace = False
     for lineno, line in enumerate(f):
     for lineno, line in enumerate(f):
         if not in_function:
         if not in_function:
             # find the start of a function
             # find the start of a function
@@ -41,10 +42,13 @@ def get_function_lines(f):
                     continue
                     continue
                 func_start = lineno
                 func_start = lineno
                 in_function = True
                 in_function = True
-
+        elif not found_openbrace and line.startswith("{"):
+            found_openbrace = True
+            func_start = lineno
         else:
         else:
             # Find the end of a function
             # Find the end of a function
             if line.startswith("}"):
             if line.startswith("}"):
-                n_lines = lineno - func_start
+                n_lines = lineno - func_start + 1
                 in_function = False
                 in_function = False
+                found_openbrace = False
                 yield (func_name, n_lines)
                 yield (func_name, n_lines)

+ 5 - 3
scripts/maint/practracker/practracker_tests.py

@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
 """Some simple tests for practracker metrics"""
 """Some simple tests for practracker metrics"""
 
 
 import unittest
 import unittest
@@ -38,13 +40,13 @@ class TestFunctionLength(unittest.TestCase):
     def test_function_length(self):
     def test_function_length(self):
         funcs = StringIO.StringIO(function_file)
         funcs = StringIO.StringIO(function_file)
         # All functions should have length 2
         # All functions should have length 2
-        for name, lines in metrics.function_lines(funcs):
+        for name, lines in metrics.get_function_lines(funcs):
             self.assertEqual(name, "fun")
             self.assertEqual(name, "fun")
 
 
         funcs.seek(0)
         funcs.seek(0)
 
 
-        for name, lines in metrics.function_lines(funcs):
-            self.assertEqual(lines, 2)
+        for name, lines in metrics.get_function_lines(funcs):
+            self.assertEqual(lines, 4)
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     unittest.main()
     unittest.main()