def server_with_data(server, cloneable_with_commits): cfg = server.sandbox.gen_config(repo=cloneable_with_commits.path) main(('-C', cfg)) yield auto_namedtuple( server=server, cloneable_with_commits=cloneable_with_commits, )
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
def test_generate_integration_previous_data(sandbox, cloneable): main([cloneable, sandbox.db_path]) before_data_count = get_metric_data_count(sandbox) assert before_data_count > 0 main([cloneable, sandbox.db_path]) after_data_count = get_metric_data_count(sandbox) assert before_data_count == after_data_count
def test_generate_integration_previous_data(sandbox, cloneable): main([cloneable, sandbox.db_path]) before_data_count = get_metric_data_count(sandbox) assert before_data_count > 0 main([cloneable, sandbox.db_path]) after_data_count = get_metric_data_count(sandbox) assert before_data_count == after_data_count
def test_generate_integration_previous_data(sandbox, cloneable_with_commits): cfg = sandbox.gen_config(repo=cloneable_with_commits.path) main(('-C', cfg)) before_data_count = get_metric_data_count(sandbox) assert before_data_count > 0 main(('-C', cfg)) after_data_count = get_metric_data_count(sandbox) assert before_data_count == after_data_count
def test_generate_integration_previous_data(sandbox, cloneable_with_commits): cfg = sandbox.gen_config(repo=cloneable_with_commits.path) main(('-C', cfg)) before_data_count = get_metric_data_count(sandbox) assert before_data_count > 0 main(('-C', cfg)) after_data_count = get_metric_data_count(sandbox) assert before_data_count == after_data_count
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_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_generate_integration_config_file(sandbox, cloneable, tempdir_factory): tmpdir = tempdir_factory.get() config_filename = os.path.join(tmpdir, 'generate_config.yaml') with io.open(config_filename, 'w') as config_file: yaml.dump( {'repo': cloneable, 'database': sandbox.db_path}, stream=config_file, ) with cwd(tmpdir): main([])
def test_generate_integration_config_file(sandbox, cloneable, tempdir_factory): tmpdir = tempdir_factory.get() config_filename = os.path.join(tmpdir, 'generate_config.yaml') with io.open(config_filename, 'w') as config_file: yaml.dump( {'repo': cloneable, 'database': sandbox.db_path}, stream=config_file, ) with cwd(tmpdir): main([])
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
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
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)))
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
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)))
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
def test_exclude_pattern(sandbox, cloneable_with_commits): cfg = sandbox.gen_config( repo=cloneable_with_commits.path, exclude=r'\.tmpl$', ) assert not main(('-C', cfg)) 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 sha = ? AND name = "TotalLinesOfCode"\n') sha = cloneable_with_commits.commits[-1].sha val, = db_logic._fetch_one(query, (sha, )) # 2 lines of code from test.py, 0 lines from foo.tmpl (2 lines) assert val == 2
def test_exclude_pattern(sandbox, cloneable_with_commits): cfg = sandbox.gen_config( repo=cloneable_with_commits.path, exclude=r'\.tmpl$', ) assert not main(('-C', cfg)) 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 sha = ? AND name = "TotalLinesOfCode"\n' ) sha = cloneable_with_commits.commits[-1].sha val, = db.execute(query, (sha,)).fetchone() # 2 lines of code from test.py, 0 lines from foo.tmpl (2 lines) assert val == 2
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]
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]
def test_main_database_does_not_exist(sandbox, cloneable): new_db_path = os.path.join(sandbox.directory, 'new.db') cfg = sandbox.gen_config(database=new_db_path, repo=cloneable) assert not main(('-C', cfg)) assert os.path.exists(new_db_path)
def test_generate_integration(sandbox, cloneable): main(('-C', sandbox.gen_config(repo=cloneable)))
def test_main_no_files_exist(cloneable): ret = main([cloneable, 'i_dont_exist.db']) assert ret == 1
def test_generate_integration(sandbox, cloneable): main([cloneable, sandbox.db_path])
def test_main_no_files_exist(cloneable): ret = main([cloneable, 'i_dont_exist.db']) assert ret == 1
def server_with_data(server, cloneable_with_commits): main([cloneable_with_commits.path, server.sandbox.db_path]) yield auto_namedtuple(server=server, cloneable_with_commits=cloneable_with_commits)
def server_with_data(server, cloneable): main([cloneable, server.sandbox.db_path]) yield server
def test_generate_integration(sandbox, cloneable): main([cloneable, sandbox.db_path])
def test_main_database_does_not_exist(sandbox, cloneable): new_db_path = os.path.join(sandbox.directory, 'new.db') cfg = sandbox.gen_config(database=new_db_path, repo=cloneable) assert not main(('-C', cfg)) assert os.path.exists(new_db_path)
def server_with_data(server, cloneable_with_commits): main([cloneable_with_commits.path, server.sandbox.db_path]) yield auto_namedtuple( server=server, cloneable_with_commits=cloneable_with_commits, )
def test_generate_integration(sandbox, cloneable): main(('-C', sandbox.gen_config(repo=cloneable)))