timeit

Програмиране с Python

Курс във Факултета по Математика и Информатика към СУ

Решение на Статичен анализ на python код от Хризантема Станчева

Обратно към всички решения

Към профила на Хризантема Станчева

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from ast import *
import greentreesnakes


def line_too_long(code, line_length=79, **kwargs):
    tmp_dict = {}
    list_of_lines = code.split("\n")
    for i in range(0, len(list_of_lines)):
        cl = len(list_of_lines[i])
        if cl > line_length:
            tmp_dict[i + 1] = 'line too long ({} > {})'.format(cl, line_length)
    return tmp_dict


def multiple_expr_on_the_same_line(code, forbid_semicolons=True, **kwargs):
    tmp_dict = {}
    list_of_lines = code.split("\n")
    if forbid_semicolons is True:
        for i in range(0, len(list_of_lines)):
            if ';' in list_of_lines[i]:
                tmp_dict[i + 1] = 'multiple expressions on the same line'
    return tmp_dict


def max_nesting(code, max_nesting=None):
    tmp_dict = {}
    return tmp_dict


def indentation_size(code, indentation_size=4): #брой <Space> символи, с които трябва да са индентирани блоковете код
    tmp_dict = {}
    return tmp_dict


def methods_per_class_size(code, methods_per_class=None): #максимален брой методи в клас.
    tmp_dict = {}
    return tmp_dict


def max_arity(code, max_arity=None): #максимален брой аргументи на функции/методи.
    tmp_dict = {}
    return tmp_dict


def forbid_trailing_whitespace(code, forbid_trailing_whitespace=True): #да се отчитат ли като грешка whitespace символи в края на реда.
    tmp_dict = {}
    return tmp_dict

def max_lines_per_function(code, max_lines_per_function=None): #максимален брой логически редове в тялото на функция/метод.
    tmp_dict = {}
    return tmp_dict


def critic(code, **rules):
    list_result = []
    dict_result = {}

    list_result.append(multiple_expr_on_the_same_line(code, **rules))
    list_result.append(line_too_long(code, **rules))
    list_result.append(max_nesting(code, **rules))
    list_result.append(indentation_size(code, **rules))
    list_result.append(methods_per_class_size(code, **rules))
    list_result.append(max_arity(code, **rules))
    list_result.append(forbid_trailing_whitespace(code, **rules))
    list_result.append(max_lines_per_function(code, **rules))

    for res in list_result:
        for key, value in res.items():
            if key in dict_result.keys():
                dict_result[key].append(value)
            else:
                dict_result[key] = [value]

    return dict_result

Лог от изпълнението

No module named 'greentreesnakes'
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 114, in main
    loaded_test = imp.load_source('test', test_module)
  File "/usr/local/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/tmp/d20160709-29474-7wrbbj/test.py", line 3, in <module>
    import solution
  File "/tmp/d20160709-29474-7wrbbj/solution.py", line 2, in <module>
    import greentreesnakes

История (1 версия и 0 коментара)

Хризантема обнови решението на 18.05.2016 09:49 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from ast import *
import greentreesnakes


def line_too_long(code, line_length=79, **kwargs):
    tmp_dict = {}
    list_of_lines = code.split("\n")
    for i in range(0, len(list_of_lines)):
        cl = len(list_of_lines[i])
        if cl > line_length:
            tmp_dict[i + 1] = 'line too long ({} > {})'.format(cl, line_length)
    return tmp_dict


def multiple_expr_on_the_same_line(code, forbid_semicolons=True, **kwargs):
    tmp_dict = {}
    list_of_lines = code.split("\n")
    if forbid_semicolons is True:
        for i in range(0, len(list_of_lines)):
            if ';' in list_of_lines[i]:
                tmp_dict[i + 1] = 'multiple expressions on the same line'
    return tmp_dict


def max_nesting(code, max_nesting=None):
    tmp_dict = {}
    return tmp_dict


def indentation_size(code, indentation_size=4): #брой <Space> символи, с които трябва да са индентирани блоковете код
    tmp_dict = {}
    return tmp_dict


def methods_per_class_size(code, methods_per_class=None): #максимален брой методи в клас.
    tmp_dict = {}
    return tmp_dict


def max_arity(code, max_arity=None): #максимален брой аргументи на функции/методи.
    tmp_dict = {}
    return tmp_dict


def forbid_trailing_whitespace(code, forbid_trailing_whitespace=True): #да се отчитат ли като грешка whitespace символи в края на реда.
    tmp_dict = {}
    return tmp_dict

def max_lines_per_function(code, max_lines_per_function=None): #максимален брой логически редове в тялото на функция/метод.
    tmp_dict = {}
    return tmp_dict


def critic(code, **rules):
    list_result = []
    dict_result = {}

    list_result.append(multiple_expr_on_the_same_line(code, **rules))
    list_result.append(line_too_long(code, **rules))
    list_result.append(max_nesting(code, **rules))
    list_result.append(indentation_size(code, **rules))
    list_result.append(methods_per_class_size(code, **rules))
    list_result.append(max_arity(code, **rules))
    list_result.append(forbid_trailing_whitespace(code, **rules))
    list_result.append(max_lines_per_function(code, **rules))

    for res in list_result:
        for key, value in res.items():
            if key in dict_result.keys():
                dict_result[key].append(value)
            else:
                dict_result[key] = [value]

    return dict_result