示例#1
0
    def testNothingToExport(self):
        project = test_util.EmptyMoeProjectConfig()

        internal_creator = test_util.StaticCodebaseCreator({
            '1001':
            'simple_python',
            '1002':
            'simple_python'
        })

        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'simple_python'})

        config = actions.MigrationConfig(base.Migration.EXPORT,
                                         internal_creator,
                                         project.internal_repository_config,
                                         public_creator,
                                         project.public_repository_config,
                                         None, project.export_strategy)
        revisions = [base.Revision('1002')]
        export = actions.Migration(base.Revision('1001'), base.Revision('1'),
                                   revisions, project, [], config, False, -1)

        result = export.Perform()
        self.assertEqual(result, None)
示例#2
0
    def testErrorsOnLastBrokenCodebase(self):
        mock_db = test_util.MockDbClient(migration_id_seed=88)
        mock_editor = test_util.MockEditor()
        mock_client = test_util.MockClient(
            lambda migration_strategy, revisions: mock_editor)
        report = base.MoeReport()
        project = test_util.EmptyMoeProjectConfig()

        internal_creator = test_util.StaticCodebaseCreator(
            {
                '1001': 'simple_python',
                '1002': None,
            }, lambda: mock_client)

        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'simple_python'})

        config = actions.MigrationConfig(base.Migration.EXPORT,
                                         internal_creator,
                                         project.internal_repository_config,
                                         public_creator,
                                         project.public_repository_config,
                                         None, project.export_strategy)
        revisions = [base.Revision('1002', changelog='1002')]
        action = actions.Migration(base.Revision('1001'), base.Revision('1'),
                                   revisions, project, [], config, False, 1)

        self.assertRaises(base.CodebaseCreationError,
                          action.Perform,
                          db=mock_db)
示例#3
0
    def testSingleImport(self):
        mock_db = test_util.MockDbClient(migration_id_seed=88)
        mock_editor = test_util.MockEditor()
        mock_client = test_util.MockClient(
            lambda migration_strategy, revisions: mock_editor)
        project = test_util.EmptyMoeProjectConfig()

        internal_creator = test_util.StaticCodebaseCreator(
            {'1001': 'simple_python'}, lambda: mock_client)

        public_creator = test_util.StaticCodebaseCreator({
            '1': 'simple_python',
            '2': 'simple_python2'
        })

        config = actions.MigrationConfig(base.Migration.IMPORT, public_creator,
                                         project.public_repository_config,
                                         internal_creator,
                                         project.internal_repository_config,
                                         None, project.import_strategy)
        revisions = [base.Revision('2', changelog='log')]
        action = actions.Migration(base.Revision('1'), base.Revision('1001'),
                                   revisions, project, [], config, False, -1)

        result = action.Perform(db=mock_db)
        self.assertFalse(result)
        self.assertTrue(mock_editor.ChangesMade())

        expected = base.Migration(migration_id='88',
                                  direction=base.Migration.IMPORT,
                                  status=base.Migration.ACTIVE,
                                  up_to_revision=base.Revision('2'),
                                  changelog='log',
                                  revisions=revisions)
        self.assertEqual(mock_db.GetMigration('88').Dict(), expected.Dict())
示例#4
0
    def testDivideMultipleChangelogs(self):
        mock_db = test_util.MockDbClient()
        mock_editor = test_util.MockEditor()
        mock_client = test_util.MockClient(
            lambda migration_strategy, revisions: mock_editor)
        project = test_util.EmptyMoeProjectConfig()
        project.export_strategy.separate_revisions = True

        internal_creator = test_util.StaticCodebaseCreator({
            '1001':
            'simple_python',
            '1002':
            'simple_python2',
            '1003':
            'simple_python',
            '1004':
            'simple_python2'
        })

        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'simple_python'}, lambda: mock_client)

        config = actions.MigrationConfig(base.Migration.EXPORT,
                                         internal_creator,
                                         project.internal_repository_config,
                                         public_creator,
                                         project.public_repository_config,
                                         None, project.export_strategy)
        revisions = [
            base.Revision('1002',
                          changelog='Change 1: a change',
                          single_scrubbed_log='a change'),
            base.Revision('1003',
                          changelog='Change 2: another change',
                          single_scrubbed_log='another change'),
            base.Revision('1004',
                          changelog='Change 3: something',
                          single_scrubbed_log='something')
        ]
        action = actions.Migration(base.Revision('1001'), base.Revision('1'),
                                   revisions, project, [], config, False, 1)

        result = action.Perform(db=mock_db)
        self.assertEqual(len(result.actions), 1)
        self.assertEqual(
            mock_db.GetMigration('1', abbreviated=False).changelog, 'a change')

        result = result.actions[0].Perform(db=mock_db)
        self.assertEqual(len(result.actions), 1)
        self.assertEqual(
            mock_db.GetMigration('2', abbreviated=False).changelog,
            'another change')

        result = result.actions[0].Perform(db=mock_db)
        self.assertEqual(result, None)
        self.assertEqual(
            mock_db.GetMigration('3', abbreviated=False).changelog,
            'something')
示例#5
0
def RevisionsFromDicts(revision_dicts):
    return [
        base.Revision(r['rev_id'],
                      r['repository_name'],
                      author=r.get('author'),
                      time=r.get('time')) for r in revision_dicts
    ]
示例#6
0
文件: svn.py 项目: pir8aye/MOE-py
def ParseRevisions(text, repository_name):
    """Extract separate revisions out of the xml output of an svn log call."""
    # TODO(user): This should always scrub out MOE_MIGRATION lines
    rev_tree = ElementTree.XML(text.encode('UTF-8'))
    result = []
    for entry in rev_tree.findall('logentry'):
        rev_id = entry.get('revision')

        changelog = ''
        if entry.find('msg') is not None:
            changelog = entry.find('msg').text or ''

        author = ''
        if entry.find('author') is not None:
            author = entry.find('author').text or ''

        time = ''
        if entry.find('date') is not None:
            time = entry.find('date').text or ''

        result.append(
            base.Revision(rev_id=rev_id,
                          repository_name=repository_name,
                          changelog=changelog,
                          author=author,
                          time=time))
    return result
