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()
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()
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()
def test_add_same_relation(mocker): mocker.patch.object(GitPython, 'IsGitRepo', return_value=True) mocker.patch.object(GitPython, 'CurrentBranch', return_value='master') repo1 = Repository('some/path/terrame') sys1 = System('terrame', repo1) f1 = File('Cell.lua') src1 = SourceFile(f1) op1 = Operation('Cell', src1) src1.add_code_element(op1) f2 = File('CellularSpace.lua') src2 = SourceFile(f2) op2 = Operation('CellularSpace', src2) src2.add_code_element(op2) sys1.add_source_file(src1) sys1.add_source_file(src2) repo2 = Repository('some/path/ca') sys2 = System('ca', repo2) f3 = File('Anneal.lua') src3 = SourceFile(f3) c1 = Call('Cell', src3) src3.add_code_element(c1) c2 = Call('CellularSpace', src3) src3.add_code_element(c2) sys2.add_source_file(src3) ecosystem = Ecosystem() tme_author = Author(Person('TerraMe Dev', '*****@*****.**')) ca_author = Author(Person('CA Dev', '*****@*****.**')) mocker.patch.object(op1, 'author', return_value=tme_author, autospec=True) mocker.patch.object(op2, 'author', return_value=tme_author, autospec=True) mocker.patch.object(c1, 'author', return_value=ca_author, autospec=True) mocker.patch.object(c2, 'author', return_value=ca_author, autospec=True) to_info = RelationInfo(sys1, src1, op1) from_info = FromRelationInfo(sys2, src3, c1, 10) rel1 = Relationship(from_info, to_info) rel2 = Relationship(from_info, to_info) assert rel1.from_system == rel2.from_system assert rel1.to_system == rel2.to_system assert rel1.from_code_element == rel2.from_code_element assert rel1.to_code_element == rel2.to_code_element ecosystem.add_relationship(rel1) ecosystem.add_relationship(rel2) assert len(ecosystem.relationships) == 2 ecosystem.relationships[0] == rel1 ecosystem.relationships[1] == rel2
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()
def execute(self, dataaccess): gh = GitHub(self._repo_url) dependents = gh.dependents(self._stars, self._forks) git = GitPython() central_repo_path = git.url_to_path(self._repo_url) existing_repos = self._get_repos(dataaccess) central_system = None ecosystem = None if central_repo_path in existing_repos: central_repo = existing_repos[central_repo_path] if not self._system_name: self._system_name = central_repo.name central_system = dataaccess.query(System).\ filter_by(name=self._system_name).one() ecosystem = dataaccess.query(Ecosystem).\ filter_by(name=self._ecosystem_name).one() else: git.clone(self._repo_url, branch=self._branch) # TODO: check if it exists central_repo = Repository(git.path) if not self._system_name: self._system_name = central_repo.name central_system = System(self._system_name, central_repo) dataaccess.add(central_system) miner = RepositoryMiner(central_repo, central_system) self._ignore_dirs(miner) miner.extract_last_commits(dataaccess) FileUtils.rmdir(git.path) if not self._ecosystem_name: self._ecosystem_name = central_repo.name ecosystem = Ecosystem(self._ecosystem_name) dataaccess.add(ecosystem) dataaccess.commit() existing_repos[central_repo.path] = central_repo ecolyzer = EcosystemAnalyzer(ecosystem) count = 0 for dep in dependents: if dep.repo not in existing_repos: gp = GitPython() gp.clone(dep.url, dep.repo) repo = Repository(gp.path) sys = System(repo.name, repo) count += 1 print(count, 'Analysing', sys.name, dep.url) miner = RepositoryMiner(repo, sys) miner.extract_last_commits(dataaccess) FileUtils.rmdir(gp.path) ecolyzer.make_relations(sys, central_system, dataaccess) existing_repos[repo.path] = repo
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()
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()
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()
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()
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()
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) assert mod.id is None session = db.create_session() session.add(commit) session.commit() assert mod.id is not None # read commitdb = session.query(Commit).get(1) assert commitdb.msg == commit_info.msg assert commitdb.date.strftime('%Y-%m-%d %H:%M:%S') == '2019-02-06 14:14:55' assert commitdb.hash == commit_info.hash assert commitdb.repository.path == repo.path assert commitdb.author.name == commit_info.author_name assert commitdb.author.email == commit_info.author_email # update commit.msg = 'updating message' session.commit() commitdb = session.query(Commit).get(1) assert commitdb.msg == commit.msg # delete session.delete(commit) session.commit() commitdb = session.query(Commit).get(1) moddb = session.query(Modification).get(1) repodb = session.query(Repository).get(1) authordb = session.query(Author).get(1) filedb = session.query(File).get(1) assert commitdb is None assert moddb is None assert repodb.path == repo.path assert authordb.email == author.email assert filedb.id == 1 == file.id session.close() db.drop_all()
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)) 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.status = 'ADD' file = File(modinfo.filename) mod = Modification(modinfo, file, commit) session = db.create_session() session.add(mod) session.commit() # read moddb = session.query(Modification).get(1) assert moddb.new_path == 'some/path/file.ext' assert moddb.old_path == '' assert moddb.added == 10 assert moddb.removed == 0 assert moddb.status == 'ADD' assert moddb.commit_id == 1 assert moddb.file_id == 1 # update mod.status = 'DELETED' session.commit() moddb = session.query(Modification).get(1) assert moddb.status == 'DELETED' # delete session.delete(mod) session.commit() moddb = session.query(Modification).get(1) commitdb = session.query(Commit).get(1) repodb = session.query(Repository).get(1) authordb = session.query(Author).get(1) filedb = session.query(File).get(1) assert moddb is None assert commitdb.id == 1 assert repodb.id == 1 assert authordb.id == 1 assert filedb.id == 1 session.close() db.drop_all()
def test_file_exists(mocker): mocker.patch.object(GitPython, 'IsGitRepo', return_value=True) mocker.patch.object(GitPython, 'CurrentBranch', return_value='master') repo = Repository('repo/terrame') sys = System('terrame', repo) file = File('path/file.ext') sys.add_file(file) assert sys.file_exists(file.fullpath)
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()
def test_add_file_same_fullpath(mocker): mocker.patch.object(GitPython, 'IsGitRepo', return_value=True) mocker.patch.object(GitPython, 'CurrentBranch', return_value='master') repo = Repository('repo/terrame') sys = System('terrame', repo) file1 = File('path/file.ext') file2 = File('path/file.ext') sys.add_file(file1) with pytest.raises(Exception) as e: sys.add_file(file2) assert (('File \'path/file.ext\' is already present') in str(e.value))
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()
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()
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()
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()
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()
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()
from ecolyzer.repository import RepositoryMiner, Repository from ecolyzer.system import System from ecolyzer.dataaccess import SQLAlchemyORM db_url = 'postgresql://*****:*****@localhost:5432/extract_repo_data' db = SQLAlchemyORM(db_url) db.create_all(True) session = db.create_session() repo1 = Repository('repo/terrame') sys1 = System('terrame', repo1) miner = RepositoryMiner(repo1, sys1) miner.extract(session) repo2 = Repository('repo/ca') sys2 = System('ca', repo2) miner = RepositoryMiner(repo2, sys2) miner.extract(session) session.close()
def test_invalid_repo_path(): with pytest.raises(Exception) as e: Repository('invalid/repo') assert (('Invalid repository path \'invalid/repo\'') in str(e.value))
def test_make_relations(mocker): mocker.patch.object(GitPython, 'IsGitRepo', return_value=True) mocker.patch.object(GitPython, 'CurrentBranch', return_value='master') repo1 = Repository('some/path/terrame') sys1 = System('terrame', repo1) f1 = File('Cell.lua') src1 = SourceFile(f1) op1 = Operation('Cell', src1) src1.add_code_element(op1) f2 = File('CellularSpace.lua') src2 = SourceFile(f2) op2 = Operation('CellularSpace', src2) src2.add_code_element(op2) sys1.add_source_file(src1) sys1.add_source_file(src2) repo2 = Repository('some/path/ca') sys2 = System('ca', repo2) f3 = File('Anneal.lua') src3 = SourceFile(f3) c1 = Call('Cell', src3) src3.add_code_element(c1) c2 = Call('CellularSpace', src3) src3.add_code_element(c2) sys2.add_source_file(src3) ecosystem = Ecosystem() tme_author = Author(Person('TerraMe Dev', '*****@*****.**')) ca_author = Author(Person('CA Dev', '*****@*****.**')) mocker.patch.object(op1, 'author', return_value=tme_author, autospec=True) mocker.patch.object(op2, 'author', return_value=tme_author, autospec=True) mocker.patch.object(c1, 'author', return_value=ca_author, autospec=True) mocker.patch.object(c2, 'author', return_value=ca_author, autospec=True) mocker.patch.object(EcosystemAnalyzer, '_total_of_calls', return_value=10) ecolyzer = EcosystemAnalyzer(ecosystem) ecolyzer.make_relations(sys2, sys1) relationships = ecosystem.relationships assert len(relationships) == 2 rel1 = relationships[0] rel2 = relationships[1] assert rel1.from_system.name == 'ca' assert rel1.from_author.name == 'CA Dev' assert rel1.from_author.email == '*****@*****.**' assert rel1.to_system.name == 'terrame' assert rel1.to_author.name == 'TerraMe Dev' assert rel1.to_author.email == '*****@*****.**' assert rel1.from_code_element.name == rel1.to_code_element.name == 'Cell' assert rel2.from_system.name == 'ca' assert rel2.from_author.name == 'CA Dev' assert rel2.from_author.email == '*****@*****.**' assert rel2.to_system.name == 'terrame' assert rel2.to_author.name == 'TerraMe Dev' assert rel2.to_author.email == '*****@*****.**' assert rel2.from_code_element.name == rel2.to_code_element.name == 'CellularSpace'
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()
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()
from ecolyzer.ecosystem import EcosystemAnalyzer from ecolyzer.system import System from ecolyzer.repository import Repository, RepositoryMiner from ecolyzer.dataaccess import SQLAlchemyORM from ecolyzer.ecosystem import Ecosystem db_url = 'postgresql://*****:*****@localhost:5432/terrame_ecosystem' 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.add_ignore_dir_with('data') miner.add_ignore_dir_with('images') miner.add_ignore_dir_with('zerobrane') 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) repo3 = Repository('repo/calibration')
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()
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()