-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathtests.py
95 lines (71 loc) · 2.5 KB
/
tests.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__authors__ = 'Bruno Adelé <bruno@adele.im>'
__copyright__ = 'Copyright (C) 2015 Bruno Adelé'
__description__ = """Unittest"""
__license__ = 'GPLv3'
import os
import sys
import shutil
from cStringIO import StringIO
import unittest
import git
from gitcheck import gitcheck
GITROOT = '/tmp/gitcheck-unittest'
def setUpModule():
# Get projects
get_github_projects("gitcheck", "https://github.com/badele/gitcheck.git")
get_github_projects("serialkiller", "https://github.com/badele/serialkiller.git")
get_github_projects("fabrecipes", "https://github.com/badele/fabrecipes.git")
def get_github_projects(projectname, projecturl):
# Preparing the git directory
gitdir = "%s/%s" % (GITROOT, projectname)
if os.path.exists(gitdir):
shutil.rmtree(gitdir)
os.makedirs(gitdir)
os.chdir(GITROOT)
# Get a git projects
print "Get git %s project" % projectname
git.Git().clone(projecturl)
class TestPackages(unittest.TestCase):
def setUp(self):
# Redirect stdout
self.output = StringIO()
self.saved_stdout = sys.stdout
sys.stdout = self.output
def tearDown(self):
# Reset stdout
self.output.close()
sys.stdout = self.saved_stdout
def test_searchRepositories(self):
os.chdir(GITROOT)
repos = gitcheck.searchRepositories()
self.assertEqual(repos[0], '%s/fabrecipes' % GITROOT)
self.assertEqual(repos[1], '%s/gitcheck' % GITROOT)
self.assertEqual(repos[2], '%s/serialkiller' % GITROOT)
def test_gitcheck(self):
os.chdir(GITROOT)
defaulttheme = ""
gitcheck.colortheme = {
'default': defaulttheme,
'prjchanged': defaulttheme,
'prjremote': defaulttheme,
'prjname': defaulttheme,
'reponame': defaulttheme,
'branchname': defaulttheme,
'fileupdated': defaulttheme,
'remoteto': defaulttheme,
'committo': defaulttheme,
'commitinfo': defaulttheme,
'commitstate': defaulttheme,
'bell': defaulttheme,
'reset': defaulttheme,
}
gitcheck.gitcheck()
output = sys.stdout.getvalue().strip()
lines = output.split('\n')
self.assertEqual(lines[0], 'fabrecipes/master ')
self.assertEqual(lines[1], 'gitcheck/master ')
self.assertEqual(lines[2], 'serialkiller/master')
if __name__ == "__main__":
unittest.main(verbosity=2)