示例#1
0
 def _create_module_pool(self, existing_modules):
   if not self.get_options().module_pool:
     return None
   module_type_pattern = re.compile(r'^(?P<generic_modules>gen-\d+$)|(?P<specific_modules>\.pants\.d-)')
   module_types = dict(generic_modules=[], specific_modules=[])
   for filename in existing_modules:
     name, _ = os.path.splitext(filename)
     m = module_type_pattern.match(name)
     if m:
       module_types[m.lastgroup].append(name)
   return IdeaProject.ModulePool(steal_names=self.get_options().module_pool_steal_names,
                                 **module_types)
示例#2
0
 def test_module_pool_stealing(self):
     pool = IdeaProject.ModulePool(generic_modules=('2', '1', '3'),
                                   specific_modules=('b', 'c', 'a'),
                                   steal_names=True)
     self.assertEquals('1', pool.module_for('foobar'))
     self.assertEquals('1', pool.module_for('foobar'))
     self.assertEquals('2', pool.module_for('cantaloupe'))
     self.assertEquals('3', pool.module_for('the-third-number'))
     self.assertEquals('2', pool.module_for('cantaloupe'))
     # The specific modules are stored in an unordered set, so we can't depend on the order.
     no_more = pool.module_for('no-more-gen-modules')
     self.assertIn(no_more, 'abc')
     self.assertEquals(no_more, pool.module_for('no-more-gen-modules'))
     self.assertIn(pool.module_for('this-will-not-explode'), 'abc')
     self.assertNotEquals(no_more, pool.module_for('this-will-not-explode'))
示例#3
0
 def test_module_pool_no_stealing(self):
     pool = IdeaProject.ModulePool(generic_modules=('2', '1', '3'),
                                   specific_modules=('b', 'c', 'a'),
                                   steal_names=False)
     self.assertEquals('1', pool.module_for('foobar'))
     self.assertEquals('1', pool.module_for('foobar'))
     self.assertEquals('2', pool.module_for('cantaloupe'))
     self.assertEquals('3', pool.module_for('the-third-number'))
     self.assertEquals('2', pool.module_for('cantaloupe'))
     self.assertEquals('no-more-gen-modules',
                       pool.module_for('no-more-gen-modules'))
     self.assertEquals('no-more-gen-modules',
                       pool.module_for('no-more-gen-modules'))
     with self.assertRaises(IdeaProject.ModulePool.NoAvailableModules):
         pool.module_for('this-will-explode', create_if_necessary=False)
示例#4
0
 def test_module_pool_preferential(self):
     pool = IdeaProject.ModulePool(generic_modules=('2', '1', '3'),
                                   specific_modules=('b', 'c', 'a'),
                                   steal_names=True)
     self.assertEquals('1', pool.module_for('foobar'))
     self.assertEquals('c', pool.module_for('c'))
     self.assertEquals('2', pool.module_for('the-third-module'))
     self.assertEquals('3', pool.module_for('the-third-number'))
     self.assertEquals('a', pool.module_for('a'))
     self.assertEquals('b', pool.module_for('process-of-elimination'))
     self.assertEquals('c', pool.module_for('c'))
     self.assertEquals('had-to-make-a-new-one',
                       pool.module_for('had-to-make-a-new-one'))
     # 'b' has been stolen, and there are no specific or generic modules left, so this forces a new
     # generic module to be generated.
     self.assertEquals('gen-0000', pool.module_for('b'))