示例#7
0
    def testSingleExportCommit(self):
        mock_db = test_util.MockDbClient(migration_id_seed=88)
        mock_editor = test_util.MockEditor(commit_id='2')
        mock_client = test_util.MockClient(
            lambda migration_strategy, revisions: mock_editor)
        report = base.MoeReport()
        project = test_util.EmptyMoeProjectConfig()
        project.public_repository_config = test_util.MockRepositoryConfig(
            '', repository=test_util.MockRepository(''))

        internal_creator = test_util.StaticCodebaseCreator({
            '1001':
            'simple_python',
            '1002':
            'simple_python2'
        })

        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'simple_python'}, lambda: mock_client)

        config = actions.MigrationConfig(
            base.Migration.EXPORT, internal_creator,
            project.internal_repository_config, public_creator,
            project.public_repository_config,
            project.public_repository_config.MakeRepository()[0],
            project.export_strategy)
        revisions = [base.Revision('1002', changelog='log')]
        action = actions.Migration(base.Revision('1001'), base.Revision('1'),
                                   revisions, project, [], config, False, -1)

        result = action.Perform(db=mock_db)
        equivalence_check = result.actions[0]
        self.assertEqual(equivalence_check.internal_revision, '1002')
        self.assertEqual(equivalence_check.public_revision, '2')
        self.assertFalse(result.actions[1:])
        self.assertTrue(mock_editor.ChangesMade())

        expected = base.Migration(
            migration_id='88',
            direction=base.Migration.EXPORT,
            status=base.Migration.SUBMITTED,
            up_to_revision=base.Revision('1002'),
            revisions=revisions,
            submitted_as=base.Revision('2'),
            changelog='log',
        )
        self.assertEqual(mock_db.GetMigration('88').Dict(), expected.Dict())
示例#8
0
def ParseRevisions(log, repository_name):
    """Extract separate revisions out of the output of a verbose hg log call."""
    # TODO(user): perhaps use a mercurial template to make this job easier
    result = []
    description_lines = []
    rev_id = None
    time = None
    author = None
    in_description = False
    for line in log.splitlines():
        if CHANGESET_RE.match(line):
            if rev_id:
                result.append(
                    base.Revision(rev_id=rev_id,
                                  repository_name=repository_name,
                                  time=time,
                                  author=author,
                                  changelog='\n'.join(description_lines)))
                rev_id = None
                time = None
                author = None
                description_lines = []
            rev_id = CHANGESET_RE.match(line).group(2)
        elif USER_RE.match(line):
            author = USER_RE.match(line).group(1)
        elif DATE_RE.match(line):
            time = DATE_RE.match(line).group(1).strip()
        elif TAG_RE.match(line):
            pass
        elif FILES_RE.match(line):
            in_description = False
        else:
            if DESCRIPTION_RE.match(line):
                in_description = True
                line = DESCRIPTION_RE.match(line).group(1)
            if in_description:
                description_lines.append(line)
    if rev_id:
        result.append(
            base.Revision(rev_id=rev_id,
                          repository_name=repository_name,
                          time=time,
                          author=author,
                          changelog='\n'.join(description_lines)))
    return result
示例#9
0
    def testSkipsBrokenCodebase(self):
        mock_db = test_util.MockDbClient(migration_id_seed=88)
        mock_editor = test_util.MockEditor()
        mock_client = test_util.MockClient(
            lambda migration_strategy, revisions: mock_editor)
        project = test_util.EmptyMoeProjectConfig()

        internal_creator = test_util.StaticCodebaseCreator(
            {
                '1001': 'simple_python',
                '1002': None,
                '1003': 'simple_python2',
            }, lambda: mock_client)

        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'simple_python'})

        config = actions.MigrationConfig(base.Migration.EXPORT,
                                         internal_creator,
                                         project.internal_repository_config,
                                         public_creator,
                                         project.export_strategy, None,
                                         project.public_repository_config)
        revisions = [
            base.Revision('1002', changelog='1002'),
            base.Revision('1003', changelog='1003')
        ]
        action = actions.Migration(base.Revision('1001'), base.Revision('1'),
                                   revisions, project, [], config, False, 1)

        result = action.Perform(db=mock_db)
        migration = result.actions[0]
        migrated_revisions = migration.revisions
        # because we couldn't migrate 1002 on its own, we now want to migrate
        # 1002 *and* 1003
        self.assertEqual(len(migrated_revisions), 2)
        self.assertEqual(migrated_revisions[0].rev_id, '1002')
        self.assertEqual(migrated_revisions[1].rev_id, '1003')
示例#10
0
文件: db_test.py 项目: pir8aye/MOE-py
def PublicRevision(rev_id, project, **kwargs):
    return base.Revision(rev_id,
                         project.public_repository_config.Info()['name'],
                         **kwargs)
示例#11
0
文件: db_test.py 项目: pir8aye/MOE-py
def InternalRevision(rev_id, project, **kwargs):
    return base.Revision(rev_id,
                         project.internal_repository_config.Info()['name'],
                         **kwargs)
示例#12
0
 def MakeRevisionFromId(self, id):
     self._Pull()
     return base.Revision(rev_id=id, repository_name=self._name)
示例#13
0
 def RecurUntilMatchingRevision(self, *args, **kwargs):
   return [base.Revision(r) for r in
           self.recur_until_matching_revision_results]