forked from Nginlion/git-in-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_status.py
More file actions
79 lines (61 loc) · 2.3 KB
/
test_status.py
File metadata and controls
79 lines (61 loc) · 2.3 KB
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
'''
Created on Jul 4, 2014
@author: lzrak47
'''
import os
import shutil
import unittest
from command import Command
from repository import Repository
from utils import write_to_file
class TestStatus(unittest.TestCase):
def setUp(self):
self.workspace = 'test_status'
Command.cmd_init(self.workspace)
def tearDown(self):
os.chdir('..')
shutil.rmtree(self.workspace)
def test_status_init(self):
repo = Repository()
untracked_files = repo.get_untracked_files()
self.assertFalse(untracked_files)
Command.cmd_status()
def test_status_untracked_files(self):
path, content = ('1.txt', '1\n')
write_to_file(path, content)
repo = Repository()
untracked_files = repo.get_untracked_files()
self.assertEqual(untracked_files, ['1.txt'])
Command.cmd_status()
def test_status_unstaged_files(self):
file_list = [('1.txt', '1\n'), ('2.txt', '2\n')]
for path, content in file_list:
write_to_file(path, content)
Command.cmd_add(path)
write_to_file(file_list[0][0], '11\n')
os.remove(file_list[1][0])
repo = Repository()
unstaged_files = repo.get_unstaged_files()
self.assertEqual(unstaged_files['modified'], [file_list[0][0]])
self.assertEqual(unstaged_files['deleted'], [file_list[1][0]])
Command.cmd_status()
def test_status_uncommitted_files(self):
file_list = [('1.txt', '1\n'), ('2.txt', '2\n')]
for path, content in file_list:
write_to_file(path, content)
Command.cmd_add(path)
Command.cmd_commit('first ci')
write_to_file(file_list[0][0], '11\n')
Command.cmd_rm(file_list[1][0])
new_path = '3.txt'
new_content = '3\n'
write_to_file(new_path, new_content)
Command.cmd_add('.')
repo = Repository()
uncommitted_files = repo.get_uncommitted_files()
self.assertEqual(uncommitted_files['modified'], [file_list[0][0]])
self.assertEqual(uncommitted_files['deleted'], [file_list[1][0]])
self.assertEqual(uncommitted_files['new file'], [new_path])
Command.cmd_status()
if __name__ == "__main__":
unittest.main()