예제 #1
0
	def test_executions__day_executions__multiple_clients__first_client_with_last_day_empty(self):
		a_project = Project('project name')
		a_client = Client('a_client')
		a_client2 = Client('a_client2')
		listener1 = ServerListener( client=a_client, project=a_project )
		listener1.current_time = lambda : "2006-04-29-12-12-00"
		listener2 = ServerListener( client=a_client2, project=a_project )
		listener2.current_time = lambda : "2006-04-29-12-00-00"
		generator = WebGenerator(project_name= a_project.name)
		task = Task(a_project, a_client, 'task')
		task.add_subtask('subtask1', [])
		Runner(task, testinglisteners=[listener1])
		task = Task(a_project, a_client2, 'task')	
		task.add_subtask('subtask1', [])
		Runner(task, testinglisteners=[listener2])
		listener2.current_time = lambda : "2006-04-30-12-00-00"	
		Runner(task, testinglisteners=[listener2])
		self.assertEquals(
			{'2006-04-30':
				{'a_client2': [('2006-04-30-12-00-00', '2006-04-30-12-00-00', 'task', 'stable')]},
			'2006-04-29':
				{'a_client2': [('2006-04-29-12-00-00', '2006-04-29-12-00-00', 'task', 'stable')],
				'a_client': [('2006-04-29-12-12-00', '2006-04-29-12-12-00', 'task', 'stable')]
				}
			}, generator.day_executions(generator.get_executions()) )
예제 #2
0
	def test_stats_single_client_multiple_key(self):
		a_project = Project('project name')
		a_client = Client('a_client')
		listener = ServerListener( client=a_client, project=a_project )
		generator = WebGenerator(project_name= a_project.name)

		listener.current_time = lambda : "2006-04-04-00-00-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'key1':5, 'key2':0} }] )
		Runner(task, testinglisteners=[listener])
		
		listener.current_time = lambda : "2006-04-05-00-00-00"
		task = Task(a_project, a_client, 'task')		
		task.add_subtask("subtask", [{STATS:lambda x: {'key1':-1, 'key2':4} }] )
		Runner(task, testinglisteners=[listener])
		
		self.assertEquals( 
			{
			'a_client': 
				{
				'subtask': 
					[
					('2006-04-04-00-00-00', {'key2': 0, 'key1': 5}),
					('2006-04-05-00-00-00', {'key2': 4, 'key1': -1})
					]
				}
			}, generator.collect_stats() )
예제 #3
0
	def test_two_clients(self):
		a_project = Project('project name')
		a_client = Client('client 1')
		a_client2 = Client('client 2')
		listener1 = ServerListener(
			client=a_client,
			logs_base_dir='/tmp/clients_testdir',
			project=a_project)
		listener2 = ServerListener(
			client=a_client2,
			logs_base_dir='/tmp/clients_testdir',
			project=a_project)
		listener1.current_time = lambda : "some date"
		listener2.current_time = lambda : "some other date"
		generator = WebGenerator(logs_base_dir='/tmp/clients_testdir', project_name= a_project.name)
		task = Task(a_project, a_client, 'task')
		task.add_subtask('subtask1', [])

		Runner(task, testinglisteners=[listener1])
		task = Task(a_project, a_client2, 'task')
		task.add_subtask('subtask1', [])
		Runner(task, testinglisteners=[listener2])
		self.assertEquals( 
			{'client 1':[('some date', 'some date', 'task', 'stable')],
			 'client 2':[('some other date', 'some other date', 'task', 'stable')]}, 
			generator.get_executions() )
		listener1.clean_log_files()
		listener2.clean_log_files()
예제 #4
0
	def test_purged_details(self):
		a_project = Project('project name')
		a_client = Client('a_client')
		listener = ServerListener( client=a_client, project=a_project )
		generator = WebGenerator(project_name= a_project.name)
		listener.current_time = lambda : "1999-99-99-99-99-99"
		listener.listen_begin_task("we want this one")
		listener.listen_begin_subtask("subtask")
		listener.listen_begin_command("a command")
		listener.listen_end_command("a command", False, "some output", "some info", {'a':1})
		listener.listen_begin_command("a command")
		listener.listen_end_command("a command", False, "some more output", "some more info", {'a':1})
		listener.listen_end_subtask("subtask")
		listener.current_time = lambda : "2000-00-00-00-00-00"
		listener.listen_end_task("we want this one", False)
		expected = [
('BEGIN_TASK', 'we want this one', '1999-99-99-99-99-99'),
('BEGIN_SUBTASK', 'subtask'),
('BEGIN_CMD', 'a command'),
('END_CMD', 'a command', False, 'some output', 'some info', {'a':1}),
('BEGIN_CMD', 'a command'),
('END_CMD', 'a command', False, 'some more output','some more info', {'a':1}),
('END_SUBTASK', 'subtask'),
('END_TASK', 'we want this one', '2000-00-00-00-00-00', 'False'),
]
		generator.purge_client_logfile('a_client','1999-99-99-99-99-99')
		self.assertEquals( expected, generator.single_execution_details('a_client', '1999-99-99-99-99-99') )
