def default_matches(self, attributes, parameters): method = target_tasks.get_method('default') graph = TaskGraph(tasks={ 'a': Task(kind='build', label='a', attributes=attributes, task={}), }, graph=Graph(nodes={'a'}, edges=set())) return 'a' in method(graph, parameters, {})
def default_matches(self, run_on_projects, project): method = target_tasks.get_method('default') graph = TaskGraph(tasks={ 'a': Task(kind='build', label='a', attributes={'run_on_projects': run_on_projects}, task={}), }, graph=Graph(nodes={'a'}, edges=set())) parameters = {'project': project} return 'a' in method(graph, parameters, {})
def test_try_task_config(self): "try_mode = try_task_config uses the try config" tg = self.make_task_graph() method = target_tasks.get_method('try_tasks') params = { 'try_mode': 'try_task_config', 'try_task_config': {'tasks': ['a']}, } self.assertEqual(method(tg, params, {}), ['a'])
def test_try_option_syntax(self): "try_mode = try_option_syntax uses TryOptionSyntax" tg = self.make_task_graph() method = target_tasks.get_method("try_tasks") with self.fake_TryOptionSyntax(): params = { "try_mode": "try_option_syntax", "message": "try: -p all", } self.assertEqual(method(tg, params, {}), ["b"])
def test_try_option_syntax(self): "try_mode = try_option_syntax uses TryOptionSyntax" tg = self.make_task_graph() method = target_tasks.get_method('try_tasks') with self.fake_TryOptionSyntax(): params = { 'try_mode': 'try_option_syntax', 'message': 'try: -p all', } self.assertEqual(method(tg, params, {}), ['b'])
def test_try_option_syntax(self): "try_mode = try_option_syntax uses TryOptionSyntax" tg = self.make_task_graph() method = target_tasks.get_method('try_tasks') with self.fake_TryOptionSyntax(): params = { 'try_mode': 'try_option_syntax', 'message': 'try: -p all', } self.assertEqual(method(tg, params, {}), ['b'])
def test_try_task_config(self): "try_mode = try_task_config uses the try config" tg = self.make_task_graph() method = target_tasks.get_method("try_tasks") params = { "try_mode": "try_task_config", "try_task_config": { "tasks": ["a"] }, } self.assertEqual(method(tg, params, {}), ["a"])
def test_empty_try(self): "try_mode = None runs nothing" tg = self.make_task_graph() method = target_tasks.get_method("try_tasks") params = { "try_mode": None, "project": "try", "message": "", } # only runs the task with run_on_projects: try self.assertEqual(method(tg, params, {}), [])
def test_try_task_config(self): "try_mode = try_task_config uses the try config" tg = self.make_task_graph() method = target_tasks.get_method('try_tasks') params = { 'try_mode': 'try_task_config', 'try_task_config': { 'tasks': ['a'] }, } self.assertEqual(method(tg, params, {}), ['a'])
def test_empty_try(self): "try_mode = None runs nothing" tg = self.make_task_graph() method = target_tasks.get_method('try_tasks') params = { 'try_mode': None, 'project': 'try', 'message': '', } # only runs the task with run_on_projects: try self.assertEqual(method(tg, params, {}), [])
def test_empty_try(self): "try_mode = None runs nothing" tg = self.make_task_graph() method = target_tasks.get_method('try_tasks') params = { 'try_mode': None, 'project': 'try', 'message': '', } # only runs the task with run_on_projects: try self.assertEqual(method(tg, params, {}), [])
def default_matches(self, attributes, parameters): method = target_tasks.get_method("default") graph = TaskGraph( tasks={ "a": Task(kind="build", label="a", attributes=attributes, task={}), }, graph=Graph(nodes={"a"}, edges=set()), ) return "a" in method(graph, parameters, {})
def default_matches(self, run_on_projects, project): method = target_tasks.get_method('default') graph = TaskGraph(tasks={ 'a': Task(kind='build', label='a', attributes={'run_on_projects': run_on_projects}, task={}), }, graph=Graph(nodes={'a'}, edges=set())) parameters = {'project': project} return 'a' in method(graph, parameters)
def test_try_tasks(self): tasks = { 'a': Task(kind=None, label='a', attributes={}, task={}), 'b': Task(kind=None, label='b', attributes={'at-at': 'yep'}, task={}), 'c': Task(kind=None, label='c', attributes={}, task={}), } graph = Graph(nodes=set('abc'), edges=set()) tg = TaskGraph(tasks, graph) method = target_tasks.get_method('try_tasks') config = os.path.join(os.getcwd(), 'try_task_config.json') orig_TryOptionSyntax = try_option_syntax.TryOptionSyntax try: try_option_syntax.TryOptionSyntax = FakeTryOptionSyntax # no try specifier self.assertEqual(method(tg, {'message': ''}), ['b']) # try syntax only self.assertEqual(method(tg, {'message': 'try: me'}), ['b']) # try task config only with open(config, 'w') as fh: fh.write('["c"]') self.assertEqual(method(tg, {'message': ''}), ['c']) with open(config, 'w') as fh: fh.write('{"c": {}}') self.assertEqual(method(tg, {'message': ''}), ['c']) # both syntax and config self.assertEqual(set(method(tg, {'message': 'try: me'})), set(['b', 'c'])) finally: try_option_syntax.TryOptionSyntax = orig_TryOptionSyntax if os.path.isfile(config): os.remove(config)
def test_try_tasks(self): tasks = { 'a': Task(kind=None, label='a', attributes={}, task={}), 'b': Task(kind=None, label='b', attributes={'at-at': 'yep'}, task={}), 'c': Task(kind=None, label='c', attributes={}, task={}), } graph = Graph(nodes=set('abc'), edges=set()) tg = TaskGraph(tasks, graph) method = target_tasks.get_method('try_tasks') params = { 'message': '', 'target_task_labels': [], } orig_TryOptionSyntax = try_option_syntax.TryOptionSyntax try: try_option_syntax.TryOptionSyntax = FakeTryOptionSyntax # no try specifier self.assertEqual(method(tg, params), ['b']) # try syntax only params['message'] = 'try: me' self.assertEqual(method(tg, params), ['b']) # try task config only params['message'] = '' params['target_task_labels'] = ['c'] self.assertEqual(method(tg, params), ['c']) # both syntax and config params['message'] = 'try: me' self.assertEqual(set(method(tg, params)), set(['b', 'c'])) finally: try_option_syntax.TryOptionSyntax = orig_TryOptionSyntax