def _do_check(self, project_dir_path, expected_project_path, expected_targets): """Check to see that the project contains the expected source folders.""" iws_file = os.path.join(project_dir_path, '{}.iws'.format(IdeaPluginGen.get_project_name(expected_targets))) self.assertTrue(os.path.exists(iws_file)) dom = minidom.parse(iws_file) self.assertEqual(1, len(dom.getElementsByTagName("project"))) project = dom.getElementsByTagName("project")[0] self.assertEqual(1, len(project.getElementsByTagName('component'))) component = project.getElementsByTagName('component')[0] actual_properties = component.getElementsByTagName('property') # 3 properties: targets, project_path, pants_idea_plugin_version self.assertEqual(3, len(actual_properties)) self.assertEqual('targets', actual_properties[0].getAttribute('name')) actual_targets = json.loads(actual_properties[0].getAttribute('value')) abs_expected_target_specs = [os.path.join(get_buildroot(), relative_spec) for relative_spec in expected_targets] self.assertEqual(abs_expected_target_specs, actual_targets) self.assertEqual('project_path', actual_properties[1].getAttribute('name')) actual_project_path = actual_properties[1].getAttribute('value') self.assertEqual(os.path.join(get_buildroot(), expected_project_path), actual_project_path) self.assertEqual('pants_idea_plugin_version', actual_properties[2].getAttribute('name')) self.assertEqual(IDEA_PLUGIN_VERSION, actual_properties[2].getAttribute('value'))
def test_idea_plugin_project_name(self): self.assertEqual( 'examples.src.scala.org.pantsbuild.example.hello:__testprojects.src.python.antlr::', IdeaPluginGen.get_project_name([ 'examples/src/scala/org/pantsbuild/example/hello:', 'testprojects/src/python/antlr::' ]))
def test_project_name(self) -> None: targets = [ 'examples/src/scala/org/pantsbuild/example/hello:', 'testprojects/src/python/antlr::', ] self.assertEqual( 'examples.src.scala.org.pantsbuild.example.hello:__testprojects.src.python.antlr::', IdeaPluginGen.get_project_name(targets))
def test_project_name(self) -> None: targets = [ "examples/src/scala/org/pantsbuild/example/hello:", "testprojects/src/python/sources::", ] self.assertEqual( "examples.src.scala.org.pantsbuild.example.hello:__testprojects.src.python.sources::", IdeaPluginGen.get_project_name(targets), )
def _do_check(self, project_dir_path, expected_project_path, expected_targets, incremental_import=None): """Check to see that the project contains the expected source folders.""" iws_file = os.path.join( project_dir_path, '{}.iws'.format(IdeaPluginGen.get_project_name(expected_targets))) self.assertTrue(os.path.exists(iws_file)) dom = minidom.parse(iws_file) self.assertEqual(1, len(dom.getElementsByTagName("project"))) project = dom.getElementsByTagName("project")[0] self.assertEqual(1, len(project.getElementsByTagName('component'))) component = project.getElementsByTagName('component')[0] actual_properties = component.getElementsByTagName('property') valid_property_names = { 'targets', 'project_path', 'pants_idea_plugin_version', 'incremental_import' } self.assertTrue({p.getAttribute('name') for p in actual_properties }.issubset(valid_property_names)) self.assertTrue(len(actual_properties) >= 3) self.assertEqual('targets', actual_properties[0].getAttribute('name')) actual_targets = json.loads(actual_properties[0].getAttribute('value')) abs_expected_target_specs = [ os.path.join(get_buildroot(), relative_spec) for relative_spec in expected_targets ] self.assertEqual(abs_expected_target_specs, actual_targets) self.assertEqual('project_path', actual_properties[1].getAttribute('name')) actual_project_path = actual_properties[1].getAttribute('value') self.assertEqual(os.path.join(get_buildroot(), expected_project_path), actual_project_path) self.assertEqual('pants_idea_plugin_version', actual_properties[2].getAttribute('name')) self.assertEqual(IDEA_PLUGIN_VERSION, actual_properties[2].getAttribute('value')) incremental_import_props = [ p for p in actual_properties if p.getAttribute('name') == 'incremental_import' ] if incremental_import is None: self.assertEqual(incremental_import_props, []) else: self.assertEqual( [str(incremental_import)], [p.getAttribute('value') for p in incremental_import_props])
def test_idea_plugin_long_project_name(self): list_run = self.run_pants(['-q', 'list', 'testprojects/tests/java/org/pantsbuild/testproject/::']) self.assert_success(list_run) self.assertGreater(len(list_run.stdout_data), IdeaPluginGen.PROJECT_NAME_LIMIT) a_lot_of_targets = [l for l in list_run.stdout_data.splitlines() if l] self.assertEqual(IdeaPluginGen.PROJECT_NAME_LIMIT, len(IdeaPluginGen.get_project_name(a_lot_of_targets))) self._run_and_check(a_lot_of_targets)
def test_idea_plugin_project_name(self): self.assertEqual( 'examples.src.scala.org.pantsbuild.example.hello:__testprojects.src.python.antlr::', IdeaPluginGen.get_project_name([ 'examples/src/scala/org/pantsbuild/example/hello:', 'testprojects/src/python/antlr::' ] ) )
def test_long_project_name(self) -> None: targets = [ 'examples/src/scala/org/pantsbuild/example/hello/really/long/fake/project/name:', 'testprojects/src/python/antlr::', 'testprojects/src/python/sources::', 'testprojects/src/python/unicode::', 'testprojects/src/python/another/long/project/name::', ] self.assertGreater(len("".join(targets)), IdeaPluginGen.PROJECT_NAME_LIMIT) self.assertEqual(( 'examples.src.scala.org.pantsbuild.example.hello.really.long.fake.project.name:' '__testprojects.src.python.antlr::' '__testprojects.src.python.sources::' '__testprojects.src.python.unicode::' '__testprojects.src.python.another.long.project.name::' )[:IdeaPluginGen.PROJECT_NAME_LIMIT], IdeaPluginGen.get_project_name(targets))
def _do_check(self, project_dir_path, expected_project_path, expected_targets, incremental_import=None): """Check to see that the project contains the expected source folders.""" iws_file = os.path.join(project_dir_path, '{}.iws'.format(IdeaPluginGen.get_project_name(expected_targets))) self.assertTrue(os.path.exists(iws_file)) dom = minidom.parse(iws_file) self.assertEqual(1, len(dom.getElementsByTagName("project"))) project = dom.getElementsByTagName("project")[0] self.assertEqual(1, len(project.getElementsByTagName('component'))) component = project.getElementsByTagName('component')[0] actual_properties = component.getElementsByTagName('property') valid_property_names = { 'targets', 'project_path', 'pants_idea_plugin_version', 'incremental_import' } self.assertTrue({p.getAttribute('name') for p in actual_properties}.issubset(valid_property_names)) self.assertTrue(len(actual_properties) >= 3) self.assertEqual('targets', actual_properties[0].getAttribute('name')) actual_targets = json.loads(actual_properties[0].getAttribute('value')) abs_expected_target_specs = [os.path.join(get_buildroot(), relative_spec) for relative_spec in expected_targets] self.assertEqual(abs_expected_target_specs, actual_targets) self.assertEqual('project_path', actual_properties[1].getAttribute('name')) actual_project_path = actual_properties[1].getAttribute('value') self.assertEqual(os.path.join(get_buildroot(), expected_project_path), actual_project_path) self.assertEqual('pants_idea_plugin_version', actual_properties[2].getAttribute('name')) self.assertEqual(IDEA_PLUGIN_VERSION, actual_properties[2].getAttribute('value')) incremental_import_props = [p for p in actual_properties if p.getAttribute('name') == 'incremental_import'] if incremental_import is None: self.assertEqual(incremental_import_props, []) else: self.assertEqual([str(incremental_import)], [p.getAttribute('value') for p in incremental_import_props])
def _do_check(self, project_dir_path, expected_project_path, expected_targets): """Check to see that the project contains the expected source folders.""" iws_file = os.path.join( project_dir_path, '{}.iws'.format(IdeaPluginGen.get_project_name(expected_targets))) self.assertTrue(os.path.exists(iws_file)) dom = minidom.parse(iws_file) self.assertEqual(1, len(dom.getElementsByTagName("project"))) project = dom.getElementsByTagName("project")[0] self.assertEqual(1, len(project.getElementsByTagName('component'))) component = project.getElementsByTagName('component')[0] actual_properties = component.getElementsByTagName('property') # 3 properties: targets, project_path, pants_idea_plugin_version self.assertEqual(3, len(actual_properties)) self.assertEqual('targets', actual_properties[0].getAttribute('name')) actual_targets = json.loads(actual_properties[0].getAttribute('value')) abs_expected_target_specs = [ os.path.join(get_buildroot(), relative_spec) for relative_spec in expected_targets ] self.assertEqual(abs_expected_target_specs, actual_targets) self.assertEqual('project_path', actual_properties[1].getAttribute('name')) actual_project_path = actual_properties[1].getAttribute('value') self.assertEqual(os.path.join(get_buildroot(), expected_project_path), actual_project_path) self.assertEqual('pants_idea_plugin_version', actual_properties[2].getAttribute('name')) self.assertEqual(IDEA_PLUGIN_VERSION, actual_properties[2].getAttribute('value'))