2020-02-16 20:58:01 +01:00
|
|
|
#!/usr/bin/env python
|
2019-07-17 14:00:28 +02:00
|
|
|
|
2019-02-27 14:14:29 +01:00
|
|
|
"""Some simple tests for practracker metrics"""
|
|
|
|
|
2019-12-12 06:58:51 +01:00
|
|
|
# Future imports for Python 2.7, mandatory in 3.0
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2019-02-27 14:14:29 +01:00
|
|
|
import unittest
|
|
|
|
|
2019-08-01 20:00:48 +02:00
|
|
|
try:
|
|
|
|
# python 2 names the module this way...
|
|
|
|
from StringIO import StringIO
|
|
|
|
except ImportError:
|
|
|
|
# python 3 names the module this way.
|
|
|
|
from io import StringIO
|
2019-02-27 14:14:29 +01:00
|
|
|
|
|
|
|
import metrics
|
|
|
|
|
|
|
|
function_file = """static void
|
|
|
|
fun(directory_request_t *req, const char *resource)
|
|
|
|
{
|
|
|
|
time_t if_modified_since = 0;
|
|
|
|
uint8_t or_diff_from[DIGEST256_LEN];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fun(directory_request_t *req,
|
|
|
|
const char *resource)
|
|
|
|
{
|
|
|
|
time_t if_modified_since = 0;
|
|
|
|
uint8_t or_diff_from[DIGEST256_LEN];
|
|
|
|
}
|
|
|
|
|
|
|
|
MOCK_IMPL(void,
|
|
|
|
fun,(
|
|
|
|
uint8_t dir_purpose,
|
|
|
|
uint8_t router_purpose,
|
|
|
|
const char *resource,
|
|
|
|
int pds_flags,
|
|
|
|
download_want_authority_t want_authority))
|
|
|
|
{
|
|
|
|
const routerstatus_t *rs = NULL;
|
|
|
|
const or_options_t *options = get_options();
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
class TestFunctionLength(unittest.TestCase):
|
|
|
|
def test_function_length(self):
|
2019-08-01 20:00:48 +02:00
|
|
|
funcs = StringIO(function_file)
|
2019-02-27 14:14:29 +01:00
|
|
|
# All functions should have length 2
|
2019-07-17 14:00:28 +02:00
|
|
|
for name, lines in metrics.get_function_lines(funcs):
|
2019-02-27 14:14:29 +01:00
|
|
|
self.assertEqual(name, "fun")
|
2019-02-27 18:29:27 +01:00
|
|
|
|
|
|
|
funcs.seek(0)
|
|
|
|
|
2019-07-17 14:00:28 +02:00
|
|
|
for name, lines in metrics.get_function_lines(funcs):
|
|
|
|
self.assertEqual(lines, 4)
|
2019-02-27 14:14:29 +01:00
|
|
|
|
2019-07-17 14:02:17 +02:00
|
|
|
class TestIncludeCount(unittest.TestCase):
|
|
|
|
def test_include_count(self):
|
2019-08-01 20:00:48 +02:00
|
|
|
f = StringIO("""
|
2019-07-17 14:02:17 +02:00
|
|
|
# include <abc.h>
|
|
|
|
# include "def.h"
|
|
|
|
#include "ghi.h"
|
|
|
|
\t#\t include "jkl.h"
|
|
|
|
""")
|
|
|
|
self.assertEqual(metrics.get_include_count(f),4)
|
|
|
|
|
2019-02-27 14:14:29 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|