Exemplo n.º 1
0
def test_delete_cascade():
    db_url = 'postgresql://*****:*****@localhost:5432/author_del_cascade'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    repo1 = Repository('repo/terrame')
    person = Person('dev1', '*****@*****.**')
    author1 = Author(person, repo1)

    repo2 = Repository('repo/ca')
    author2 = Author(person, repo2)

    assert author2.id is None

    session = db.create_session()
    session.add(author1)
    session.commit()

    assert author2.id is not None

    authorsdb = session.query(Author).all()

    assert len(authorsdb) == 2

    session.delete(person)
    session.commit()

    authorsdb = session.query(Author).all()

    assert len(authorsdb) == 0

    session.close()
    db.drop_all()
Exemplo n.º 2
0
def test_same_person_in_two_repos():
    db_url = 'postgresql://*****:*****@localhost:5432/author_two_repos'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    repo1 = Repository('repo/terrame')
    person = Person('dev1', '*****@*****.**')
    author1 = Author(person, repo1)

    repo2 = Repository('repo/ca')
    author2 = Author(person, repo2)

    assert author2.id is None

    session = db.create_session()
    session.add(author1)
    session.commit()

    assert author2.id is not None

    authorsdb = session.query(Author).all()

    assert len(authorsdb) == 2
    assert authorsdb[0].person == authorsdb[1].person
    assert authorsdb[0].repository != authorsdb[1].repository

    session.close()
    db.drop_all()
Exemplo n.º 3
0
def test_add_same_code_element():
	db_url = 'postgresql://*****:*****@localhost:5432/src_add_same'	
	db = SQLAlchemyORM(db_url)
	db.create_all(True)

	filepath = 'some/path/file.src'
	file = File(filepath)
	src_file = SourceFile(file)

	f1 = Operation('get', src_file)
	src_file.add_code_element(f1)

	session = db.create_session()
	session.add(src_file)
	session.commit()	

	src_filedb = session.query(SourceFile).one()
	f2 = Operation('get', src_filedb)

	with pytest.raises(Exception) as e:
		src_filedb.add_code_element(f2)
	assert (('Code element \'get\' of type \'Operation\' is already present')
			in str(e.value))
	session.close()
	db.drop_all()	 	
Exemplo n.º 4
0
def test_system_crud():
    db_url = 'postgresql://*****:*****@localhost:5432/system_crud'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    # create
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)

    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.commit()

    # read
    sysdb = session.query(System).get(1)
    assert sys.name == sysdb.name
    assert sys.repository.path == sysdb.repository.path

    # update
    sys.name = 'TerraME-2.0'
    session.commit()
    sysdb = session.query(System).get(1)
    assert sysdb.name == sys.name

    # delete
    session.delete(sys)
    session.commit()
    sysdb = session.query(System).get(1)
    repodb = session.query(Repository).get(1)
    assert sysdb is None
    assert repodb.path == repo.path

    session.close()
    db.drop_all()
Exemplo n.º 5
0
def test_extract_same_commit():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_rename_file'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.commit()
    miner = RepositoryMiner(repo, sys)

    miner.extract(session, '082dff5e822ea1b4491911b7bf434a7f47a4be26')
    file_count = session.query(File).count()
    srcfile_count = session.query(SourceFile).count()
    mod_count = session.query(Modification).count()

    # TODO(#41) miner.extract(session, '082dff5e822ea1b4491911b7bf434a7f47a4be26')

    assert file_count == session.query(File).count()
    assert srcfile_count == session.query(SourceFile).count()
    assert mod_count == session.query(Modification).count()

    session.close()
    db.drop_all()
Exemplo n.º 6
0
def test_extract_renamed_files():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_rename_file'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.commit()
    miner = RepositoryMiner(repo, sys)

    miner.extract(session, '082dff5e822ea1b4491911b7bf434a7f47a4be26')
    file = session.query(File).filter_by(
        fullpath='base/lua/Observer.lua').one()
    mod = session.query(Modification).filter_by(file_id=file.id).first()

    assert mod.new_path == 'base/lua/Observer.lua'
    assert mod.old_path is None
    assert mod.status == 'ADD'
    assert sys.file_exists('base/lua/Observer.lua')

    miner.extract(session, 'c57b6d69461abf10ba5950e0577dff3c982f3ea4')
    file = session.query(File).filter_by(fullpath='src/lua/observer.lua').one()
    mod = session.query(Modification).filter_by(file_id=file.id)\
      .filter_by(status='RENAME').first()

    assert mod.new_path == 'src/lua/observer.lua'
    assert mod.old_path == 'base/lua/Observer.lua'
    assert mod.status == 'RENAME'
    assert sys.file_exists('src/lua/observer.lua')
    assert sys.file_exists('base/lua/Observer.lua')

    session.close()
    db.drop_all()
Exemplo n.º 7
0
def test_extract_deleted_files():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_del_files'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.commit()
    miner = RepositoryMiner(repo, sys)

    miner.extract(session, '082dff5e822ea1b4491911b7bf434a7f47a4be26')
    file = session.query(File).filter_by(fullpath='src/lua/terrame.lua').one()
    mod = session.query(Modification).filter_by(file_id=file.id).first()

    assert mod.new_path == 'src/lua/terrame.lua'
    assert mod.old_path is None
    assert mod.status == 'ADD'
    assert sys.file_exists('src/lua/terrame.lua')

    miner.extract(session, 'f2e117598feee9db8cabbd1c300e143199e12d92')
    file = session.query(File).filter_by(fullpath='src/lua/terrame.lua').one()
    mod = session.query(Modification).filter_by(file_id=file.id)\
      .filter_by(status='DELETE').first()

    assert mod.new_path is None
    assert mod.old_path == 'src/lua/terrame.lua'
    assert mod.status == 'DELETE'
    assert sys.file_exists('src/lua/terrame.lua')

    session.close()
    db.drop_all()
