示例#1
0
def test_select_good_functions(source_code, expected_names, monkeypatch):
    monkeypatch.setattr(loader.Selector, 'MIN_NUM_STATEMENTS', 2)
    functions = parser.get_functions_from_fileobj(
        io.StringIO(textwrap.dedent(source_code)), 'file.py',
        parser.Options(False, True))
    good_functions = loader.select_good_functions(functions)
    actual_names = {a_function.name for a_function in good_functions}
    assert actual_names == set(expected_names)
示例#2
0
def _get_functions_from_directory(
        dir_path: str,
        github_repo: models.GithubRepo) -> tp.Set[parser.Function]:
    functions = set()
    parser_options = parser.Options(catch_exceptions=True, verbose=False)
    with utils.log_time(loggers.loader, f'parsing {github_repo.url}'):
        py_files = _find_files(dir_path, extension='py')
        for a_file in py_files:
            functions.update(parser.get_functions(a_file, parser_options))
    loggers.loader.info('found %d distinct functions in %d files',
                        len(functions), len(py_files))
    return functions
示例#3
0
def test_get_functions_failure(source_code, expected_exception):
    with pytest.raises(expected_exception):
        parser.get_functions_from_fileobj(
            io.StringIO(textwrap.dedent(source_code)), 'file.py',
            parser.Options(False, True))
示例#4
0
def test_get_functions_catch_decode_error():
    # noinspection PyTypeChecker
    fileobj = io.TextIOWrapper(io.BytesIO('тест'.encode('cp1251')),
                               encoding='utf-8')
    assert parser.get_functions_from_fileobj(fileobj, 'file.py',
                                             parser.Options(True, True)) == []
示例#5
0
def test_get_functions(source_code, expected_functions):
    fileobj = io.StringIO(textwrap.dedent(source_code))
    actual_functions = parser.get_functions_from_fileobj(
        fileobj, 'file.py', parser.Options(True, True))
    assert actual_functions == expected_functions