Return a float percent of lines covered for the source
        in `src_path`.

        If we have no coverage information for `src_path`, returns None
772266
def percent_covered(self, src_path):
        
        diff_violations = self._diff_violations().get(src_path)

        if diff_violations is None:
            return None

        # Protect against a divide by zero
        num_measured = len(diff_violations.measured_lines)
        if num_measured > 0:
            num_uncovered = len(diff_violations.lines)
            return 100 - float(num_uncovered) / num_measured * 100

        else:
            return None
1180475
def individual_report(coverage_path, current_project_path)
      if File.exist? coverage_path
        committed_files = git.modified_files + git.added_files

        unless current_project_path.nil?
          committed_files = committed_files.map do |s|
            current_project_path + '/' + s
          end
        end

        covered_files = JSON.parse(File.read(coverage_path), symbolize_names: true)[:files]
                            .select { |f| committed_files.include?(f[:filename]) }

        unless current_project_path.nil?
          covered_files.each { |f| f[:filename].sub!(%r{^#{current_project_path}/?}, '') }
        end

        return if covered_files.nil? || covered_files.empty?
        markdown individual_coverage_message(covered_files)
      else
        fail('Code coverage data not found')
      end
    end
646551
def stat(self, path):
        
        try:
            stat = self.exists(str(path))
        except (NoNodeError, NoAuthError):
            stat = None
        return stat
315348
def global_unlock_percent(self):
        
        percent = CRef.cfloat()
        result = self._iface.get_ach_progress(self.name, percent)

        if not result:
            return 0.0

        return float(percent)
676721
def get_percentage_from_prob(prob):
    
    assert isinstance(prob, (float, int))
    prob = float(prob)
    assert prob >= 0
    assert prob <= 1

    percentages = list(probability_list.keys())
    percentages.sort()
    for percentage in percentages:
        if prob < probability_list[percentage]:
            return percentage - 1
    return 100
459773
def repercent_broken_unicode(path):
    
    # originally from django.utils.encoding
    while True:
        try:
            return path.decode('utf-8')
        except UnicodeDecodeError as e:
            repercent = quote(path[e.start:e.end], safe=b"/#%[]=:;$&()+,!?*@'~")
            path = path[:e.start] + repercent.encode('ascii') + path[e.end:]
867189
def collect_modules(self):
        
        coverage_dir = os.path.join(self.root, 'cover')
        for name in fnmatch.filter(os.listdir(coverage_dir), "*.html"):
                if name == 'index.html':
                    continue
                with open(os.path.join(coverage_dir, name)) as cover_file:
                    src_file, line_ranges = self.determine_coverage(cover_file)
                if not src_file:
                    continue
                src_file = os.path.abspath(os.path.join(self.root, src_file))
                if os.path.isfile(src_file):
                    yield (src_file, line_ranges)
                else:
                    raise SourceNotFound(
                        "Source file %(file)s not found at %(area)s" %
                        {'file': os.path.basename(src_file),
                         'area': os.path.dirname(src_file)})
632224
function( data ) {
        var ret = {
            coverage: 0,
            hits: 0,
            misses: 0,
            sloc: 0
        };
        for (var i = 0; i < data.source.length; i++) {
            var line = data.source[i];
            var num = i + 1;
            if (data[num] === 0) {
                ret.misses++;
                ret.sloc++;
            } else if (data[num] !== undefined) {
                ret.hits++;
                ret.sloc++;
            }
        }
        ret.coverage = ret.hits / ret.sloc * 100;

        return [ret.hits,ret.sloc];

    }
33534
def coverage_path
      @coverage_path ||= begin
        coverage_path = File.expand_path(coverage_dir, root)
        FileUtils.mkdir_p coverage_path
        coverage_path
      end
    end
342967
def wraith_percentage(file, browser_output)
        file_object = File.open(file, 'rb')
        browser_output[:percent_changed] ||= {}
        browser_output[:percent_changed][File.basename(file).split('_')[0].to_i] = file_object.read.to_f

        file_object.close

        browser_output
      end
1042972
def get(self):
        """"""
        ret = sparklines(self.percents)[0]
        if self.__with_text:
            percents_without_none = [x for x in self.percents if x is not None]
            if len(percents_without_none) > 0:
                ret = '{}{:5.1f}%'.format(ret, percents_without_none[-1])
        return nativestr(ret)
30741
def mangle_coverage(local_path, log):
    
    # Read the file, or return if not a .coverage file.
    with open(local_path, mode='rb') as handle:
        if handle.read(13) != b'!coverage.py:':
            log.debug('File %s not a coverage file.', local_path)
            return
        handle.seek(0)

        # I'm lazy, reading all of this into memory. What could possibly go wrong?
        file_contents = handle.read(52428800).decode('utf-8')  # 50 MiB limit, surely this is enough?

    # Substitute paths.
    for windows_path in set(REGEX_MANGLE.findall(file_contents)):
        unix_relative_path = windows_path.replace(r'\\', '/').split('/', 3)[-1]
        unix_absolute_path = os.path.abspath(unix_relative_path)
        if not os.path.isfile(unix_absolute_path):
            log.debug('Windows path: %s', windows_path)
            log.debug('Unix relative path: %s', unix_relative_path)
            log.error('No such file: %s', unix_absolute_path)
            raise HandledError
        file_contents = file_contents.replace(windows_path, unix_absolute_path)

    # Write.
    with open(local_path, 'w') as handle:
        handle.write(file_contents)
590404
def lstat(path):
    '''
    
    '''
    path = os.path.expanduser(path)

    if not os.path.isabs(path):
        raise SaltInvocationError('Path to file must be absolute.')

    try:
        lst = os.lstat(path)
        return dict((key, getattr(lst, key)) for key in ('st_atime', 'st_ctime',
            'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'))
    except Exception:
        return {}
510029
def _get_src_path_line_nodes_clover(self, xml_document, src_path):
        

        files = [file_tree
                 for file_tree in xml_document.findall(".//file")
                 if GitPathTool.relative_path(file_tree.get('path')) == src_path
                 or []]
        if not files:
            return None
        lines = [file_tree.findall('./line[@type="stmt"]')
                 for file_tree in files]
        return [elem for elem in itertools.chain(*lines)]
223955
def get_noqa_suppressions(file_contents):
    
    ignore_whole_file = False
    ignore_lines = set()
    for line_number, line in enumerate(file_contents):
        if _FLAKE8_IGNORE_FILE.search(line):
            ignore_whole_file = True
        if _PEP8_IGNORE_LINE.search(line):
            ignore_lines.add(line_number + 1)
    return ignore_whole_file, ignore_lines
1159555
def _walk_src(self, targets, flags, pipeline):
        """"""

        for target in targets:
            for f in glob.iglob(target, flags=flags | glob.S):
                if not os.path.isdir(f):
                    self.log('', 2)
                    self.log('> Processing: %s' % f, 1)
                    if pipeline:
                        try:
                            yield pipeline[0]._run_first(f)
                        except Exception as e:
                            err = self.get_error(e)
                            yield [filters.SourceText('', f, '', '', err)]
                    else:
                        try:
                            if self.default_encoding:
                                encoding = filters.PYTHON_ENCODING_NAMES.get(
                                    self.default_encoding, self.default_encoding
                                ).lower()
                                encoding = codecs.lookup(encoding).name
                            else:
                                encoding = self.default_encoding
                            yield [filters.SourceText('', f, encoding, 'file')]
                        except Exception as e:
                            err = self.get_error(e)
                            yield [filters.SourceText('', f, '', '', err)]
968056
def add_missing_covered_codes
      top_level_path = DeepCover.config.paths.detect do |path|
        next unless path.is_a?(String)
        path = File.expand_path(path)
        File.dirname(path) == path
      end
      if top_level_path
        # One of the paths is a root path.
        # Either a mistake, or the user wanted to check everything that gets loaded. Either way,
        # we will probably hang from searching the files to load. (and then loading them, as there
        # can be lots of ruby files) We prefer to warn the user and not do anything.
        suggestion = "#{top_level_path}/**/*.rb"
        warn ["Because the `paths` configured in DeepCover include #{top_level_path.inspect}, which is a root of your fs, ",
              'DeepCover will not attempt to find Ruby files that were not required. Your coverage report will not include ',
              'files that were not instrumented. This is to avoid extremely long wait times. If you actually want this to ',
              "happen, then replace the specified `paths` with #{suggestion.inspect}.",
             ].join
        return
      end

      DeepCover.all_tracked_file_paths.each do |path|
        covered_code(path, tracker_hits: :zeroes)
      end
      nil
    end