Exemplo n.º 8
0
def test_add_source_file():
    db_url = 'postgresql://*****:*****@localhost:5432/sys_add_src_file'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    repo = Repository('repo/terrame')
    sys = System('terrame', repo)

    session = db.create_session()
    session.add(repo)
    session.add(sys)

    file1 = File('path/file1.ext')
    src1 = SourceFile(file1)
    sys.add_source_file(src1)

    session.commit()

    sysdb = session.query(System).get(1)
    src1db = sysdb.get_source_file(file1.fullpath)
    assert src1db.file.fullpath == src1.file.fullpath
    assert src1db.ext == src1.file.ext

    session.close()
    db.drop_all()
Exemplo n.º 9
0
def test_make_relations():
	db_url = 'postgresql://*****:*****@localhost:5432/ecolyzer_relations'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)
	session = db.create_session()

	repo1 = Repository('repo/terrame')
	sys1 = System('terrame', repo1)

	session.add(repo1)
	session.add(sys1)

	miner = RepositoryMiner(repo1, sys1)
	git = GitPython(repo1.path)
	hashs1 = git.commit_hashs_reverse(10)
	for hash in hashs1:
		miner.extract(session, hash)

	repo2 = Repository('repo/ca')
	sys2 = System('ca', repo2)

	miner = RepositoryMiner(repo2, sys2)
	git = GitPython(repo2.path)
	hashs2 = git.commit_hashs_reverse(10)
	for hash in hashs2:
		miner.extract(session, hash)
	
	ecosystem = Ecosystem()

	ecolyzer = EcosystemAnalyzer(ecosystem)
	ecolyzer.make_relations(sys2, sys1, session)

	relationships = ecosystem.relationships

	assert len(relationships) == 292

	rel1 = relationships[0]
	rel2 = relationships[291]

	assert rel1.from_system.name == 'ca'
	assert rel1.from_author.name == 'Pedro Andrade'
	assert rel1.from_author.email == '*****@*****.**'
	assert rel1.to_system.name == 'terrame'
	assert rel1.to_author.name == 'rvmaretto'	
	assert rel1.to_author.email == '*****@*****.**'	
	assert rel1.from_code_element.name == rel1.to_code_element.name == 'notify'
	assert rel1.from_code_element_count == 1
	
	assert rel2.from_system.name == 'ca'
	assert rel2.from_author.name == 'Pedro Andrade'
	assert rel2.from_author.email == '*****@*****.**'	
	assert rel2.to_system.name == 'terrame'
	assert rel2.to_author.name == 'rvmaretto'	
	assert rel2.to_author.email == '*****@*****.**'	
	assert rel2.from_code_element.name == rel2.to_code_element.name == 'type'
	assert rel2.from_code_element_count == 1

	session.close()
	db.drop_all()
Exemplo n.º 10
0
def test_relations_last_commits():
	db_url = 'postgresql://*****:*****@localhost:5432/ecolyzer_relations_last'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)
	session = db.create_session()

	repo1 = Repository('repo/terrame')
	sys1 = System('terrame', repo1)

	session.add(repo1)
	session.add(sys1)

	miner = RepositoryMiner(repo1, sys1)
	miner.add_ignore_dir_with('test')
	miner.add_ignore_dir_with('example')	
	miner.extract_last_commits(session, '2.0-RC-8')

	repo2 = Repository('repo/ca')
	sys2 = System('ca', repo2)

	miner = RepositoryMiner(repo2, sys2)	
	miner.extract_last_commits(session)
	
	ecosystem = Ecosystem()

	ecolyzer = EcosystemAnalyzer(ecosystem)
	ecolyzer.make_relations(sys2, sys1, session)

	relationships = ecosystem.relationships

	assert len(relationships) == 531

	rel1 = relationships[0]
	rel2 = relationships[530]

	assert rel1.from_system.name == 'ca'
	assert rel1.from_author.name == 'Pedro Andrade'
	assert rel1.from_author.email == '*****@*****.**'
	assert rel1.to_system.name == 'terrame'
	assert rel1.to_author.name == 'wsenafranca'	
	assert rel1.to_author.email == '*****@*****.**'	
	assert rel1.from_code_element.name == rel1.to_code_element.name == 'run'
	assert rel1.from_code_element_count == 1
	
	assert rel2.from_system.name == 'ca'
	assert rel2.from_author.name == 'Pedro Andrade'
	assert rel2.from_author.email == '*****@*****.**'	
	assert rel2.to_system.name == 'terrame'
	assert rel2.to_author.name == 'Pedro Andrade'	
	assert rel2.to_author.email == '*****@*****.**'	
	assert rel2.from_code_element.name == rel2.to_code_element.name == 'assertSnapshot'	
	assert rel2.from_code_element_count == 1

	session.close()
	db.drop_all()	
