def tearDown(self): """ :API: public """ Goal.clear() super(EngineTestBase, self).tearDown()
def setUp(self): super(BaseTest, self).setUp() Goal.clear() Subsystem.reset() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) self.addCleanup(safe_rmtree, self.build_root) self.pants_workdir = os.path.join(self.build_root, '.pants.d') safe_mkdir(self.pants_workdir) self.options = defaultdict(dict) # scope -> key-value mapping. self.options[''] = { 'pants_workdir': self.pants_workdir, 'pants_supportdir': os.path.join(self.build_root, 'build-support'), 'pants_distdir': os.path.join(self.build_root, 'dist'), 'pants_configdir': os.path.join(self.build_root, 'config'), 'cache_key_gen_version': '0-test', } BuildRoot().path = self.build_root self.addCleanup(BuildRoot().reset) # We need a pants.ini, even if empty. get_buildroot() uses its presence. self.create_file('pants.ini') self._build_configuration = BuildConfiguration() self._build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile) self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def setUp(self): super(EngineTestBase, self).setUp() # TODO(John Sirois): Now that the BuildFileParser controls goal registration by iterating # over plugin callbacks a GoalRegistry can be constructed by it and handed to all these # callbacks in place of having a global Goal registry. Remove the Goal static cling. Goal.clear()
def clean_global_runtime_state(): """Resets the global runtime state of a pants runtime for cleaner forking.""" # Reset RunTracker state. RunTracker.global_instance().reset(reset_options=False) # Reset Goals and Tasks. Goal.clear()
def tearDown(self): """ :API: public """ Goal.clear() super().tearDown()
def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC), ) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( self._INSTALLED_HEADER, ' %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC), )
def test_list_goals_graph(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( 'digraph G {\n rankdir=LR;\n graph [compound=true];', ' subgraph cluster_goals {\n node [style=filled];\n color = blue;\n label = "goals";', ' goals_goals [label="goals"];', ' }', ' subgraph cluster_llama {\n node [style=filled];\n color = blue;\n label = "llama";', ' llama_llama [label="llama"];', ' }', ' subgraph cluster_alpaca {\n node [style=filled];\n color = blue;\n label = "alpaca";', ' alpaca_alpaca [label="alpaca"];', ' }', ' alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];', '}', args=['--test-graph'], )
def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) # Goals with no tasks should always be elided. list_goals_goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) self.assert_console_output(self._INSTALLED_HEADER) list_goals_goal.install(self._LIST_GOALS_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC).install(self._LLAMA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) Goal.register(self._ALPACA_NAME, description='').install(self._ALPACA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), )
def setUp(self): super(EngineTestBase, self).setUp() # TODO(John Sirois): Now that the BuildFileParser controls goal registration by iterating # over plugin callbacks a GoalRegistry can be constructed by it and handed to all these # callbacks in place of having a global Goal registry. Remove the Goal static cling. Goal.clear()
def test_load_valid_partial_goals(self): def register_goals(): Goal.by_name("jack").install(TaskRegistrar("jill", DummyTask)) with self.create_register( register_goals=register_goals) as backend_package: Goal.clear() self.assertEqual(0, len(Goal.all())) load_backend(self.build_configuration, backend_package, is_v1_backend=False) self.assertEqual(0, len(Goal.all())) load_backend(self.build_configuration, backend_package, is_v1_backend=True) self.assert_empty_aliases() self.assertEqual(1, len(Goal.all())) task_names = Goal.by_name("jack").ordered_task_names() self.assertEqual(1, len(task_names)) task_name = task_names[0] self.assertEqual("jill", task_name)
def setUp(self): Goal.clear() super(ConsoleTaskTestBase, self).setUp() task_type = self.task_type() assert issubclass(task_type, ConsoleTask), \ 'task_type() must return a ConsoleTask subclass, got %s' % task_type
def test_list_goals_graph(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( 'digraph G {\n rankdir=LR;\n graph [compound=true];', ' subgraph cluster_goals {\n node [style=filled];\n color = blue;\n label = "goals";', ' goals_goals [label="goals"];', ' }', ' subgraph cluster_llama {\n node [style=filled];\n color = blue;\n label = "llama";', ' llama_llama [label="llama"];', ' }', ' subgraph cluster_alpaca {\n node [style=filled];\n color = blue;\n label = "alpaca";', ' alpaca_alpaca [label="alpaca"];', ' }', ' alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];', '}', args=['--test-graph'], )
def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), )
def tearDown(self): """ :API: public """ Goal.clear() super(EngineTestBase, self).tearDown()
def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) # Goals with no tasks should always be elided. list_goals_goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) self.assert_console_output(self._INSTALLED_HEADER) list_goals_goal.install(self._LIST_GOALS_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC).install(self._LLAMA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) Goal.register(self._ALPACA_NAME, description='').install(self._ALPACA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), )
def setUp(self): Goal.clear() super(ConsoleTaskTest, self).setUp() task_type = self.task_type() assert issubclass(task_type, ConsoleTask), \ 'task_type() must return a ConsoleTask subclass, got %s' % task_type
def clean_global_runtime_state(): """Resets the global runtime state of a pants runtime for cleaner forking.""" # Reset RunTracker state. RunTracker.global_instance().reset(reset_options=False) # Reset Goals and Tasks. Goal.clear()
def setUp(self): """ :API: public """ Goal.clear() super().setUp() task_type = self.task_type() assert issubclass(task_type, ConsoleTask), \ 'task_type() must return a ConsoleTask subclass, got %s' % task_type
def _clean_runtime_state(self): """Resets the runtime state from running ./pants -> running in the fork()'d daemon context.""" # TODO(kwlzn): Make this logic available to PantsRunner et al for inline state reset before # pants runs to improve testability and avoid potential bitrot. # Reset RunTracker state. RunTracker.global_instance().reset(reset_options=False) # Reset Goals and Tasks. Goal.clear()
def setUp(self): Goal.clear() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) BuildRoot().path = self.build_root self.create_file('pants.ini') build_configuration = BuildConfiguration() build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(build_configuration, self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser) self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def test_task_subclass_singletons(self): # Install the same task class twice (before/after Goal.clear()) and confirm that the # resulting task is equal. class MyTask(Task): pass def install(): reg = super(RoundEngineTest, self).install_task(name='task1', action=MyTask, goal='goal1') return reg.task_types() task1_pre, = install() Goal.clear() task1_post, = install() self.assertEquals(task1_pre, task1_post)
def setUp(self): Goal.clear() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) BuildRoot().path = self.build_root self.create_file('pants.ini') build_configuration = BuildConfiguration() build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(build_configuration, self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser) self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def clean_global_runtime_state(reset_subsystem=False): """Resets the global runtime state of a pants runtime for cleaner forking. :param bool reset_subsystem: Whether or not to clean Subsystem global state. """ if reset_subsystem: # Reset subsystem state. Subsystem.reset() # Reset Goals and Tasks. Goal.clear() # Reset global plugin state. BuildConfigInitializer.reset()
def setUp(self): super(BaseTest, self).setUp() Goal.clear() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) self.new_options = defaultdict(dict) # scope -> key-value mapping. BuildRoot().path = self.build_root self.create_file('pants.ini') build_configuration = BuildConfiguration() build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(build_configuration, self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser) self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def clean_global_runtime_state(reset_subsystem=False): """Resets the global runtime state of a pants runtime for cleaner forking. :param bool reset_subsystem: Whether or not to clean Subsystem global state. """ if reset_subsystem: # Reset subsystem state. Subsystem.reset() # Reset Goals and Tasks. Goal.clear() # Reset backend/plugins state. OptionsInitializer.reset()
def test_list_goals_all(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), '', self._UNDOCUMENTED_HEADER, ' {0}'.format(self._ALPACA_NAME), options={'all': True} )
def test_task_subclass_singletons(self): # Install the same task class twice (before/after Goal.clear()) and confirm that the # resulting task is equal. class MyTask(Task): pass def install(): reg = super(RoundEngineTest, self).install_task(name="task1", action=MyTask, goal="goal1") return reg.task_types() (task1_pre, ) = install() Goal.clear() (task1_post, ) = install() self.assertEqual(task1_pre, task1_post)
def test_list_goals_all(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output(self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), '', self._UNDOCUMENTED_HEADER, ' {0}'.format(self._ALPACA_NAME), options={'all': True})
def test_register_duplicate_task_name_is_not_error_when_replacing(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) goal.install(TaskRegistrar(task_name, OtherNoopTask), replace=True) self.assertTrue(issubclass(goal.task_type_by_name(task_name), OtherNoopTask))
def test_register_duplicate_task_name_is_not_error_when_replacing(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) goal.install(TaskRegistrar(task_name, OtherNoopTask), replace=True) self.assertTrue(issubclass(goal.task_type_by_name(task_name), OtherNoopTask))
def test_load_valid_partial_goals(self): def register_goals(): Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask)) with self.create_register(register_goals=register_goals) as backend_package: Goal.clear() self.assertEqual(0, len(Goal.all())) load_backend(self.build_configuration, backend_package) self.assert_empty_aliases() self.assertEqual(1, len(Goal.all())) task_names = Goal.by_name('jack').ordered_task_names() self.assertEqual(1, len(task_names)) task_name = task_names[0] self.assertEqual('jill', task_name)
def test_load_valid_partial_goals(self): def register_goals(): Goal.by_name('jack').install(TaskRegistrar('jill', lambda: 42)) with self.create_register(register_goals=register_goals) as backend_package: Goal.clear() self.assertEqual(0, len(Goal.all())) load_backend(self.build_configuration, backend_package) self.assert_empty_aliases() self.assertEqual(1, len(Goal.all())) task_names = Goal.by_name('jack').ordered_task_names() self.assertEqual(1, len(task_names)) task_name = task_names[0] self.assertEqual('jill', task_name)
def setUp(self): """ :API: public """ super(BaseTest, self).setUp() Goal.clear() Subsystem.reset() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) self.subprocess_dir = os.path.join(self.build_root, '.pids') self.addCleanup(safe_rmtree, self.build_root) self.pants_workdir = os.path.join(self.build_root, '.pants.d') safe_mkdir(self.pants_workdir) self.options = defaultdict(dict) # scope -> key-value mapping. self.options[''] = { 'pants_workdir': self.pants_workdir, 'pants_supportdir': os.path.join(self.build_root, 'build-support'), 'pants_distdir': os.path.join(self.build_root, 'dist'), 'pants_configdir': os.path.join(self.build_root, 'config'), 'pants_subprocessdir': self.subprocess_dir, 'cache_key_gen_version': '0-test', } self.options['cache'] = { 'read_from': [], 'write_to': [], } BuildRoot().path = self.build_root self.addCleanup(BuildRoot().reset) self._build_configuration = BuildConfiguration() self._build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root) self.project_tree = FileSystemProjectTree(self.build_root) self.address_mapper = BuildFileAddressMapper( self.build_file_parser, self.project_tree, build_ignore_patterns=self.build_ignore_patterns) self.build_graph = MutableBuildGraph( address_mapper=self.address_mapper)
def test_list_goals_all(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC).install(self._LIST_GOALS_TASK) # Goals with no tasks should always be elided. Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) Goal.register(self._ALPACA_NAME, description='').install(self._ALPACA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), '', self._UNDOCUMENTED_HEADER, ' {0}'.format(self._ALPACA_NAME), options={'all': True} )
def test_list_goals_all(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC).install(self._LIST_GOALS_TASK) # Goals with no tasks should always be elided. Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) Goal.register(self._ALPACA_NAME, description='').install(self._ALPACA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), '', self._UNDOCUMENTED_HEADER, ' {0}'.format(self._ALPACA_NAME), options={'all': True} )
def test_list_goals_all(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), '', self._UNDOCUMENTED_HEADER, ' {0}'.format(self._ALPACA_NAME), options={'all': True} )
def clean_global_runtime_state(reset_runtracker=True, reset_subsystem=False): """Resets the global runtime state of a pants runtime for cleaner forking. :param bool reset_runtracker: Whether or not to clean RunTracker global state. :param bool reset_subsystem: Whether or not to clean Subsystem global state. """ if reset_runtracker: # Reset RunTracker state. RunTracker.global_instance().reset(reset_options=False) if reset_subsystem: # Reset subsystem state. Subsystem.reset() # Reset Goals and Tasks. Goal.clear() # Reset backend/plugins state. OptionsInitializer.reset()
def test_list_goals_all(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( self._INSTALLED_HEADER, ' %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC), '', self._UNDOCUMENTED_HEADER, ' %s' % self._ALPACA_NAME, args=['--test-all'], )
def test_register_duplicate_task_name_is_error(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) with self.assertRaises(GoalError) as ctx: goal.install(TaskRegistrar(task_name, OtherNoopTask)) self.assertIn('foo', ctx.exception.message) self.assertIn(self._LIST_GOALS_NAME, ctx.exception.message)
def setUp(self): super(BaseTest, self).setUp() Goal.clear() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) self.options = defaultdict(dict) # scope -> key-value mapping. self.options[''] = { 'pants_workdir': os.path.join(self.build_root, '.pants.d'), 'pants_supportdir': os.path.join(self.build_root, 'build-support'), 'pants_distdir': os.path.join(self.build_root, 'dist'), 'cache_key_gen_version': '0-test' } BuildRoot().path = self.build_root self.create_file('pants.ini') build_configuration = BuildConfiguration() build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(build_configuration, self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser) self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def setUp(self): super(BaseTest, self).setUp() Goal.clear() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) self.new_options = defaultdict(dict) # scope -> key-value mapping. self.new_options[''] = { 'pants_workdir': os.path.join(self.build_root, '.pants.d'), 'pants_supportdir': os.path.join(self.build_root, 'build-support'), 'pants_distdir': os.path.join(self.build_root, 'dist') } BuildRoot().path = self.build_root self.create_file('pants.ini') build_configuration = BuildConfiguration() build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(build_configuration, self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser) self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def test_list_goals_all(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals).install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask).install().with_description( self._LLAMA_DESC ) TaskRegistrar( name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME] ).install() self.assert_console_output( self._INSTALLED_HEADER, " %s: %s" % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), " %s: %s" % (self._LLAMA_NAME, self._LLAMA_DESC), "", self._UNDOCUMENTED_HEADER, " %s" % self._ALPACA_NAME, args=["--test-all"], )
def test_register_duplicate_task_name_is_error(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) with self.assertRaises(GoalError) as ctx: goal.install(TaskRegistrar(task_name, OtherNoopTask)) self.assertIn('foo', ctx.exception.message) self.assertIn(self._LIST_GOALS_NAME, ctx.exception.message)
def setUp(self): """ :API: public """ super(BaseTest, self).setUp() Goal.clear() Subsystem.reset() self.real_build_root = BuildRoot().path self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT')) self.subprocess_dir = os.path.join(self.build_root, '.pids') self.addCleanup(safe_rmtree, self.build_root) self.pants_workdir = os.path.join(self.build_root, '.pants.d') safe_mkdir(self.pants_workdir) self.options = defaultdict(dict) # scope -> key-value mapping. self.options[''] = { 'pants_workdir': self.pants_workdir, 'pants_supportdir': os.path.join(self.build_root, 'build-support'), 'pants_distdir': os.path.join(self.build_root, 'dist'), 'pants_configdir': os.path.join(self.build_root, 'config'), 'pants_subprocessdir': self.subprocess_dir, 'cache_key_gen_version': '0-test', } self.options['cache'] = { 'read_from': [], 'write_to': [], } BuildRoot().path = self.build_root self.addCleanup(BuildRoot().reset) self._build_configuration = BuildConfiguration() self._build_configuration.register_aliases(self.alias_groups) self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root) self.project_tree = FileSystemProjectTree(self.build_root) self.address_mapper = BuildFileAddressMapper(self.build_file_parser, self.project_tree, build_ignore_patterns=self.build_ignore_patterns) self.build_graph = MutableBuildGraph(address_mapper=self.address_mapper)
def test_list_goals_graph(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output( 'digraph G {\n rankdir=LR;\n graph [compound=true];', ' subgraph cluster_goals {\n node [style=filled];\n color = blue;\n label = "goals";', ' goals_goals [label="goals"];', ' }', ' subgraph cluster_llama {\n node [style=filled];\n color = blue;\n label = "llama";', ' llama_llama [label="llama"];', ' }', ' subgraph cluster_alpaca {\n node [style=filled];\n color = blue;\n label = "alpaca";', ' alpaca_alpaca [label="alpaca"];', ' }', ' alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];', '}', options={'graph': True})
def test_list_goals_graph(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC).install(self._LIST_GOALS_TASK) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC).install(self._LLAMA_TASK) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output( 'digraph G {\n rankdir=LR;\n graph [compound=true];', ' subgraph cluster_goals {\n node [style=filled];\n color = blue;\n label = "goals";', ' goals_goals [label="goals"];', ' }', ' subgraph cluster_llama {\n node [style=filled];\n color = blue;\n label = "llama";', ' llama_llama [label="llama"];', ' }', ' subgraph cluster_alpaca {\n node [style=filled];\n color = blue;\n label = "alpaca";', ' alpaca_alpaca [label="alpaca"];', ' }', ' alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];', '}', options={'graph': True} )
def clean_global_runtime_state(reset_runtracker=True, reset_subsystem=False): """Resets the global runtime state of a pants runtime for cleaner forking. :param bool reset_runtracker: Whether or not to clean RunTracker global state. :param bool reset_subsystem: Whether or not to clean Subsystem global state. """ if reset_runtracker: # Reset RunTracker state. RunTracker.global_instance().reset(reset_options=False) if reset_subsystem: # Reset subsystem state. Subsystem.reset() #TODO: Think of an alternative for IntermediateTargetFactoryBase._targets to avoid this call IntermediateTargetFactoryBase.reset() # Reset Goals and Tasks. Goal.clear() # Reset backend/plugins state. OptionsInitializer.reset()
def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), )
def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), )
def tearDown(self): Goal.clear()
def tearDown(self): super(GoalTest, self).tearDown() Goal.clear()
def tearDown(self): Goal.clear() super(EngineTestBase, self).tearDown()
def tearDown(self): Goal.clear()
def tearDown(self): Goal.clear() super(EngineTestBase, self).tearDown()