示例#1
0
 def _parse_commit(self, commit):
     return git.Commit(
         commit.oid.hex,
         str('%s <%s>' % (
             commit.author.name, commit.author.email)),
         timestamps.Timestamp(commit.author.time,
                              commit.author.offset),
         str('%s <%s>' % (
             commit.committer.name, commit.committer.email)),
         timestamps.Timestamp(commit.committer.time,
                              commit.committer.offset),
         str(commit.message),
         [x.oid.hex for x in commit.parents])
    def test_message_subject_and_body_are_extracted_correctly(self):
        """Verify that commit messages are split into subject and body."""

        messages = {
            '': ['', ''],
            'Implement the ReferenceProperty class, with unit tests':
            ('Implement the ReferenceProperty class, with unit tests', ''),
            '''Implement the first batch of property classes

This commit implements the following property classes:

* consonant.store.properties.Property
* consonant.store.properties.IntProperty
* consonant.store.properties.FloatProperty
* consonant.store.properties.BooleanProperty
* consonant.store.properties.TextProperty
* consonant.store.properties.TimestampProperty

Unit tests for all these classes are included.''':
            ('Implement the first batch of property classes',
             '''This commit implements the following property classes:

* consonant.store.properties.Property
* consonant.store.properties.IntProperty
* consonant.store.properties.FloatProperty
* consonant.store.properties.BooleanProperty
* consonant.store.properties.TextProperty
* consonant.store.properties.TimestampProperty

Unit tests for all these classes are included.''')
        }

        for message, data in messages.iteritems():
            subject, body = data

            commit = git.Commit('sha1', 'author', 'author date', 'comitter',
                                'committer date', message,
                                ['parent1', 'parent2'])
            self.assertEqual(commit.message, message)
            self.assertEqual(commit.message_subject(), subject)
            self.assertEqual(commit.message_body(), body)
    def test_constructor_sets_members_correctly(self):
        """Verify that the constructor sets all members correctly."""

        for sha1, data in self.test_input.iteritems():
            commit = git.Commit(
                sha1, data['author'],
                timestamps.Timestamp.from_raw(data['author-date']),
                data['committer'],
                timestamps.Timestamp.from_raw(data['committer-date']),
                data['message'], data['parents'])

            self.assertEqual(commit.sha1, sha1)
            self.assertEqual(commit.author, data['author'])
            self.assertEqual(
                commit.author_date,
                timestamps.Timestamp.from_raw(data['author-date']))
            self.assertEqual(commit.committer, data['committer'])
            self.assertEqual(
                commit.committer_date,
                timestamps.Timestamp.from_raw(data['committer-date']))
            self.assertEqual(commit.message, data['message'])
            self.assertEqual(commit.parents, data['parents'])
    def test_json_representation_has_all_expected_fields(self):
        """Verify that the JSON representation of Commit objects is ok."""

        for sha1, data in self.test_input.iteritems():
            commit = git.Commit(
                sha1, data['author'],
                timestamps.Timestamp.from_raw(data['author-date']),
                data['committer'],
                timestamps.Timestamp.from_raw(data['committer-date']),
                data['message'], data['parents'])

            string = json.dumps([commit], cls=JSONObjectEncoder)
            json_data = json.loads(string)
            self.assertEqual(
                json_data,
                [{
                    'sha1': sha1,
                    'author': data['author'],
                    'author-date': data['author-date'],
                    'committer': data['committer'],
                    'committer-date': data['committer-date'],
                    'subject': data['message'].splitlines(True)[0].strip(),
                    'parents': data['parents'],
                }])