Exemplo n.º 11
0
def test_source_file_crud():
	db_url = 'postgresql://*****:*****@localhost:5432/src_file_crud'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)

	# create
	filepath = 'some/path/file.src'
	file = File(filepath)
	src_file = SourceFile(file)
	f1 = Operation('get', src_file)
	f2 = Operation('add', src_file)
	c1 = Call('call', src_file)	
	src_file.add_code_element(f1)
	src_file.add_code_element(f2)
	src_file.add_code_element(c1)

	session = db.create_session()
	session.add(file)
	session.commit()

	# read
	src_filedb = session.query(SourceFile).get(1)
	assert src_filedb.file_id == file.id
	assert src_filedb.file.ext == file.ext
	assert src_filedb.code_element_by_key(f1.key)
	assert src_filedb.code_element_by_key(f2.key)
	assert src_filedb.code_element_by_key(c1.key)

	# update
	file.ext = 'crs'
	f3 = Operation('update', src_file)
	session.add(f3)
	session.commit()
	src_filedb = session.query(SourceFile).get(1)
	code_elements = session.query(Operation).filter_by(source_file_id=src_filedb.id).all()	
	assert src_filedb.file.ext == file.ext
	assert len(code_elements) == 3

	# delete
	session.delete(src_file)
	session.commit()
	src_filedb = session.query(SourceFile).get(1)
	filedb = session.query(File).get(1)
	funcsdb = session.query(Operation).all()
	assert src_filedb is None
	assert filedb.name == 'file'
	assert len(funcsdb) == 0

	session.close()
	db.drop_all()
Exemplo n.º 12
0
def test_extract_current_files():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_curr_files'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    miner = RepositoryMiner(repo, sys)
    miner.add_ignore_dir_with('test')
    miner.add_ignore_dir_with('example')

    session = db.create_session()
    miner.extract_current_files(session)

    session.close()
    db.drop_all()
Exemplo n.º 13
0
def test_crud():
	db_url = 'postgresql://*****:*****@localhost:5432/central_system_crud'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)	

	# create
	repo = Repository('repo/terrame')
	sys = System('terrame', repo)
	central = CentralSystem(sys)

	session = db.create_session()	
	session.add(central)
	session.commit()

	session.close()
	db.drop_all()	
Exemplo n.º 14
0
def test_no_relationships():	
	db_url = 'postgresql://*****:*****@localhost:5432/scribejava_ecosystem'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)	

	repo_url = 'https://github.com/scribejava/scribejava'
	uc = MappingEcosystemDependents(repo_url, branch='master', ecosystem_name='ScribeJava',
		ignore_dirs_with=['test', 'scribejava-apis', 'scribejava-httpclient'], forks=1000)
	session = db.create_session()
	uc.execute(session)

	ecosystem = session.query(Ecosystem).\
			filter(Ecosystem.name == 'ScribeJava').first()
	assert len(ecosystem.relationships) == 0

	session.close()
	db.drop_all()
Exemplo n.º 15
0
def test_file_crud():
	db_url = 'postgresql://*****:*****@localhost:5432/file_crud'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)

	# create
	filepath = 'some/path/file.ext'
	file = File(filepath)
	assert file.name == 'file'
	assert file.path == 'some/path'
	assert file.ext == 'ext'
	assert file.fullpath == filepath

	session = db.create_session()	
	session.add(file)
	session.commit()

	# read	
	filedb = session.query(File).get(1)
	assert filedb.name == file.name
	assert filedb.path == file.path
	assert filedb.ext == file.ext
	assert filedb.fullpath == file.fullpath

	# update
	file.name = 'renamed_file'
	assert file.fullpath == 'some/path/renamed_file.ext'
	file.path = 'new/path'
	assert file.fullpath == 'new/path/renamed_file.ext'
	file.ext = 'txe'
	assert file.fullpath == 'new/path/renamed_file.txe'
	file.fullpath = 'new/full/path/renamed_file.txe'	
	assert file.fullpath == 'new/full/path/renamed_file.txe'
	session.commit()	
	filedb = session.query(File).get(1)
	assert filedb.fullpath == file.fullpath
	assert filedb.name == file.name

	# delete
	session.delete(file)
	session.commit()
	filedb = session.query(File).get(1)
	assert filedb is None

	session.close()
	db.drop_all()
Exemplo n.º 16
0
def test_call_crud():
    db_url = 'postgresql://*****:*****@localhost:5432/call_crud'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    # create
    filepath = 'some/path/file.src'
    file = File(filepath)
    src_file = SourceFile(file)
    f1 = Call('get', src_file)
    f2 = Call('add', src_file)

    session = db.create_session()
    session.add(src_file)
    session.commit()

    # read
    funcsdb = session.query(Call).all()
    assert len(funcsdb) == 2
    assert funcsdb[0].name == 'get'
    assert funcsdb[0].type == 'call'
    assert funcsdb[1].name == 'add'

    # update
    f1.name = 'getX'
    session.commit()
    f1db = session.query(Call).get(1)
    assert f1db.name == 'getX'

    # delete
    session.delete(f1)
    session.commit()
    funcsdb = session.query(Call).all()
    assert len(funcsdb) == 1
    session.delete(f2)
    session.commit()
    funcsdb = session.query(Call).all()
    assert len(funcsdb) == 0
    filedb = session.query(File).get(1)
    src_filedb = session.query(SourceFile).get(1)
    assert filedb.name == 'file'
    assert src_filedb.ext == 'src'

    session.close()
    db.drop_all()
Exemplo n.º 17
0
def test_crud():
    db_url = 'postgresql://*****:*****@localhost:5432/author_crud'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    # create
    repo = Repository('repo/terrame')
    person = Person('dev1', '*****@*****.**')
    author = Author(person, repo)

    session = db.create_session()
    session.add(author)
    session.commit()

    authordb = session.query(Author).one()
    assert authordb.person == person
    assert authordb.repository == repo

    session.close()
    db.drop_all()
