コード例 #1
0
ファイル: hg.py プロジェクト: dcramer/quickunit
def parse_commit(parent=None):
    cmd = ['hg', 'diff']
    if parent:
        cmd.append('-r "%s"' % (parent,))

    proc = Popen(cmd, stdout=PIPE, stderr=STDOUT)
    diff = proc.stdout.read().strip()

    parser = DiffParser(diff)

    files = []
    for file in parser.parse():
        if file['is_header']:
            continue

        # file was removed
        if file['new_filename'] == '/dev/null':
            continue

        filename = file['new_filename'][2:]

        is_new = (file['old_filename'] == '/dev/null')

        files.append(ChangedFile(filename, is_new))

    return files
コード例 #2
0
ファイル: git.py プロジェクト: dcramer/quickunit
def parse_commit(parent=None):
    if parent is None:
        parent = 'master'

    proc = Popen(['git', 'merge-base', 'HEAD', parent], stdout=PIPE, stderr=STDOUT)

    parent_revision = proc.stdout.read().strip()

    # pull in our diff
    # git diff `git merge-base HEAD master`
    proc = Popen(['git', 'diff', parent_revision], stdout=PIPE, stderr=STDOUT)
    diff = proc.stdout.read().strip()

    parser = DiffParser(diff)

    files = []
    for file in parser.parse():
        if file['is_header']:
            continue

        # file was removed
        if file['new_filename'] == '/dev/null':
            continue

        filename = file['new_filename'][2:]

        is_new = (file['old_filename'] == '/dev/null')

        files.append(ChangedFile(filename, is_new))

    return files
コード例 #3
0
    def begin(self):
        # XXX: this is pretty hacky
        if self.verbosity > 1:
            self.logger.info("Parsing parent commit..")
        proc = Popen(['git', 'merge-base', 'HEAD', self.parent],
                     stdout=PIPE,
                     stderr=STDOUT)
        self.parent_revision = proc.stdout.read().strip()
        if self.verbosity > 1:
            self.logger.info("Parent commit identified as %s",
                             self.parent_revision)

        # pull in our diff
        # git diff `git merge-base HEAD master`
        if self.verbosity > 1:
            self.logger.info("Parsing diff..")
        proc = Popen(['git', 'diff', self.parent_revision],
                     stdout=PIPE,
                     stderr=STDOUT)
        diff = proc.stdout.read().strip()

        parser = DiffParser(diff)
        files = list(parser.parse())

        diff = self.diff_data
        for file in files:
            # we dont care about headers
            if file['is_header']:
                continue

            # file was removed
            if file['new_filename'] == '/dev/null':
                continue

            is_new_file = (file['old_filename'] == '/dev/null')
            if is_new_file:
                filename = file['new_filename']
                if not filename.startswith('b/'):
                    continue
            else:
                filename = file['old_filename']
                if not filename.startswith('a/'):
                    continue  # ??

            filename = filename[2:]

            if self.file_cache.root is None:
                self.file_cache.root = os.path.abspath(
                    filename)[:-len(filename)]

            # Ignore non python files
            if not is_py_script(filename):
                continue

            new_filename = file['new_filename'][2:]

            # file is new, only record diff state
            for chunk in file['chunks']:
                linenos = filter(bool,
                                 (l['new_lineno'] for l in chunk if l['line']))
                diff[new_filename].update(linenos)

            if is_new_file:
                continue

            for prefix in self.prefixes:
                self.pending_files.add(
                    os.path.join(prefix,
                                 new_filename.rsplit('.', 1)[0]))

        if self.verbosity > 1:
            self.logger.info(
                "Found %d changed file(s) and %d possible test paths..",
                len(diff), len(self.pending_files))
コード例 #4
0
ファイル: plugin.py プロジェクト: msabramo/nose-quickunit
    def begin(self):
        # If we're recording coverage we need to ensure it gets reset
        self.coverage = self._setup_coverage()

        # XXX: this is pretty hacky
        if self.verbosity > 1:
            self.logger.info("Parsing parent commit..")
        proc = Popen(['git', 'merge-base', 'HEAD', self.parent], stdout=PIPE, stderr=STDOUT)
        self.parent_revision = proc.stdout.read().strip()
        if self.verbosity > 1:
            self.logger.info("Parent commit identified as %s", self.parent_revision)

        # pull in our diff
        # git diff `git merge-base HEAD master`
        if self.verbosity > 1:
            self.logger.info("Parsing diff..")
        proc = Popen(['git', 'diff', self.parent_revision], stdout=PIPE, stderr=STDOUT)
        diff = proc.stdout.read().strip()

        parser = DiffParser(diff)
        files = list(parser.parse())

        diff = self.diff_data
        for file in files:
            # we dont care about headers
            if file['is_header']:
                continue

            # file was removed
            if file['new_filename'] == '/dev/null':
                continue

            is_new_file = (file['old_filename'] == '/dev/null')
            if is_new_file:
                filename = file['new_filename']
                if not filename.startswith('b/'):
                    continue
            else:
                filename = file['old_filename']
                if not filename.startswith('a/'):
                    continue  # ??

            filename = filename[2:]

            if self.root is None:
                self.root = os.path.abspath(filename)[:-len(filename)]

            # Ignore non python files
            if not is_py_script(filename):
                continue

            new_filename = file['new_filename'][2:]

            # file is new, only record diff state
            for chunk in file['chunks']:
                linenos = filter(bool, (l['new_lineno'] for l in chunk if l['line']))
                diff[new_filename].update(linenos)

            # we dont care about missing coverage for new code, and there
            # wont be any "existing coverage" to check for
            if is_new_file:
                continue

            for prefix in self.prefixes:
                self.pending_files.add(os.path.join(prefix, new_filename.rsplit('.', 1)[0]))

        self.tests_run = set()

        if self.verbosity > 1:
            self.logger.info("Found %d changed file(s) and %d possible test paths..", len(diff), len(self.pending_files))