practracker_tests.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """Some simple tests for practracker metrics"""
  2. import unittest
  3. import StringIO
  4. import metrics
  5. function_file = """static void
  6. fun(directory_request_t *req, const char *resource)
  7. {
  8. time_t if_modified_since = 0;
  9. uint8_t or_diff_from[DIGEST256_LEN];
  10. }
  11. static void
  12. fun(directory_request_t *req,
  13. const char *resource)
  14. {
  15. time_t if_modified_since = 0;
  16. uint8_t or_diff_from[DIGEST256_LEN];
  17. }
  18. MOCK_IMPL(void,
  19. fun,(
  20. uint8_t dir_purpose,
  21. uint8_t router_purpose,
  22. const char *resource,
  23. int pds_flags,
  24. download_want_authority_t want_authority))
  25. {
  26. const routerstatus_t *rs = NULL;
  27. const or_options_t *options = get_options();
  28. }
  29. """
  30. class TestFunctionLength(unittest.TestCase):
  31. def test_function_length(self):
  32. funcs = StringIO.StringIO(function_file)
  33. # All functions should have length 2
  34. for name, lines in metrics.function_lines(funcs):
  35. self.assertEqual(name, "fun")
  36. funcs.seek(0)
  37. for name, lines in metrics.function_lines(funcs):
  38. self.assertEqual(lines, 2)
  39. if __name__ == '__main__':
  40. unittest.main()