Esempio n. 1
0
    def test_nothing_to_commit_exception_right_after_a_commit(self):
        self.make_first_commit()

        timestamp = int(datetime.now().timestamp())
        author = Signature('Rajat', '*****@*****.**', timestamp,
                           330)
        author.timestamp = int(datetime.now().timestamp())
        with self.assertRaises(NothingToCommitException):
            self.repo.commit(message="Second commit", author=author)
Esempio n. 2
0
 def test_commit_serialization_deserialization(self):
     commit = Commit(get_random_sha1_hash(),
                     parents=[Commit(get_random_sha1_hash())],
                     author=Signature("Some author", "*****@*****.**",
                                      1494659418, 330),
                     committer=Signature("ABC", "*****@*****.**", 1494659418,
                                         90),
                     commit_message="Testing commit",
                     tree=Tree(get_random_sha1_hash()))
     deserialized_commit = self.serializer.deserialize(
         commit.id, self.serializer.serialize(commit))
     self.assertEqual(deserialized_commit, commit,
                      'Serialized and deserialized commits don\'t match')
Esempio n. 3
0
 def make_commit(self, filename: str):
     self.repo.add(filename)
     timestamp = int(datetime.now().timestamp())
     author = Signature('Rajat', '*****@*****.**', timestamp,
                        330)
     commit = self.repo.commit(message="First commit", author=author)
     return commit
Esempio n. 4
0
 def test_nothing_to_commit_exception_thrown_when_nothing_to_commit(self):
     timestamp = int(datetime.now().timestamp())
     with self.assertRaises(NothingToCommitException):
         self.repo.commit(message="First commit",
                          author=Signature('Rajat',
                                           '*****@*****.**',
                                           timestamp, 330))
Esempio n. 5
0
    def test_commit_deserialization(self):
        commit_id = '97d3f98f52b5779598424c552428d24c020703b5'
        expected_commit = Commit(
            commit_id, [Commit('9975c95be19b40f29f9ab6e9d70c48ab508c859d')],
            Signature('Rajat Khanduja', '*****@*****.**',
                      1496291306, 330),
            Signature('Rajat Khanduja', '*****@*****.**',
                      1496291306, 330),
            'Added tests, still having issues with timestamp in CommitObject.',
            Tree('cafee551bb869ad60cc6ddd82c07ebd6b32c51f5'))

        with open(os.path.join(TEST_FILES_DIR, "commit_" + commit_id),
                  'rb') as fp:
            commit = self.serializer.deserialize(commit_id,
                                                 zlib.decompress(fp.read()))
            self.assertEqual(commit, expected_commit,
                             "Deserialized commit doesn't match expectation")
Esempio n. 6
0
 def test_tag_serialization(self):
     tag = Tag(
         'some_id', 'testTag',
         Signature('Rajat Khanduja', '*****@*****.**',
                   1496564731, 330),
         '751796a3a414321be1805cee9cb8b32023fa6bf7', GitObjectType.COMMIT,
         'A trivial test tag')
     serialized_bytes = self.serializer.serialize(tag)
     tag_from_bytes = self.serializer.deserialize(tag.id, serialized_bytes)
     self.assertEqual(tag, tag_from_bytes)
Esempio n. 7
0
def get_signature(line, type):
    match = re.search(type + " (.+) <(.+)> (.+)", line)
    if match:
        name = match.group(1)
        email = match.group(2)
        timestamp_str = match.group(3)
        timestamp = int(timestamp_str.split()[0])
        tz = parse_timezone(str(timestamp_str.split()[1]))
        return Signature(name, email, timestamp, tz)
    else:
        raise ValueError("Input not formatted as expected")
Esempio n. 8
0
 def test_tag_deserialization(self):
     tag_id = 'some_id'
     serialized_bytes = b'tag 159\x00object 751796a3a414321be1805cee9cb8b32023fa6bf7\ntype commit\ntag ' \
                        b'testTag\ntagger Rajat Khanduja <*****@*****.**> 1496564731 +0530\n\nA trivial' \
                        b' test tag\n'
     expected_tag = Tag(
         tag_id, 'testTag',
         Signature('Rajat Khanduja', '*****@*****.**',
                   1496564731, 330),
         '751796a3a414321be1805cee9cb8b32023fa6bf7', GitObjectType.COMMIT,
         'A trivial test tag\n')
     self.assertEqual(self.serializer.deserialize(tag_id, serialized_bytes),
                      expected_tag)