Exemplo n.º 18
0
def test_add_operation_same_name():  # TODO: add asserts - flake8
    db_url = 'postgresql://*****:*****@localhost:5432/function_same_name'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    # file1 = File('some/path/file1.src')
    # src_file1 = SourceFile(file1)
    # f1 = Operation('get', src_file1)

    # file2 = File('some/path/file2.src')
    # src_file2 = SourceFile(file2)
    # f2 = Operation('get', src_file2)

    session = db.create_session()
    # session.add(src_file1)
    # session.add(src_file2)
    session.commit()

    session.close()
    db.drop_all()
Exemplo n.º 19
0
def test_add_operation():
	db_url = 'postgresql://*****:*****@localhost:5432/src_file_one_to_one'	
	db = SQLAlchemyORM(db_url)
	db.create_all(True)

	filepath = 'some/path/file.src'
	file = File(filepath)
	src_file = SourceFile(file)

	f1 = Operation('get', src_file)
	src_file.add_code_element(f1)

	session = db.create_session()
	session.add(src_file)
	session.commit()	

	f1db = session.query(Operation).get(1)
	assert f1db.name == 'get'
	assert f1db.source_file_id == 1

	session.close()
	db.drop_all()	 
Exemplo n.º 20
0
def test_one_to_one_relation():
	db_url = 'postgresql://*****:*****@localhost:5432/src_file_one_to_one'	
	db = SQLAlchemyORM(db_url)
	db.create_all(True)
	
	filepath = 'some/path/file.src'
	file = File(filepath)
	src_file1 = SourceFile(file)
	# src_file2 = SourceFile(file) #TODO(#42): how to test one-to-one relationship
	
	session = db.create_session()
	session.add(src_file1)
	# session.add(src_file2)
	session.commit()
	
	# src_filedb1 = session.query(SourceFile).get(1)
	# src_filedb2 = session.query(SourceFile).get(2)
	assert src_file1.file_id == 1
	# assert src_file2.file_id == 1 #TODO: one to one seems not working
	
	session.close()
	db.drop_all()
Exemplo n.º 21
0
def db_connection():
    db_url = 'postgresql://*****:*****@localhost:5432/flask_test'
    db = SQLAlchemyORM(db_url)

    if db.existsdb():  # Comment it for create database
        yield db_connection
        return

    db.create_all(True)
    session = db.create_session()

    repo1 = Repository('repo/terrame')
    sys1 = System('TerraME', repo1)

    session.add(repo1)
    session.add(sys1)

    miner = RepositoryMiner(repo1, sys1)
    miner.add_ignore_dir_with('test')
    miner.add_ignore_dir_with('examples')
    miner.add_ignore_dir_with('ide')
    miner.add_ignore_dir_with('data')
    miner.extract_last_commits(session)

    repo2 = Repository('repo/ca')
    sys2 = System('CA', repo2)
    miner = RepositoryMiner(repo2, sys2)
    miner.extract_last_commits(session)

    ecosystem = Ecosystem()

    ecolyzer = EcosystemAnalyzer(ecosystem)
    ecolyzer.make_relations(sys2, sys1, session)

    session.close()

    yield db_connection

    db.drop_all()
Exemplo n.º 22
0
def test_get_commit_source_file():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_sources'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    miner = RepositoryMiner(repo, sys)
    commit_info = miner.get_commit_info(
        '082dff5e822ea1b4491911b7bf434a7f47a4be26')
    author = Author(Person(commit_info.author_name, commit_info.author_email))
    commit = Commit(commit_info, author, repo)
    session = db.create_session()
    for mod_info in commit_info.modifications:
        file = File(mod_info.new_path)
        sys.add_file(file)
        mod = Modification(mod_info, file, commit)
        if miner.is_source_file(file):
            srcfile = SourceFile(file)
            code_elements = miner.extract_code_elements(srcfile, mod)
            for element in code_elements:
                element.modification = mod
                session.add(element)
            session.add(mod)

    session.commit()
    afile = sys.get_file('base/lua/CellularSpace.lua')
    srcfiledb = session.query(SourceFile).filter_by(file_id=afile.id).first()
    assert srcfiledb.ext == 'lua'
    assert srcfiledb.name == 'CellularSpace'
    assert srcfiledb.code_elements_len() == 78

    functions = session.query(Operation).filter_by(
        source_file_id=srcfiledb.id).all()
    assert srcfiledb.code_element_exists(functions[0])
    assert functions[0].name == 'CellularSpace'

    session.close()
    db.drop_all()
Exemplo n.º 23
0
def test_extract_tag_interval():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_tag_interval'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.commit()
    miner = RepositoryMiner(repo, sys)
    '''
	miner.commit_interval('80a562be869dbb984229f608ae9a04d05c5e1689', 
						'082dff5e822ea1b4491911b7bf434a7f47a4be26') TODO: not working
	'''
    miner.tag_interval('2.0-RC-6', '2.0-RC-7')
    miner.extract(session, max_count=20)

    commits = session.query(Commit).all()

    assert len(commits) == 20

    session.close()
    db.drop_all()
