예제 #1
0
def test_regression_for_issue_10(sandbox, cloneable):
    # Create a commit, then create another commit at a previous time
    with cwd(cloneable):
        cmd_output(
            'git',
            'commit',
            '--allow-empty',
            '-m',
            'c1',
            env=dict(
                os.environ,
                GIT_COMMITTER_DATE='Wed, Feb 16 14:00 2011 +0100',
            ),
        )
        cmd_output(
            'git',
            'commit',
            '--allow-empty',
            '-m',
            'c2',
            env=dict(
                os.environ,
                GIT_COMMITTER_DATE='Tue, Feb 15 14:00 2011 +0100',
            ),
        )

    cfg = sandbox.gen_config(repo=cloneable)
    main(('-C', cfg))
    data_count_before = get_metric_data_count(sandbox)
    # Used to raise IntegrityError
    main(('-C', cfg))
    data_count_after = get_metric_data_count(sandbox)
    assert data_count_before == data_count_after
예제 #2
0
def test_generate_new_data_created(sandbox, cloneable):
    main([cloneable, sandbox.db_path])
    before_data_count = get_metric_data_count(sandbox)
    # Add some commits
    with cwd(cloneable):
        cmd_output('git', 'commit', '--allow-empty', '-m', 'bar')
    main([cloneable, sandbox.db_path])
    after_data_count = get_metric_data_count(sandbox)
    assert after_data_count > before_data_count
예제 #3
0
def test_generate_new_data_created(sandbox, cloneable):
    main([cloneable, sandbox.db_path])
    before_data_count = get_metric_data_count(sandbox)
    # Add some commits
    with cwd(cloneable):
        cmd_output('git', 'commit', '--allow-empty', '-m', 'bar')
    main([cloneable, sandbox.db_path])
    after_data_count = get_metric_data_count(sandbox)
    assert after_data_count > before_data_count
def test_raises_on_nonzero():
    cmd = ('sh', '-c', 'echo "stderr" >&2 && echo "stdout" && exit 1')
    with pytest.raises(CalledProcessError) as exc_info:
        cmd_output(*cmd)

    assert exc_info.value.args == (
        cmd,
        1,
        b'stdout\n',
        b'stderr\n',
    )
예제 #5
0
def test_generate_new_data_created(sandbox, cloneable_with_commits):
    cfg = sandbox.gen_config(repo=cloneable_with_commits.path)
    main(('-C', cfg))
    before_data_count = get_metric_data_count(sandbox)
    # Add some commits
    with cwd(cloneable_with_commits.path):
        with open('new_file.py', 'w') as f:
            f.write('# test\n')
        cmd_output('git', 'add', 'new_file.py')
        cmd_output('git', 'commit', '-m', 'bar')
    main(('-C', cfg))
    after_data_count = get_metric_data_count(sandbox)
    assert after_data_count > before_data_count
예제 #6
0
def test_generate_new_data_created(sandbox, cloneable_with_commits):
    cfg = sandbox.gen_config(repo=cloneable_with_commits.path)
    main(('-C', cfg))
    before_data_count = get_metric_data_count(sandbox)
    # Add some commits
    with cwd(cloneable_with_commits.path):
        with open('new_file.py', 'w') as f:
            f.write('# test\n')
        cmd_output('git', 'add', 'new_file.py')
        cmd_output('git', 'commit', '-m', 'bar')
    main(('-C', cfg))
    after_data_count = get_metric_data_count(sandbox)
    assert after_data_count > before_data_count
예제 #7
0
 def get_commit_diff(self, previous_sha, sha):
     assert self.tempdir
     output = cmd_output(
         'git', 'diff', previous_sha, sha, '--no-renames',
         cwd=self.tempdir, encoding=None,
     )
     return output
예제 #8
0
    def get_commit(self, sha):
        output = cmd_output(
            'git', 'show', COMMIT_FORMAT, sha, cwd=self.tempdir,
        )
        sha, date = output.splitlines()[:2]

        return Commit(sha, int(date))
예제 #9
0
    def get_commit(self, sha: str) -> Commit:
        output = cmd_output(
            'git', 'show', COMMIT_FORMAT, sha, cwd=self.tempdir,
        )
        sha, date = output.splitlines()[:2]

        return Commit(sha, int(date))