예제 #5
0
	def test_idle_state(self):
		a_project = Project('project name')
		listener = ServerListener( project = a_project )
		listener.current_time = lambda : "1000-10-10-10-10-10"
		listener.listen_found_new_commits(True, next_run_in_seconds=60)
		self.assertEquals("{'date': '1000-10-10-10-10-10', 'new_commits_found': True, 'next_run_in_seconds': 60}", 
			open(listener.idle_file).read())
예제 #6
0
	def test_executions__day_executions__single_client(self):
		a_project = Project('project name')
		listener = ServerListener( project = a_project)
		listener.current_time = lambda : "2006-04-29-12-00-00"
		a_project = Project('project name')
		generator = WebGenerator(project_name= a_project.name)
		a_client = Client('client name')
		task = Task(a_project, a_client, 'task')
		task.add_subtask('subtask1', [])	
		Runner(task, testinglisteners=[listener])	
		listener.current_time = lambda : "2006-04-30-12-00-00"	
		Runner(task, testinglisteners=[listener])	
		self.assertEquals(
			{'2006-04-30':
				 {'testing_client': [('2006-04-30-12-00-00', '2006-04-30-12-00-00', 'task', 'stable')]},
			'2006-04-29':
				{'testing_client': [('2006-04-29-12-00-00', '2006-04-29-12-00-00', 'task', 'stable')]}
			}, generator.day_executions(generator.get_executions()) )
예제 #7
0
	def test_plot_data_file(self):
		a_project = Project('project name')
		a_client = Client('client1')
		a_client2 = Client('client2')
		listener1 = ServerListener( client=a_client, project=a_project )
		listener2 = ServerListener( client=a_client2, project=a_project )
		generator = WebGenerator(project_name= a_project.name)

		listener1.current_time = lambda : "2006-04-04-00-00-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'key':5} }] )
		Runner(task, testinglisteners=[listener1])
		
		listener1.current_time = lambda : "2006-04-05-00-00-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'kk':3} }, {STATS:lambda x: {'key':1, 'key2':2} }] )
		Runner(task, testinglisteners=[listener1])
		
		listener2.current_time = lambda : "2000-01-01-12-54-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'clau 1':0, 'clau 2':10} }] )
		task.add_subtask("another subtask", [{STATS:lambda x: {'clau 1':2, 'clau 2':13} }] )
		Runner(task, testinglisteners=[listener2])
		
		generator.plot_stats()

		self.assertEquals('''\
time	kk	key2	key
2006/04/04.00:00	-	-	5
2006/04/05.00:00	3	-	-
2006/04/05.00:00	-	2	1
''', open("%s/%s/client1_1.plot" % (generator.logs_base_dir, generator.project_name)).read() )

		self.assertEquals('''\
time	clau_1	clau_2
2000/01/01.12:54	0	10
''', open("%s/%s/client2_1.plot" % (generator.logs_base_dir, generator.project_name)).read() )
		self.assertEquals('''\
time	clau_1	clau_2
2000/01/01.12:54	2	13
''', open("%s/%s/client2_2.plot" % (generator.logs_base_dir, generator.project_name)).read() )
예제 #8
0
	def test_stats_multiple_client_single_key(self):
		a_project = Project('project name')
		a_client = Client('client1')
		a_client2 = Client('client2')
		listener1 = ServerListener( client=a_client, project=a_project )
		listener2 = ServerListener( client=a_client2, project=a_project )
		generator = WebGenerator(project_name= a_project.name)

		listener1.current_time = lambda : "2006-04-04-00-00-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'key':5} }] )
		Runner(task, testinglisteners=[listener1])
		
		listener1.current_time = lambda : "2006-04-05-00-00-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'key':1} }] )
		Runner(task, testinglisteners=[listener1])
		
		listener2.current_time = lambda : "1000-00-00-00-00-00"
		task = Task(a_project, a_client, 'task')	
		task.add_subtask("subtask", [{STATS:lambda x: {'clau':0} }] )
		Runner(task, testinglisteners=[listener2])


		self.assertEquals( 
			{
			'client1': 
				{
				'subtask': 
					[
					('2006-04-04-00-00-00', {'key': 5}),
					('2006-04-05-00-00-00', {'key': 1})
					]
				},
			'client2': 
				{'subtask': 
					[
					('1000-00-00-00-00-00', {'clau': 0})
					]
				}
			}, generator.collect_stats() )