Exemplo n.º 24
0
def test_extract():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_extract'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.commit()
    miner = RepositoryMiner(repo, sys)
    miner.extract(session, '082dff5e822ea1b4491911b7bf434a7f47a4be26')
    filedb = session.query(File).filter_by(
        fullpath='base/lua/CellularSpace.lua').first()
    srcfiledb = session.query(SourceFile).filter_by(file_id=filedb.id).first()
    commitdb = session.query(Commit)\
       .filter(Commit.hash == '082dff5e822ea1b4491911b7bf434a7f47a4be26').one()
    assert commitdb.msg == (
        '* New structure for directories.\n'
        '* Function require already implemented.\n'
        '* Function -config-tests already moved to terrame.lua and working.\n'
        '* Function -test already moved to terrame.lua, but still ' +
        'having problems when executing the tests.')
    authordb = session.query(Author).filter(
        Author.id == commitdb.author_id).one()
    assert authordb.name == 'rvmaretto'
    modificationsdb = session.query(Modification).filter_by(
        commit_id=commitdb.id).all()

    files_mod = {
        'base/description.lua': True,
        'base/load.lua': True,
        'base/lua/Action.lua': True,
        'base/lua/Agent.lua': True,
        'base/lua/Automaton.lua': True,
        'base/lua/Cell.lua': True,
        'base/lua/CellularSpace.lua': True,
        'base/lua/Coord.lua': True,
        'base/lua/Environment.lua': True,
        'base/lua/Event.lua': True,
        'base/lua/Flow.lua': True,
        'base/lua/Group.lua': True,
        'base/lua/Jump.lua': True,
        'base/lua/Legend.lua': True,
        'base/lua/Model.lua': True,
        'base/lua/Neighborhood.lua': True,
        'base/lua/Observer.lua': True,
        'base/lua/Pair.lua': True,
        'base/lua/Random.lua': True,
        'base/lua/SocialNetwork.lua': True,
        'base/lua/Society.lua': True,
        'base/lua/State.lua': True,
        'base/lua/Timer.lua': True,
        'base/lua/Trajectory.lua': True,
        'base/lua/UnitTest.lua': True,
        'base/lua/Utils.lua': True,
        'base/tests/core/alternative/Agent.lua': True,
        'base/tests/core/alternative/Automaton.lua': True,
        'base/tests/core/alternative/Cell.lua': True,
        'base/tests/core/alternative/CellularSpace.lua': True,
        'base/tests/core/alternative/Coord.lua': True,
        'base/tests/core/alternative/Environment.lua': True,
        'base/tests/core/alternative/Event.lua': True,
        'base/tests/core/alternative/Flow.lua': True,
        'base/tests/core/alternative/Group.lua': True,
        'base/tests/core/alternative/Jump.lua': True,
        'base/tests/core/alternative/Model.lua': True,
        'base/tests/core/alternative/Neighborhood.lua': True,
        'base/tests/core/alternative/Random.lua': True,
        'base/tests/core/alternative/SocialNetwork.lua': True,
        'base/tests/core/alternative/Society.lua': True,
        'base/tests/core/alternative/State.lua': True,
        'base/tests/core/alternative/Timer.lua': True,
        'base/tests/core/alternative/Trajectory.lua': True,
        'base/tests/core/alternative/Utils.lua': True,
        'base/tests/core/basics/Agent.lua': True,
        'base/tests/core/basics/Cell.lua': True,
        'base/tests/core/basics/CellularSpace.lua': True,
        'base/tests/core/basics/Coord.lua': True,
        'base/tests/core/basics/Environment.lua': True,
        'base/tests/core/basics/Event.lua': True,
        'base/tests/core/basics/Group.lua': True,
        'base/tests/core/basics/Jump.lua': True,
        'base/tests/core/basics/Memory.lua': True,
        'base/tests/core/basics/Model.lua': True,
        'base/tests/core/basics/Neighborhood.lua': True,
        'base/tests/core/basics/Random.lua': True,
        'base/tests/core/basics/SocialNetwork.lua': True,
        'base/tests/core/basics/Society.lua': True,
        'base/tests/core/basics/Timer.lua': True,
        'base/tests/core/basics/Trajectory.lua': True,
        'base/tests/core/basics/Utils.lua': True,
        'src/lua/terrame.lua': True
    }

    for mod in modificationsdb:
        assert files_mod[mod.new_path]

    operationsdb = session.query(Operation).filter_by(
        source_file_id=srcfiledb.id).all()

    operations = {
        'CellularSpace': True,
        'createNeighborhood': True,
        'add': True,
        'getCell': True,
        'get': True,
        'getCells': True,
        'getCellByID': True,
        'load': True,
        'loadShape': True,
        'loadNeighborhood': True,
        'notify': True,
        'sample': True,
        'save': True,
        'saveShape': True,
        'size': True,
        'split': True,
        'synchronize': True,
        'moore': True,
        'mxn': True,
        'vonneumann': True,
        'coord': True,
        '__len': True
    }

    operationsdb_dict = {}
    for op in operationsdb:
        operationsdb_dict[op.name] = True
        assert operations[op.name]

    for k in operations.keys():
        assert operationsdb_dict[k]

    calls = {
        'addNeighborhood': True,
        'addCell': True,
        'getNeighborhood': True,
        'caseof': True,
        'clear': True,
        'endswith': True,
        'getTime': True,
        'integer': True,
        'getDBName': True,
        'sub': True,
        'setDBType': True,
        'setDBName': True,
        'len': True,
        'setPort': True,
        'setHostName': True,
        'setUser': True,
        'setPassword': True,
        'setTheme': True,
        'setLayer': True,
        'setWhereClause': True,
        'clearAttrName': True,
        'addAttrName': True,
        'setReference': True,
        'getLayerName': True,
        'init': True,
        'forEachCell': True,
        'Neighborhood': True,
        'ipairs': True,
        'weightF': True,
        'filterF': True,
        'customWarningMsg': True,
        'namedParametersErrorMsg': True,
        'type': True,
        'defaultValueWarningMsg': True,
        'incompatibleTypesErrorMsg': True,
        'checkUnnecessaryParameters': True,
        'mandatoryArgumentErrorMsg': True,
        'incompatibleValuesErrorMsg': True,
        'switch': True,
        'deprecatedFunctionWarningMsg': True,
        'Coord': True,
        'readCSV': True,
        'tostring': True,
        'Cell': True,
        'customErrorMsg': True,
        'pairs': True,
        'tableParameterErrorMsg': True,
        'resourceNotFoundErrorMsg': True,
        'print': True,
        'argument': True,
        'Trajectory': True,
        'getn': True,
        'TeCellularSpace': True,
        'incompatibleFileExtensionErrorMsg': True,
        'setmetatable': True,
        'forEachElement': True
    }

    callsdb = session.query(Call).filter_by(source_file_id=srcfiledb.id).all()
    callsdb_dict = {}
    for call in callsdb:
        callsdb_dict[call.name] = True
        assert calls[call.name]

    for k in calls.keys():
        assert callsdb_dict[k]

    session.close()
    db.drop_all()