예제 #10
0
def test_moves_handled_properly(sandbox, cloneable):
    with cwd(cloneable):
        with io.open('f', 'w') as f:
            f.write('foo\nbar\nbaz\n')
        cmd_output('git', 'add', 'f')
        cmd_output('git', 'commit', '-m', 'add f')
        cmd_output('git', 'mv', 'f', 'g')
        cmd_output('git', 'commit', '-m', 'move f to g')

    # Used to raise AssertionError
    assert main((cloneable, sandbox.db_path)) is None
예제 #11
0
def test_moves_handled_properly(sandbox, cloneable):
    with cwd(cloneable):
        with io.open('f', 'w') as f:
            f.write('foo\nbar\nbaz\n')
        cmd_output('git', 'add', 'f')
        cmd_output('git', 'commit', '-m', 'add f')
        cmd_output('git', 'mv', 'f', 'g')
        cmd_output('git', 'commit', '-m', 'move f to g')

    # Used to raise AssertionError
    assert not main(('-C', sandbox.gen_config(repo=cloneable)))
예제 #12
0
def test_moves_handled_properly(sandbox, cloneable):
    with cwd(cloneable):
        with io.open('f', 'w') as f:
            f.write('foo\nbar\nbaz\n')
        cmd_output('git', 'add', 'f')
        cmd_output('git', 'commit', '-m', 'add f')
        cmd_output('git', 'mv', 'f', 'g')
        cmd_output('git', 'commit', '-m', 'move f to g')

    # Used to raise AssertionError
    assert not main(('-C', sandbox.gen_config(repo=cloneable)))
예제 #13
0
def test_internal_zero_populated(sandbox, cloneable):
    with cwd(cloneable):
        with io.open('f.py', 'w') as f:
            f.write('# hello world\n')
        cmd_output('git', 'add', 'f.py')
        cmd_output('git', 'commit', '-m', 'add f')
        cmd_output('git', 'rm', 'f.py')
        cmd_output('git', 'commit', '-m', 'remove f')
        cmd_output('git', 'revert', 'HEAD', '--no-edit')

    assert not main(('-C', sandbox.gen_config(repo=cloneable)))
    with sandbox.db_logic() as db_logic:
        query = ('SELECT running_value\n'
                 'FROM metric_data\n'
                 'INNER JOIN metric_names ON\n'
                 '    metric_data.metric_id == metric_names.id\n'
                 'WHERE name = "TotalLinesOfCode_python"\n')
        vals = [x for x, in db_logic._fetch_all(query)]
        assert vals == [1, 0, 1]
예제 #14
0
 def append_commit():
     output = cmd_output(
         'hg',
         'log',
         '--template={node}\n{word(0, date, \".\")}\n',
         '--rev',
         '.',
     )
     sha, date = output.splitlines()[:2]
     commits.append(Commit(sha, int(date)))
예제 #15
0
 def get_original_commit(self, sha):
     assert self.tempdir
     output = cmd_output(
         'git',
         'show',
         sha,
         cwd=self.tempdir,
         encoding=None,
     )
     return output
예제 #16
0
 def get_commit_diff(self, previous_sha, sha):
     assert self.tempdir
     output = cmd_output(
         'git',
         'diff',
         previous_sha,
         sha,
         cwd=self.tempdir,
         encoding=None,
     )
     return output
예제 #17
0
def test_internal_zero_populated(sandbox, cloneable):
    with cwd(cloneable):
        with io.open('f.py', 'w') as f:
            f.write('# hello world\n')
        cmd_output('git', 'add', 'f.py')
        cmd_output('git', 'commit', '-m', 'add f')
        cmd_output('git', 'rm', 'f.py')
        cmd_output('git', 'commit', '-m', 'remove f')
        cmd_output('git', 'revert', 'HEAD', '--no-edit')

    assert not main(('-C', sandbox.gen_config(repo=cloneable)))
    with sandbox.db() as db:
        query = (
            'SELECT running_value\n'
            'FROM metric_data\n'
            'INNER JOIN metric_names ON\n'
            '    metric_data.metric_id == metric_names.id\n'
            'WHERE name = "TotalLinesOfCode_python"\n'
        )
        vals = [x for x, in db.execute(query).fetchall()]
        assert vals == [1, 0, 1]