예제 #9
0
	def test_executions__one_green_execution(self):
		a_project = Project('project name')
		listener = ServerListener( project = a_project)
		listener.current_time = lambda : "a date"	
		generator = WebGenerator(project_name= a_project.name)
		a_client = Client('client name')
		task = Task(a_project, a_client, 'task')
		task.add_subtask('subtask1', [])	
		Runner(task, testinglisteners=[listener])
		self.assertEquals(
			{'testing_client' : [('a date', 'a date', 'task', 'stable')]}, 
			generator.get_executions() )
예제 #10
0
	def test_no_stats(self):
		a_project = Project('project name')
		a_client = Client('a_client')
		listener = ServerListener( client=a_client, project=a_project )
		generator = WebGenerator(project_name= a_project.name)

		listener.current_time = lambda : "2006-04-04-00-00-00"
		task = Task(a_project, a_client, 'task')
		task.add_subtask("subtask", ["echo no stats"] )
		Runner(task, testinglisteners=[listener])
		
		self.assertEquals( {'a_client': {} }, generator.collect_stats() )
예제 #11
0
	def test_multiple_repositories_multiple_tasks(self):
		a_project = Project('project name')
		id = lambda txt : txt
		listener1 = ServerListener( project=a_project)
		listener2 = ServerListener( project=a_project)
		listener1.current_time = lambda : "2006-03-17-13-26-20"
		listener2.current_time = lambda : "2006-03-17-13-26-20"
		a_client = Client('a_client')
		task1 = Task(a_project, a_client, 'task')	
		task2 = Task(a_project, a_client, 'task')	
		task1.add_subtask('subtask1', ["echo subtask1"])	
		task1.add_subtask('subtask2', [{CMD:"echo something echoed", INFO:id}, "./lalala gh"])
		task2.add_subtask('subtask1', [])
		task2.add_subtask('subtask2', ["ls"])	
		Runner(task1, testinglisteners=[listener1])
		Runner(task2, testinglisteners=[listener2])
		self.assertEquals("""\

('BEGIN_TASK', 'task', '2006-03-17-13-26-20'),
('BEGIN_SUBTASK', 'subtask1'),
('BEGIN_CMD', 'echo subtask1'),
('END_CMD', 'echo subtask1', True, '', '', {}),
('END_SUBTASK', 'subtask1'),
('BEGIN_SUBTASK', 'subtask2'),
('BEGIN_CMD', 'echo something echoed'),
('END_CMD', 'echo something echoed', True, '', 'something echoed\\n', {}),
('BEGIN_CMD', './lalala gh'),
('END_CMD', './lalala gh', False, '\\x1b[31m/bin/sh: 1: ./lalala: not found\\n\\x1b[0m', '', {}),
('END_SUBTASK', 'subtask2'),
('END_TASK', 'task', '2006-03-17-13-26-20', 'False'),

('BEGIN_TASK', 'task', '2006-03-17-13-26-20'),
('BEGIN_SUBTASK', 'subtask1'),
('END_SUBTASK', 'subtask1'),
('BEGIN_SUBTASK', 'subtask2'),
('BEGIN_CMD', 'ls'),
('END_CMD', 'ls', True, '', '', {}),
('END_SUBTASK', 'subtask2'),
('END_TASK', 'task', '2006-03-17-13-26-20', 'True'),
""", open( listener2.logfile ).read() )
예제 #12
0
	def test_idles(self):
		a_project = Project('project name')
		a_client = Client('a_client')
		listener = ServerListener( client=a_client, project=a_project )
		listener.current_time = lambda : "a date"
		generator = WebGenerator(project_name= a_project.name)
		task = Task(a_project, a_client, 'task')
		task.set_check_for_new_commits( checking_cmd="echo P patched_file | grep ^[UP]", minutes_idle=1 )
		Runner(task, testinglisteners=[listener])
		self.assertEquals(
			{'a_client' : 
				{'date':'a date', 
				'new_commits_found': True,
				'next_run_in_seconds':60
				}
			}, 
			generator.idle() )