-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.py
45 lines (35 loc) · 1.37 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unittest
import os
from gitinfo import get_git_info
class TestMethods(unittest.TestCase):
def test_has_git(self):
ret = get_git_info()
self.assertTrue("commit" in ret)
self.assertTrue("message" in ret)
def test_message_not_empty(self):
ret = get_git_info()
self.assertTrue(len(ret["message"]) > 0 )
def test_has_gitdir(self):
ret = get_git_info()
self.assertTrue("gitdir" in ret)
self.assertTrue(os.path.dirname(ret["gitdir"]) == os.getcwd())
def test_doesnot_have_git(self):
# The parent directory should *not* have a git file
ret = get_git_info(os.path.dirname(os.getcwd()))
self.assertEqual(ret, None)
def test_should_work_with_relative_paths(self):
# The parent directory should *not* have a git file
# Should work with ..
ret = get_git_info("..")
self.assertEqual(ret, None)
def test_should_not_crash_with_emtpy_git_dir(self):
# Create a dir named named empty_git and run git init there to test this
if os.path.isdir("empty_git"):
ret = get_git_info("empty_git")
self.assertEqual(ret, None)
def test_packed(self):
ret = get_git_info('../../c/git')
self.assertTrue("commit" in ret)
self.assertTrue("message" in ret)
if __name__ == "__main__":
unittest.main()