def tearDown(self):
     # Since we may have created a brainless manager, leading
     # to a new cache builtin module and proxy classes in the constants,
     # clear out the global manager cache.
     MANAGER.clear_cache()
     sys.path.pop(0)
     sys.path_importer_cache.pop(resources.find('data'), None)
示例#2
0
 def tearDown(self):
     # Since we may have created a brainless manager, leading
     # to a new cache builtin module and proxy classes in the constants,
     # clear out the global manager cache.
     MANAGER.clear_cache()
     sys.path.pop(0)
     sys.path_importer_cache.pop(resources.find('data'), None)
示例#3
0
 def tearDown(self):
     # Since we may have created a brainless manager, leading
     # to a new cache builtin module and proxy classes in the constants,
     # clear out the global manager cache.
     MANAGER.clear_cache(self._builtins)
     MANAGER.always_load_extensions = False
     sys.path.pop(0)
     sys.path_importer_cache.pop(resources.find("data"), None)
示例#4
0
 def tearDown(self):
     # Since we may have created a brainless manager, leading
     # to a new cache builtin module and proxy classes in the constants,
     # clear out the global manager cache.
     MANAGER.clear_cache(self._builtins)
     MANAGER.always_load_extensions = False
     sys.path.pop(0)
     sys.path_importer_cache.pop(resources.find("data"), None)
示例#5
0
文件: __init__.py 项目: ihasan98/pyta
def _check(module_name='', level='all', local_config='', output=None):
    """Check a module for problems, printing a report.

    The `module_name` can take several inputs:
      - string of a directory, or file to check (`.py` extension optional).
      - list of strings of directories or files -- can have multiple.
      - no argument -- checks the python file containing the function call.
    `level` is used to specify which checks should be made.
    `local_config` is a dict of config options or string (config file name).
    `output` is an absolute path to capture pyta data output. Default std out.
    """
    MANAGER.clear_cache()

    # Add reporters to an internal pylint data structure, for use with setting
    # custom pyta options in a Tuple, before (re)setting reporter.
    for reporter in REPORTERS:
        VALIDATORS[reporter.__name__] = reporter
    linter = reset_linter(config=local_config)

    current_reporter = reset_reporter(linter, output)
    patch_all()  # Monkeypatch pylint (override certain methods)

    # Try to check file, issue error message for invalid files.
    try:
        for locations in _get_valid_files_to_check(current_reporter,
                                                   module_name):
            for file_py in get_file_paths(locations):
                if not _verify_pre_check(file_py):
                    continue  # Check the other files
                # Load config file in user location. Construct new linter each
                # time, so config options don't bleed to unintended files.
                linter = reset_linter(config=local_config, file_linted=file_py)
                # Assume the local config will NOT set a new reporter.
                linter.set_reporter(current_reporter)
                current_reporter.register_file(file_py)
                linter.check(file_py)  # Lint !
                current_reporter.print_messages(level)
                current_reporter.reset_messages(
                )  # Clear lists for any next file.
                print(
                    '[INFO] File: {} was checked using the configuration file: {}'
                    .format(file_py, linter.config_file))
        current_reporter.output_blob()
        return current_reporter
    except Exception as e:
        print(
            '[ERROR] Unexpected error encountered! Please report this to your instructor (and attach the code that caused the error).'
        )
        print('[ERROR] Error message: "{}"'.format(e))
        raise e
示例#6
0
def _check(module_name='', level='all', local_config='', output=None):
    """Check a module for problems, printing a report.

    The `module_name` can take several inputs:
      - string of a directory, or file to check (`.py` extension optional).
      - list of strings of directories or files -- can have multiple.
      - no argument -- checks the python file containing the function call.
    `level` is used to specify which checks should be made.
    `local_config` is a dict of config options or string (config file name).
    `output` is an absolute path to capture pyta data output. Default std out.
    """
    MANAGER.clear_cache()

    # Add reporters to an internal pylint data structure, for use with setting
    # custom pyta options in a Tuple, before (re)setting reporter.
    for reporter in REPORTERS:
        VALIDATORS[reporter.__name__] = reporter
    linter = reset_linter(config=local_config)

    current_reporter = reset_reporter(linter, output)
    patch_all()  # Monkeypatch pylint (override certain methods)

    # Try to check file, issue error message for invalid files.
    try:
        for locations in _get_valid_files_to_check(current_reporter, module_name):
            for file_py in get_file_paths(locations):
                if not _verify_pre_check(file_py):
                    continue  # Check the other files
                # Load config file in user location. Construct new linter each
                # time, so config options don't bleed to unintended files.
                linter = reset_linter(config=local_config, file_linted=file_py)
                # Assume the local config will NOT set a new reporter.
                linter.set_reporter(current_reporter)
                current_reporter.register_file(file_py)
                linter.check(file_py)  # Lint !
                current_reporter.print_messages(level)
                current_reporter.reset_messages()  # Clear lists for any next file.
        current_reporter.output_blob()
        return current_reporter
    except Exception as e:
        print('[ERROR] Unexpected error encountered! Please report this to your instructor (and attach the code that caused the error).')
        print('[ERROR] Error message: "{}"'.format(e))
        raise e