Bläddra i källkod

Add unit tests for describe

Sylvia van Os 6 år sedan
förälder
incheckning
06caf85733
1 ändrade filer med 56 tillägg och 0 borttagningar
  1. 56 0
      dulwich/tests/test_porcelain.py

+ 56 - 0
dulwich/tests/test_porcelain.py

@@ -1375,3 +1375,59 @@ class FsckTests(PorcelainTestCase):
         self.assertEqual(
                 [(obj.id, 'invalid name .git')],
                 [(sha, str(e)) for (sha, e) in porcelain.fsck(self.repo)])
+
+
+class DescribeTests(PorcelainTestCase):
+
+    def test_no_commits(self):
+        self.assertRaises(KeyError, porcelain.describe, self.repo.path)
+
+    def test_single_commit(self):
+        fullpath = os.path.join(self.repo.path, 'foo')
+        with open(fullpath, 'w') as f:
+            f.write("BAR")
+        porcelain.add(repo=self.repo.path, paths=[fullpath])
+        sha = porcelain.commit(
+                self.repo.path, message=b"Some message",
+                author=b"Joe <joe@example.com>",
+                committer=b"Bob <bob@example.com>")
+        self.assertEqual(
+                'g{}'.format(str(sha)[:7]),
+                porcelain.describe(self.repo.path))
+
+    def test_tag(self):
+        fullpath = os.path.join(self.repo.path, 'foo')
+        with open(fullpath, 'w') as f:
+            f.write("BAR")
+        porcelain.add(repo=self.repo.path, paths=[fullpath])
+        porcelain.commit(
+                self.repo.path, message=b"Some message",
+                author=b"Joe <joe@example.com>",
+                committer=b"Bob <bob@example.com>")
+        porcelain.tag_create(self.repo.path, b"tryme", b'foo <foo@bar.com>',
+                             b'bar', annotated=True)
+        self.assertEqual(
+                "tryme",
+                porcelain.describe(self.repo.path))
+
+    def test_tag_and_commit(self):
+        fullpath = os.path.join(self.repo.path, 'foo')
+        with open(fullpath, 'w') as f:
+            f.write("BAR")
+        porcelain.add(repo=self.repo.path, paths=[fullpath])
+        porcelain.commit(
+                self.repo.path, message=b"Some message",
+                author=b"Joe <joe@example.com>",
+                committer=b"Bob <bob@example.com>")
+        porcelain.tag_create(self.repo.path, b"tryme", b'foo <foo@bar.com>',
+                             b'bar', annotated=True)
+        with open(fullpath, 'w') as f:
+            f.write("BAR2")
+        porcelain.add(repo=self.repo.path, paths=[fullpath])
+        sha = porcelain.commit(
+                self.repo.path, message=b"Some message",
+                author=b"Joe <joe@example.com>",
+                committer=b"Bob <bob@example.com>")
+        self.assertEqual(
+                'tryme-1-g{}'.format(str(sha)[:7]),
+                porcelain.describe(self.repo.path))