class TestActivityPersons (unittest.TestCase): def setUp (self): self.database = DB (url = url, schema = schema, schema_id = schema_id) self.session = self.database.build_session() self.start = start self.end = end def test_orgs_condition (self): """Test SCMActivityPersons object with an organizations condition""" correct = ActivityList( (KeyedTuple([774, u'John Dickinson', datetime.strptime("2013-11-15 15:10:39", datefmt), datetime.strptime("2014-01-24 14:53:17", datefmt) ], labels = rowlabels ), KeyedTuple([1094, u'Samuel Merritt', datetime.strptime("2013-11-13 12:52:21", datefmt), datetime.strptime("2014-01-31 13:17:00", datefmt) ], labels = rowlabels ), KeyedTuple([2071, u'Darrell Bishop', datetime.strptime("2013-11-27 00:37:02", datefmt), datetime.strptime("2013-11-27 12:07:42", datefmt) ], labels = rowlabels ), KeyedTuple([2110, u'Jon Snitow', datetime.strptime("2014-01-29 13:02:54", datefmt), datetime.strptime("2014-01-29 13:02:54", datefmt) ], labels = rowlabels ) ) ) period = SCMPeriodCondition (start = self.start, end = self.end) nomerges = SCMNomergesCondition() orgs = SCMOrgsCondition (orgs = ("SwiftStack", "Inktank"), actors = "authors") data = SCMActivityPersons ( datasource = self.session, name = "list_authors", conditions = (period,nomerges,orgs)) activity = data.activity() print activity self.assertEqual (data.activity(), correct)
class TestActivityPersons(unittest.TestCase): def setUp(self): self.database = DB(url=url, schema=schema, schema_id=schema_id) self.session = self.database.build_session() self.start = start self.end = end def test_orgs_condition(self): """Test SCMActivityPersons object with an organizations condition""" correct = ActivityList( (KeyedTuple([ 774, u'John Dickinson', datetime.strptime("2013-11-15 15:10:39", datefmt), datetime.strptime("2014-01-24 14:53:17", datefmt) ], labels=rowlabels), KeyedTuple([ 1094, u'Samuel Merritt', datetime.strptime("2013-11-13 12:52:21", datefmt), datetime.strptime("2014-01-31 13:17:00", datefmt) ], labels=rowlabels), KeyedTuple([ 2071, u'Darrell Bishop', datetime.strptime("2013-11-27 00:37:02", datefmt), datetime.strptime("2013-11-27 12:07:42", datefmt) ], labels=rowlabels), KeyedTuple([ 2110, u'Jon Snitow', datetime.strptime("2014-01-29 13:02:54", datefmt), datetime.strptime("2014-01-29 13:02:54", datefmt) ], labels=rowlabels))) period = SCMPeriodCondition(start=self.start, end=self.end) nomerges = SCMNomergesCondition() orgs = SCMOrgsCondition(orgs=("SwiftStack", "Inktank"), actors="authors") data = SCMActivityPersons(datasource=self.session, name="list_authors", conditions=(period, nomerges, orgs)) activity = data.activity() print activity self.assertEqual(data.activity(), correct)
class TestSCMOrgs(unittest.TestCase): def setUp(self): self.database = DB(url=url, schema=schema, schema_id=schema_id) self.session = self.database.build_session() self.start = start self.end = end def test_orgs_condition(self): """Test SCM object with an organizations condition""" orgs = OrgsCondition(orgs=("Red Hat", "Midokura", "HP"), actors="authors") data = SCM(datasource=self.database, name="ncommits", conditions=(orgs, )) self.assertEqual(data.total(), 20115)
class TestSCMOrgs (unittest.TestCase): def setUp (self): self.database = DB (url = url, schema = schema, schema_id = schema_id) self.session = self.database.build_session() self.start = start self.end = end def test_orgs_condition (self): """Test SCM object with an organizations condition""" orgs = OrgsCondition (orgs = ("Red Hat", "Midokura", "HP"), actors = "authors") data = SCM (datasource = self.database, name = "ncommits", conditions = (orgs,)) self.assertEqual (data.total(), 20115)
#--------------------------------- print_banner ("Number of commits (timeseries, total), for period") period = PeriodCondition (start = datetime(2013,1,1), end = None) data = SCM (datasource = database, name = "ncommits", conditions = (period,)) print data.timeseries() print data.total() #--------------------------------- print_banner ("List of commits") data = SCM (datasource = database, name = "listcommits") print data.list() session = database.build_session() #--------------------------------- print_banner ("Number of authors (timeseries, total)") data = SCM (datasource = session, name = "nauthors", conditions = (period,)) print data.timeseries() print data.total() #--------------------------------- print_banner ("Number of authors (timeseries, total) for a period and branch") branches = BranchesCondition (branches = ("master",)) data = SCM (datasource = session, name = "nauthors", conditions = (period, branches)) print data.timeseries() print data.total()
if __name__ == "__main__": from grimoirelib_alch.aux.standalone import stdout_utf8, print_banner from datetime import datetime, timedelta from scm import PeriodCondition as SCMPeriodCondition from scm import NomergesCondition as SCMNomergesCondition from its import PeriodCondition as ITSPeriodCondition stdout_utf8() # SCM database database = SCMDatabase(url="mysql://*****:*****@localhost/", schema="vizgrimoire_cvsanaly", schema_id="vizgrimoire_cvsanaly") session = database.build_session() #--------------------------------- print_banner("List of activity for each author") data = SCMActivityPersons(datasource=database, name="list_authors") activity = data.activity() print activity #--------------------------------- print_banner("Age (days since first activity) for each author.") age = activity.age(datetime(2014, 1, 1)) print age.json() #--------------------------------- print_banner("Idle (days since last activity) for each author.") idle = activity.idle(datetime(2014, 1, 1)) print idle.json()
class TestSCM(unittest.TestCase): def setUp(self): self.database = DB(url=url, schema=schema, schema_id=schema_id) self.session = self.database.build_session() self.start = datetime(2013, 11, 13) self.end = datetime(2014, 2, 1) def test_no_condition(self): """Test SCM object with no conditions""" data = SCM(datasource=self.database, name="ncommits") self.assertEqual(data.total(), 3646) def test_nomerges_condition(self): """Test SCM object with a no merges condition""" nomerges = NomergesCondition() data = SCM(datasource=self.database, name="ncommits", conditions=(nomerges, )) self.assertEqual(data.total(), 3405) def test_branches_condition(self): """Test SCM object with a branches condition""" # Master branch branches = BranchesCondition(branches=("master", )) data = SCM(datasource=self.database, name="ncommits", conditions=(branches, )) self.assertEqual(data.total(), 2884) def test_period_condition(self): """Test SCM object with a period condition""" # Only start for period period = PeriodCondition(start=self.start, end=None) data = SCM(datasource=self.database, name="ncommits", conditions=(period, )) self.assertEqual(data.total(), 839) # Start and end period = PeriodCondition(start=self.start, end=self.end) data = SCM(datasource=self.database, name="ncommits", conditions=(period, )) self.assertEqual(data.total(), 730) # Start and end, authoring date period = PeriodCondition(start=self.start, end=self.end, date="author") data = SCM(datasource=self.database, name="ncommits", conditions=(period, )) self.assertEqual(data.total(), 728) def test_combined_conditions(self): """Test SCM object with a combination of conditions""" # Branches and period, and the other way around branches = BranchesCondition(branches=("master", )) period = PeriodCondition(start=self.start, end=self.end, date="author") data = SCM(datasource=self.session, name="ncommits", conditions=(branches, period)) self.assertEqual(data.total(), 647) data = SCM(datasource=self.session, name="ncommits", conditions=(period, branches)) self.assertEqual(data.total(), 647) # Branches, period and merges (in several orders) nomerges = NomergesCondition() data = SCM(datasource=self.session, name="ncommits", conditions=(nomerges, period, branches)) self.assertEqual(data.total(), 647) data = SCM(datasource=self.session, name="ncommits", conditions=(branches, nomerges, period)) self.assertEqual(data.total(), 647)
def setUp (self): database = DB (url = url, schema = schema, schema_id = schema_id) self.session = database.build_session(Query, echo = False)
class TestSCM (unittest.TestCase): def setUp (self): self.database = DB (url = url, schema = schema, schema_id = schema_id) self.session = self.database.build_session() self.start = datetime(2013,11,13) self.end = datetime(2014,2,1) def test_no_condition (self): """Test SCM object with no conditions""" data = SCM (datasource = self.database, name = "ncommits") self.assertEqual (data.total(), 3646) def test_nomerges_condition (self): """Test SCM object with a no merges condition""" nomerges = NomergesCondition () data = SCM (datasource = self.database, name = "ncommits", conditions = (nomerges,)) self.assertEqual (data.total(), 3405) def test_branches_condition (self): """Test SCM object with a branches condition""" # Master branch branches = BranchesCondition (branches = ("master",)) data = SCM (datasource = self.database, name = "ncommits", conditions = (branches,)) self.assertEqual (data.total(), 2884) def test_period_condition (self): """Test SCM object with a period condition""" # Only start for period period = PeriodCondition (start = self.start, end = None) data = SCM (datasource = self.database, name = "ncommits", conditions = (period,)) self.assertEqual (data.total(), 839) # Start and end period = PeriodCondition (start = self.start, end = self.end) data = SCM (datasource = self.database, name = "ncommits", conditions = (period,)) self.assertEqual (data.total(), 730) # Start and end, authoring date period = PeriodCondition (start = self.start, end = self.end, date = "author") data = SCM (datasource = self.database, name = "ncommits", conditions = (period,)) self.assertEqual (data.total(), 728) def test_combined_conditions (self): """Test SCM object with a combination of conditions""" # Branches and period, and the other way around branches = BranchesCondition (branches = ("master",)) period = PeriodCondition (start = self.start, end = self.end, date = "author") data = SCM (datasource = self.session, name = "ncommits", conditions = (branches,period)) self.assertEqual (data.total(), 647) data = SCM (datasource = self.session, name = "ncommits", conditions = (period, branches)) self.assertEqual (data.total(), 647) # Branches, period and merges (in several orders) nomerges = NomergesCondition () data = SCM (datasource = self.session, name = "ncommits", conditions = (nomerges, period, branches)) self.assertEqual (data.total(), 647) data = SCM (datasource = self.session, name = "ncommits", conditions = (branches, nomerges, period)) self.assertEqual (data.total(), 647)
def setUp(self): database = DB(url=url, schema=schema, schema_id=schema_id) self.session = database.build_session(Query, echo=False)
database = SCMDatabase (url = "mysql://*****:*****@localhost/", schema = "oscon_opennebula_scm_tz", schema_id = "oscon_opennebula_scm_tz") #--------------------------------- print_banner("Author activity per time zone") data = SCMActivityTZ ( datasource = database, name = "authors") tz = data.timezones() print tz #--------------------------------- print_banner("Author activity per time zone (now using session)") session = database.build_session(query_cls = SCMTZQuery) data = SCMActivityTZ ( datasource = session, name = "authors") tz = data.timezones() print tz #--------------------------------- print_banner("Author activity per time zone (using session, conditions)") period = SCMPeriodCondition (start = datetime(2014,1,1), end = None) nomerges = SCMNomergesCondition() data = SCMActivityTZ ( datasource = session, name = "authors", conditions = (period,nomerges)) tz = data.timezones()