Use EWMA instead of bare rtt for min rtt.
[tor.git] / scripts / maint / practracker / practracker_tests.py
blobe03c9e05aeca22d9d782889e362d8f3fcf609daf
1 #!/usr/bin/env python
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
10 import unittest
12 try:
13 # python 2 names the module this way...
14 from StringIO import StringIO
15 except ImportError:
16 # python 3 names the module this way.
17 from io import StringIO
19 import metrics
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];
28 static void
29 fun(directory_request_t *req,
30 const char *resource)
32 time_t if_modified_since = 0;
33 uint8_t or_diff_from[DIGEST256_LEN];
36 MOCK_IMPL(void,
37 fun,(
38 uint8_t dir_purpose,
39 uint8_t router_purpose,
40 const char *resource,
41 int pds_flags,
42 download_want_authority_t want_authority))
44 const routerstatus_t *rs = NULL;
45 const or_options_t *options = get_options();
47 """
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")
56 funcs.seek(0)
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):
63 f = StringIO("""
64 # include <abc.h>
65 # include "def.h"
66 #include "ghi.h"
67 \t#\t include "jkl.h"
68 """)
69 self.assertEqual(metrics.get_include_count(f),4)
71 if __name__ == '__main__':
72 unittest.main()