예제 #1
0
 def test_should_only_return_py_glob(self):
     when(os).walk("spam").thenReturn([("spam", [], self.fake_dir_contents)
                                       ])
     expected_result = ["spam/README.md"]
     actual_result = set(discover_files_matching("spam", "README.?d"))
     self.assertEquals(set(expected_result), actual_result)
     verify(os).walk("spam")
예제 #2
0
def analyze(project, logger):
    root_directory = os.getcwd()
    source_modules = discover_files_matching(project.get_property("dir_source_main_python"),
                                             "*.py")
    errors = []

    logger.info("Executing jedi linter on project sources.")

    try:
        for path in source_modules:
            for error in jedi.Script(path=path)._analysis():
                errors.append(error)
    except Exception as e:
        logger.error("Jedi crashed: {0}".format(e))
        import traceback
        logger.debug(traceback.format_exc())

    number_of_errors = len(errors)
    output = logger.info if number_of_errors == 0 else logger.warn
    output("Jedi linter found {0} errors.".format(number_of_errors))
    if project.get_property("jedi_linter_verbose") or project.get_property("verbose"):
        for error in errors:
            logger.warn(error)

    if project.get_property("jedi_linter_break_build") and number_of_errors > 0:
        raise BuildFailedException("Jedi linter found errors")

    os.chdir(root_directory)  # jedi chdirs into directories, so undo it
def discover_integration_tests_for_project(project, logger=None):
    integrationtest_source_dir = project.expand_path("$dir_source_integrationtest_python")
    integrationtest_suffix = project.get_property("integrationtest_file_suffix")
    if integrationtest_suffix is not None:
        if logger is not None:
            logger.warn(
                "integrationtest_file_suffix is deprecated, please use integrationtest_file_glob"
            )
        project.set_property("integrationtest_file_glob", "*{0}".format(integrationtest_suffix))
    integrationtest_glob = project.expand("$integrationtest_file_glob")
    return discover_files_matching(integrationtest_source_dir, integrationtest_glob)
def discover_integration_tests_for_project(project, logger=None):
    integrationtest_source_dir = project.expand_path(
        "$dir_source_integrationtest_python")
    integrationtest_suffix = project.get_property("integrationtest_file_suffix")
    if integrationtest_suffix is not None:
        if logger is not None:
            logger.warn(
                "integrationtest_file_suffix is deprecated, please use integrationtest_file_glob"
            )
        project.set_property("integrationtest_file_glob", "*{0}".format(integrationtest_suffix))
    integrationtest_glob = project.expand("$integrationtest_file_glob")
    return discover_files_matching(integrationtest_source_dir, integrationtest_glob)
예제 #5
0
def discover_affected_files(include_test_sources, include_scripts, project):
    source_dir = project.get_property("dir_source_main_python")
    files = discover_python_files(source_dir)

    if include_test_sources:
        if project.get_property("dir_source_unittest_python"):
            unittest_dir = project.get_property("dir_source_unittest_python")
            files = itertools.chain(files, discover_python_files(unittest_dir))
        if project.get_property("dir_source_integrationtest_python"):
            integrationtest_dir = project.get_property("dir_source_integrationtest_python")
            files = itertools.chain(files, discover_python_files(integrationtest_dir))
    if include_scripts and project.get_property("dir_source_main_scripts"):
        scripts_dir = project.get_property("dir_source_main_scripts")
        files = itertools.chain(files, discover_files_matching(scripts_dir, "*"))  # we have no idea how scripts might look
    return files
예제 #6
0
def checkstyle(project, logger):
    #pylint: disable=R0914
    logger.info("Executing pylint on project sources.")

    src_dir = project.get_property('dir_source_main_python')
    py_files = [e for e in discover_files_matching(src_dir, '*.py')]  #pylint: disable=R1721
    cmd = as_list('pylint', '--rcfile=.pylintrc', py_files)
    out_fname = project.expand_path("$dir_reports/{}".format('pylint'))
    err_fname = '{}.err'.format(out_fname)
    exit_code = execute_command(cmd, out_fname)
    report = read_file(out_fname)
    error = read_file(err_fname)

    if exit_code != 0 and error:
        msg = 'Errors occurred while running pylint, check {}'.format(
            err_fname)
        logger.error(msg)
        raise BuildFailedException(msg)
    logger.warn(''.join(report))

    try:
        # get pylint score from the message
        # e.g. "Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)"
        pattern = r'(\d{0,2}\.\d{2})/10'
        pat = re.compile(pattern)
        res = re.search(pat, report[-2])
        score = float(res.group(1))
    except Exception as _:
        traceback.print_exc()
        raise BuildFailedException('fail to parse pylint score.')

    cutoff = 8.5
    if project.get_property('break_build') and score < cutoff:
        msg = 'Fail to pass (score={:.2f}, cutoff={:.2f})'.format(
            score, cutoff)
        raise BuildFailedException(msg)
    logger.info('Pass (score={:.2f}, cutoff={:.2f})'.format(score, cutoff))
예제 #7
0
def discover_integration_tests(source_path, suffix=".py"):
    return discover_files_matching(source_path, "*{0}".format(suffix))
예제 #8
0
def discover_integration_tests_matching(source_path, file_glob):
    return discover_files_matching(source_path, file_glob)
def discover_integration_tests_matching(source_path, file_glob):
    return discover_files_matching(source_path, file_glob)
예제 #10
0
 def test_should_only_return_py_glob(self, walk):
     expected_result = [nc("spam/readme.md")]
     actual_result = set(discover_files_matching("spam", "readme.?d"))
     self.assertEqual(set(expected_result), actual_result)
     walk.assert_called_with("spam")
def discover_python_files(directory, exclude_glob=None):
    return discover_files_matching(directory, "*.py", exclude_glob)
예제 #12
0
def discover_integration_tests(source_path, suffix=".py"):
    return discover_files_matching(source_path, "*{0}".format(suffix))
예제 #13
0
 def test_should_only_return_py_glob(self):
     when(os).walk("spam").thenReturn([("spam", [], self.fake_dir_contents)])
     expected_result = ["spam/README.md"]
     actual_result = set(discover_files_matching("spam", "README.?d"))
     self.assertEquals(set(expected_result), actual_result)
     verify(os).walk("spam")
예제 #14
0
 def test_should_only_return_py_glob(self, walk):
     expected_result = [nc("spam/readme.md")]
     actual_result = set(discover_files_matching("spam", "readme.?d"))
     self.assertEqual(set(expected_result), actual_result)
     walk.assert_called_with("spam")
def discover_python_files(directory):
    return discover_files_matching(directory, "*.py")
예제 #16
0
def _find_files(project):
    cram_dir = project.get_property('dir_source_cmdlinetest')
    cram_test_file_glob = project.get_property("cram_test_file_glob")
    cram_files = discover_files_matching(cram_dir, cram_test_file_glob)
    return cram_files
예제 #17
0
 def test_should_only_return_py_glob(self, walk):
     expected_result = ["spam/README.md"]
     actual_result = set(discover_files_matching("spam", "README.?d"))
     self.assertEquals(set(expected_result), actual_result)
     walk.assert_called_with("spam")
예제 #18
0
def discover_python_files(directory):
    return discover_files_matching(directory, "*.py")
예제 #19
0
 def test_should_only_return_py_glob(self, walk):
     expected_result = ["spam/README.md"]
     actual_result = set(discover_files_matching("spam", "README.?d"))
     self.assertEquals(set(expected_result), actual_result)
     walk.assert_called_with("spam")