3 """Some simple tests for practracker metrics"""
5 # Future imports for Python 2.7, mandatory in 3.0
6 from __future__
import division
7 from __future__
import print_function
8 from __future__
import unicode_literals
13 # python 2 names the module this way...
14 from StringIO
import StringIO
16 # python 3 names the module this way.
17 from io
import StringIO
21 function_file
= """static void
22 fun(directory_request_t *req, const char *resource)
24 time_t if_modified_since = 0;
25 uint8_t or_diff_from[DIGEST256_LEN];
29 fun(directory_request_t *req,
32 time_t if_modified_since = 0;
33 uint8_t or_diff_from[DIGEST256_LEN];
39 uint8_t router_purpose,
42 download_want_authority_t want_authority))
44 const routerstatus_t *rs = NULL;
45 const or_options_t *options = get_options();
49 class TestFunctionLength(unittest
.TestCase
):
50 def test_function_length(self
):
51 funcs
= StringIO(function_file
)
52 # All functions should have length 2
53 for name
, lines
in metrics
.get_function_lines(funcs
):
54 self
.assertEqual(name
, "fun")
58 for name
, lines
in metrics
.get_function_lines(funcs
):
59 self
.assertEqual(lines
, 4)
61 class TestIncludeCount(unittest
.TestCase
):
62 def test_include_count(self
):
69 self
.assertEqual(metrics
.get_include_count(f
),4)
71 if __name__
== '__main__':