Exemplo n.º 25
0
import datetime
from ecolyzer.system import File
from ecolyzer.repository import (Repository, Commit, CommitInfo,
								Author, Person, Modification, 
								ModificationInfo)
from ecolyzer.dataaccess import SQLAlchemyORM

db_url = 'postgresql://*****:*****@localhost:5432/commit_test'
db = SQLAlchemyORM(db_url)
db.create_all(True)


def test_crud():
	# create
	repo = Repository('repo/terrame')
	# sys = System('terrame', repo)
	commit_info = CommitInfo('hashhashhash')
	commit_info.date = datetime.datetime(2019, 2, 6, 14, 14, 55)  
	commit_info.msg = 'commit message'
	commit_info.author_name = 'author'
	commit_info.author_email = '*****@*****.**'	
	author = Author(Person(commit_info.author_name, commit_info.author_email), repo)
	commit = Commit(commit_info, author, repo)
	modinfo = ModificationInfo('some/path/file.ext')
	modinfo.old_path = ''
	modinfo.new_path = 'some/path/file.ext'
	modinfo.added = 10
	modinfo.removed = 0
	modinfo.type = 'ADD'
	file = File(modinfo.filename)
	mod = Modification(modinfo, file, commit)	
Exemplo n.º 26
0
def test_extract_last_commits():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_last_commits'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    miner = RepositoryMiner(repo, sys)
    miner.add_ignore_dir_with('test')
    miner.add_ignore_dir_with('example')

    session = db.create_session()
    miner.extract_last_commits(session, '2.0')

    srcfile = session.query(SourceFile).join(SourceFile.file)\
       .filter_by(fullpath='packages/base/lua/Cell.lua').one()

    code_elements = {
        'Cell': True,
        'addNeighborhood': True,
        'distance': True,
        'getAgent': True,
        'getAgents': True,
        'getId': True,
        'getNeighborhood': True,
        'init': True,
        'isEmpty': True,
        'notify': True,
        'on_synchronize': True,
        'sample': True,
        'setId': True,
        'synchronize': True,
        'area': True,
        '__len': True,
        'getID': True,
        'getTime': True,
        'setID': True,
        'setReference': True,
        'setIndex': True,
        'getPackage': True,
        'incompatibleTypeError': True,
        'type': True,
        'mandatoryArgumentError': True,
        'mandatoryArgument': True,
        'customError': True,
        's': True,
        'optionalArgument': True,
        'positiveArgument': True,
        'forEachElement': True,
        'Random': True,
        'pairs': True,
        'getn': True,
        'verifyNamedTable': True,
        'optionalTableArgument': True,
        'TeCell': True,
        'setmetatable': True,
        'mandatoryTableArgument': True,
        'integerTableArgument': True
    }

    src_code_elements = srcfile.code_elements()

    for k in src_code_elements:
        assert code_elements[srcfile.code_element_by_key(k).name]
    assert srcfile.code_elements_len() == 40

    file_mod = session.query(Modification).\
        filter_by(file_id=srcfile.file_id).one()

    assert file_mod.nloc == file_mod.added == 165

    session.close()
    db.drop_all()
