practracker_tests.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/python
  2. """Some simple tests for practracker metrics"""
  3. import unittest
  4. import StringIO
  5. import metrics
  6. function_file = """static void
  7. fun(directory_request_t *req, const char *resource)
  8. {
  9. time_t if_modified_since = 0;
  10. uint8_t or_diff_from[DIGEST256_LEN];
  11. }
  12. static void
  13. fun(directory_request_t *req,
  14. const char *resource)
  15. {
  16. time_t if_modified_since = 0;
  17. uint8_t or_diff_from[DIGEST256_LEN];
  18. }
  19. MOCK_IMPL(void,
  20. fun,(
  21. uint8_t dir_purpose,
  22. uint8_t router_purpose,
  23. const char *resource,
  24. int pds_flags,
  25. download_want_authority_t want_authority))
  26. {
  27. const routerstatus_t *rs = NULL;
  28. const or_options_t *options = get_options();
  29. }
  30. """
  31. class TestFunctionLength(unittest.TestCase):
  32. def test_function_length(self):
  33. funcs = StringIO.StringIO(function_file)
  34. # All functions should have length 2
  35. for name, lines in metrics.get_function_lines(funcs):
  36. self.assertEqual(name, "fun")
  37. funcs.seek(0)
  38. for name, lines in metrics.get_function_lines(funcs):
  39. self.assertEqual(lines, 4)
  40. class TestIncludeCount(unittest.TestCase):
  41. def test_include_count(self):
  42. f = StringIO.StringIO("""
  43. # include <abc.h>
  44. # include "def.h"
  45. #include "ghi.h"
  46. \t#\t include "jkl.h"
  47. """)
  48. self.assertEqual(metrics.get_include_count(f),4)
  49. if __name__ == '__main__':
  50. unittest.main()