/
tests.py
36 lines (27 loc) · 1.15 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
from unittest import TestCase
from tempfile import gettempdir
import git
from random import randint
randstring = lambda x=5: ''.join([chr(randint(ord('a'), ord('z'))) for y in range(x)])
from git_branchdescriptions import BranchDescriptions, _santitize_branch_name
class TestBranchDescriptions(TestCase):
def setUp(self):
self.git_dir = gettempdir()
self.repo = git.Repo()
self.repo.create(self.git_dir)
def test_basic_setting_and_retrieval(self):
bd = BranchDescriptions(self.git_dir)
desc = randstring()
bd.set('foobar', desc)
self.assertEqual(desc, bd.get('foobar'))
def test_setting_persistence(self):
bd = BranchDescriptions(self.git_dir)
desc = randstring()
bd.set('foobar', desc)
bd = BranchDescriptions(self.git_dir)
self.assertEqual(desc, bd.get('foobar'))
class TestUtilityFunctions(TestCase):
def test_santitize_branch_name(self):
self.assertEqual('ref---', _santitize_branch_name('ref_'))
self.assertEqual('ref---', _santitize_branch_name('ref/'))
self.assertEqual('ref', _santitize_branch_name('* \x1b[32mref\x1b[m'))