- Некоректно
- 4 успешни тест(а)
- 3 неуспешни тест(а)
import os
import re
small_pattern = r'\bdef\b.*:\n\s{12}'
if_pattern = small_pattern + r'if'
else_pattern = small_pattern + r'else'
while_pattern = small_pattern + r'while'
for_pattern = small_pattern + r'for'
with_pattern = small_pattern + r'with'
except_pattern = small_pattern + r'except'
try_pattern = small_pattern + r'try'
big_pattern = while_pattern + r'|' + else_pattern + r'|' + \
with_pattern + r'|' + try_pattern + r'|' + \
for_pattern + r'|' + if_pattern + r'|' + except_pattern
def stats(path_to_directory):
if not os.path.exists(path_to_directory):
raise NotADirectoryError
curr_dir = os.getcwd()
os.chdir(path_to_directory)
result = {'classes': 0, 'functions': 0, 'unpleasant_functions': []}
for file in os.listdir():
if file.endswith(".py"):
current = open(file)
source = current.read()
result['classes'] += len(re.findall(r'\bclass\b', source))
result['functions'] += len(re.findall(r'\bdef\b', source))
while source.rfind("def") >= 0:
matching = re.findall(big_pattern, source, re.DOTALL)
if matching == []:
break
source = matching[0]
index = source.rfind("def")
remove = source[index:]
source = source[:index]
add_to_dict = f_name(remove)
result['unpleasant_functions'].append(
os.getcwd() + '/' + file + "#" + add_to_dict)
current.close()
os.chdir(curr_dir)
return result
def f_name(unpleasant_function):
i = 4
name = ""
while unpleasant_function[i] != '(':
name += unpleasant_function[i]
i += 1
return name
..F..FF
======================================================================
FAIL: test_catches_unpleasant_functions (test.TestAst)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
raise result
AssertionError: False is not true
======================================================================
FAIL: test_dont_read_code_from_docstring (test.TestAst)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
raise result
AssertionError: 3 != 2
======================================================================
FAIL: test_unpleasant_functions_count_correctness (test.TestAst)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
raise result
AssertionError: 6 != 0
----------------------------------------------------------------------
Ran 7 tests in 0.087s
FAILED (failures=3)