예제 #18
0
def test_regression_for_issue_10(sandbox, cloneable):
    # Create a commit, then create another commit at a previous time
    with cwd(cloneable):
        cmd_output(
            'git', 'commit', '--allow-empty', '-m', 'c1',
            env=dict(
                os.environ, GIT_COMMITTER_DATE='Wed, Feb 16 14:00 2011 +0100',
            ),
        )
        cmd_output(
            'git', 'commit', '--allow-empty', '-m', 'c2',
            env=dict(
                os.environ, GIT_COMMITTER_DATE='Tue, Feb 15 14:00 2011 +0100',
            ),
        )

    main([cloneable, sandbox.db_path])
    data_count_before = get_metric_data_count(sandbox)
    # Used to raise IntegrityError
    main([cloneable, sandbox.db_path])
    data_count_after = get_metric_data_count(sandbox)
    assert data_count_before == data_count_after
예제 #19
0
    def get_commits(self, since_sha: Optional[str] = None) -> List[Commit]:
        """Returns a list of Commit objects.

        Args:
           since_sha - (optional) A sha to search from
        """
        assert self.tempdir

        cmd = ['git', 'log', '--first-parent', '--reverse', COMMIT_FORMAT]
        if since_sha:
            commits = [self.get_commit(since_sha)]
            cmd.append(f'{since_sha}..HEAD')
        else:
            commits = []
            cmd.append('HEAD')

        output = cmd_output(*cmd, cwd=self.tempdir)

        for sha, date in chunk_iter(output.splitlines(), 2):
            commits.append(Commit(sha, int(date)))

        return commits
예제 #20
0
    def get_commits(self, since_sha=None):
        """Returns a list of Commit objects.

        Args:
           since_sha - (optional) A sha to search from
        """
        assert self.tempdir

        cmd = ['git', 'log', '--first-parent', '--reverse', COMMIT_FORMAT]
        if since_sha:
            commits = [self.get_commit(since_sha)]
            cmd.append('{0}..HEAD'.format(since_sha))
        else:
            commits = []
            cmd.append('HEAD')

        output = cmd_output(*cmd, cwd=self.tempdir)

        for sha, date in chunk_iter(output.splitlines(), 2):
            commits.append(Commit(sha, int(date)))

        return commits
예제 #21
0
def test_subprocess_encoding():
    # Defaults to utf-8
    ret = cmd_output('echo', '☃')
    assert type(ret) is str
    assert ret == '☃\n'
def test_subprocess_encoding():
    # Defaults to utf-8
    ret = cmd_output('echo', '☃'.encode('UTF-8'))
    assert type(ret) is five.text
    assert ret == '☃\n'
예제 #23
0
 def get_original_commit(self, sha):
     assert self.tempdir
     output = cmd_output(
         'git', 'show', sha, cwd=self.tempdir, encoding=None,
     )
     return output
def test_no_encoding_gives_bytes():
    ret = cmd_output('echo', '☃'.encode('UTF-8'), encoding=None)
    assert type(ret) is bytes
    assert ret == '☃\n'.encode('UTF-8')
예제 #25
0
 def get_commit_diff(self, previous_sha, sha):
     assert self.tempdir
     output = cmd_output("git", "diff", previous_sha, sha, cwd=self.tempdir, encoding=None)
     return output
예제 #26
0
 def append_commit():
     output = cmd_output('git', 'show', COMMIT_FORMAT)
     sha, date = output.splitlines()[:2]
     commits.append(Commit(sha, int(date)))
예제 #27
0
 def append_commit():
     output = cmd_output('git', 'show', COMMIT_FORMAT)
     sha, date = output.splitlines()[:2]
     commits.append(Commit(sha, int(date)))
예제 #28
0
 def get_original_commit(self, sha):
     assert self.tempdir
     output = cmd_output("git", "show", sha, cwd=self.tempdir, encoding=None)
     return output