Exemplo n.º 27
0
def test_get_commit():
    db_url = 'postgresql://*****:*****@localhost:5432/miner_get_commit'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)
    repo = Repository('repo/terrame')
    sys = System('terrame', repo)
    miner = RepositoryMiner(repo, sys)
    commit_info = miner.get_commit_info(
        '80a562be869dbb984229f608ae9a04d05c5e1689')

    assert commit_info.msg == 'Initial commit'
    assert commit_info.date.strftime(
        '%Y-%m-%d %H:%M:%S') == '2014-09-15 08:12:11'
    assert commit_info.hash == '80a562be869dbb984229f608ae9a04d05c5e1689'
    assert commit_info.author_name == 'pedro-andrade-inpe'
    assert commit_info.author_email == '*****@*****.**'
    assert len(commit_info.modifications) == 1
    assert commit_info.modifications[0].filename == 'LICENSE'
    assert commit_info.modifications[0].old_path is None
    assert commit_info.modifications[0].new_path == 'LICENSE'
    assert commit_info.modifications[0].added == 674
    assert commit_info.modifications[0].removed == 0
    assert commit_info.modifications[0].status == 'ADD'

    author = Author(Person(commit_info.author_name, commit_info.author_email))
    commit = Commit(commit_info, author, repo)
    fmodinfo = commit_info.modifications[0]
    file = File(fmodinfo.filename)
    filemod = Modification(fmodinfo, file, commit)
    session = db.create_session()
    session.add(repo)
    session.add(sys)
    session.add(commit)
    session.add(file)
    session.add(filemod)
    session.commit()

    filemoddb = session.query(Modification).get(1)
    commitdb = filemoddb.commit
    filedb = filemoddb.file

    assert commitdb.msg == 'Initial commit'
    assert commitdb.date.strftime('%Y-%m-%d %H:%M:%S') == '2014-09-15 08:12:11'
    assert commitdb.hash == '80a562be869dbb984229f608ae9a04d05c5e1689'
    assert commitdb.repository.path == repo.path
    assert commitdb.author.name == 'pedro-andrade-inpe'
    assert commitdb.author.email == '*****@*****.**'
    assert filedb.fullpath == 'LICENSE'
    assert filemoddb.old_path is None
    assert filemoddb.new_path == 'LICENSE'
    assert filemoddb.added == 674
    assert filemoddb.removed == 0
    assert filemoddb.status == 'ADD'

    commit_info = miner.get_commit_info(
        'ffb8347b2de44eb05f6c5eba3b3cb8b7716acebb')

    assert commit_info.msg == 'Delete LICENSE'
    assert commit_info.date.strftime(
        '%Y-%m-%d %H:%M:%S') == '2014-09-17 11:49:45'
    assert commit_info.hash == 'ffb8347b2de44eb05f6c5eba3b3cb8b7716acebb'
    assert commit_info.author_name == 'pedro-andrade-inpe'
    assert commit_info.author_email == '*****@*****.**'
    assert len(commit_info.modifications) == 1
    assert commit_info.modifications[0].filename == 'LICENSE'
    assert commit_info.modifications[0].old_path == 'LICENSE'
    assert commit_info.modifications[0].new_path is None
    assert commit_info.modifications[0].added == 0
    assert commit_info.modifications[0].removed == 674
    assert commit_info.modifications[0].status == 'DELETE'

    commit = Commit(commit_info, author, repo)
    fmodinfo = commit_info.modifications[0]
    filemod = Modification(fmodinfo, file, commit)
    session.add(commit)
    session.add(filemod)
    session.commit()

    filemoddb2 = session.query(Modification).get(2)
    commitdb2 = filemoddb2.commit
    filedb2 = filemoddb2.file

    assert commitdb2.msg == 'Delete LICENSE'
    assert commitdb2.date.strftime(
        '%Y-%m-%d %H:%M:%S') == '2014-09-17 11:49:45'
    assert commitdb2.hash == 'ffb8347b2de44eb05f6c5eba3b3cb8b7716acebb'
    assert commitdb2.repository.id == repo.id
    assert commitdb2.author.name == 'pedro-andrade-inpe'
    assert commitdb2.author.email == '*****@*****.**'
    assert filedb2.fullpath == 'LICENSE'
    assert filemoddb2.old_path == 'LICENSE'
    assert filemoddb2.new_path is None
    assert filemoddb2.added == 0
    assert filemoddb2.removed == 674
    assert filemoddb2.status == 'DELETE'

    filemoddb1 = session.query(Modification).get(1)
    commitdb1 = filemoddb1.commit
    filedb1 = filemoddb1.file

    assert commitdb1.msg == 'Initial commit'
    assert commitdb1.date.strftime(
        '%Y-%m-%d %H:%M:%S') == '2014-09-15 08:12:11'
    assert commitdb1.hash == '80a562be869dbb984229f608ae9a04d05c5e1689'
    assert commitdb1.repository.path == repo.path
    assert commitdb2.author.name == 'pedro-andrade-inpe'
    assert commitdb2.author.email == '*****@*****.**'
    assert filedb1.fullpath == 'LICENSE'
    assert filemoddb1.old_path is None
    assert filemoddb1.new_path == 'LICENSE'
    assert filemoddb1.added == 674
    assert filemoddb1.removed == 0
    assert filemoddb1.status == 'ADD'

    session.close()
    db.drop_all()
Exemplo n.º 28
0
def test_relations_last_commits():
	db_url = 'postgresql://*****:*****@localhost:5432/ecolyzer_java_relations_last'
	db = SQLAlchemyORM(db_url)
	db.create_all(True)
	session = db.create_session()

	repo1 = Repository('repo/jfreechart')
	sys1 = System('JFreeChart', repo1)

	session.add(repo1)
	session.add(sys1)

	miner = RepositoryMiner(repo1, sys1)
	miner.add_ignore_dir_with('chart')
	miner.add_ignore_dir_with('test')	
	miner.extract_last_commits(session, 'v1.5.3')

	repo2 = Repository('repo/projectforge')
	sys2 = System('ProjectForge', repo2)

	miner = RepositoryMiner(repo2, sys2)	
	miner.add_ignore_dir_with('test')		
	miner.extract_last_commits(session, '6.25.0-RELEASE')
	
	ecosystem = Ecosystem()

	ecolyzer = EcosystemAnalyzer(ecosystem)
	ecolyzer.make_relations(sys2, sys1, session)

	relationships = ecosystem.relationships

	assert len(relationships) == 11

	rel1 = relationships[0]
	rel2 = relationships[7]
	rel3 = relationships[9]

	expected_code_elements = {
		'Day.Day': True,
		'TimeSeries.add': True,
		'TimeSeries.TimeSeries': True,
		'TimeSeriesCollection.addSeries': True,
		'TimeSeriesCollection.TimeSeriesCollection': True,
		'DateRange.DateRange': True,
		'Day.Day': True,
		'TimeSeries.add': True,
		'TimeSeries.TimeSeries': True,
		'TimeSeriesCollection.addSeries': True,
		'TimeSeriesCollection.TimeSeriesCollection': True,
	} 

	for i in range(len(relationships)):
		assert expected_code_elements[relationships[i].to_code_element.name]

	assert rel1.from_system.name == 'ProjectForge'
	assert rel1.from_author.name == 'Florian Blumenstein'
	assert rel1.from_author.email == '*****@*****.**'
	assert rel1.to_system.name == 'JFreeChart'
	assert rel1.to_author.name == 'David Gilbert'	
	assert rel1.to_author.email == '*****@*****.**'	
	assert rel1.from_code_element.name == rel1.to_code_element.name == 'Day.Day'
	assert rel1.from_code_element.caller == 'new'
	assert rel1.from_code_element_count == 2

	assert rel2.from_system.name == 'ProjectForge'
	assert rel2.from_author.name == 'Florian Blumenstein'
	assert rel2.from_author.email == '*****@*****.**'	
	assert rel2.to_system.name == 'JFreeChart'
	assert rel2.to_author.name == 'David Gilbert'	
	assert rel2.to_author.email == '*****@*****.**'	
	assert rel2.from_code_element.name == rel2.to_code_element.name == 'TimeSeries.add'	
	assert rel2.from_code_element.caller == 'sollSeries'
	assert rel2.from_code_element_count == 4

	assert rel3.from_system.name == 'ProjectForge'
	assert rel3.from_author.name == 'Florian Blumenstein'
	assert rel3.from_author.email == '*****@*****.**'	
	assert rel3.to_system.name == 'JFreeChart'
	assert rel3.to_author.name == 'David Gilbert'	
	assert rel3.to_author.email == '*****@*****.**'	
	assert rel3.from_code_element.name == rel3.to_code_element.name == 'TimeSeriesCollection.addSeries'	
	assert rel3.from_code_element.caller == 'dataset'
	assert rel3.from_code_element_count == 4	

	session.close()
	db.drop_all()
Exemplo n.º 29
0
def test_add_relationship(mocker):
    db_url = 'postgresql://*****:*****@localhost:5432/eco_add_relation'
    db = SQLAlchemyORM(db_url)
    db.create_all(True)

    repo1 = Repository('repo/terrame')
    sys1 = System('terrame', repo1)
    f1 = File('some/path/file1.src')
    src1 = SourceFile(f1)
    f11 = Operation('get', src1)
    f12 = Operation('add', src1)
    c11 = Call('call', src1)
    src1.add_code_element(f11)
    src1.add_code_element(f12)
    src1.add_code_element(c11)
    sys1.add_source_file(src1)

    repo2 = Repository('repo/ca')
    sys2 = System('ca', repo2)
    f2 = File('some/path/file2.src')
    src2 = SourceFile(f2)
    f21 = Operation('call', src2)
    c21 = Call('get', src2)
    src2.add_code_element(f21)
    sys2.add_source_file(src2)

    session = db.create_session()
    session.add(src1)
    session.add(src2)
    session.commit()

    tme_author = Author(Person('TerraMe Dev', '*****@*****.**'))
    ca_author = Author(Person('CA Dev', '*****@*****.**'))
    mocker.patch.object(f11, 'author', return_value=tme_author, autospec=True)
    mocker.patch.object(f12, 'author', return_value=tme_author, autospec=True)
    mocker.patch.object(c11, 'author', return_value=tme_author, autospec=True)
    mocker.patch.object(f21, 'author', return_value=ca_author, autospec=True)
    mocker.patch.object(c21, 'author', return_value=ca_author, autospec=True)

    to_info = RelationInfo(sys1, src1, c11)
    from_info = FromRelationInfo(sys2, src2, f21, 10)
    rel1 = Relationship(from_info, to_info)

    to_info = RelationInfo(sys1, src1, f11)
    from_info = FromRelationInfo(sys2, src2, c21, 20)
    rel2 = Relationship(from_info, to_info)

    eco = Ecosystem()
    eco.add_relationship(rel1)
    eco.add_relationship(rel2)

    session.add(eco)
    session.commit()
    ecodb = session.query(Ecosystem).one()
    relsdb = ecodb.relationships

    assert len(relsdb) == 2

    rel1db = relsdb[0]
    assert rel1db.from_system.name == 'ca'
    assert rel1db.to_system.name == 'terrame'
    assert rel1db.from_source_file.name == 'file2'
    assert rel1db.to_source_file.name == 'file1'
    assert rel1db.from_code_element.name == 'call'
    assert rel1db.to_code_element.name == 'call'
    assert rel1db.from_author.name == 'CA Dev'
    assert rel1db.to_author.name == 'TerraMe Dev'
    assert rel1db.from_code_element_count == 10

    rel2db = relsdb[1]
    assert rel2db.from_system.name == 'ca'
    assert rel2db.to_system.name == 'terrame'
    assert rel2db.from_source_file.name == 'file2'
    assert rel2db.to_source_file.name == 'file1'
    assert rel2db.from_code_element.name == 'get'
    assert rel2db.to_code_element.name == 'get'
    assert rel2db.from_author.name == 'CA Dev'
    assert rel2db.to_author.name == 'TerraMe Dev'
    assert rel2db.from_code_element_count == 20

    session.close()
    db.drop_all()