-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
test_commit_view.py
101 lines (82 loc) · 2.6 KB
/
test_commit_view.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
96
97
98
99
100
101
import os
from textwrap import dedent
import sublime
from unittesting import DeferrableTestCase
from GitSavvy.tests.mockito import unstub, when
from GitSavvy.tests.parameterized import parameterized as p
from GitSavvy.core.commands.commit import extract_commit_message, gs_prepare_commit_refresh_diff
examples = [
(
dedent("""\
""".rstrip()),
""
),
(
dedent("""\
## To make a commit, ...
""".rstrip()),
""
),
(
dedent("""\
The subject
## To make a commit, ...
""".rstrip()),
"The subject"
),
(
dedent("""\
The subject
b
c
d
## To make a commit, ...
""".rstrip()),
dedent("""\
The subject
b
c
d
""".rstrip())
),
]
class TestExtractCommitMessage(DeferrableTestCase):
@classmethod
def setUpClass(cls):
sublime.run_command("new_window")
cls.window = sublime.active_window()
s = sublime.load_settings("Preferences.sublime-settings")
s.set("close_windows_when_empty", False)
@classmethod
def tearDownClass(self):
self.window.run_command('close_window')
def tearDown(self):
unstub()
@p.expand(examples)
def test_a(self, VIEW_CONTENT, output):
view = self.window.new_file()
self.addCleanup(view.close)
view.set_syntax_file("Packages/GitSavvy/syntax/make_commit.sublime-syntax")
view.run_command('append', {'characters': VIEW_CONTENT})
view.set_scratch(True)
self.assertEqual(output, extract_commit_message(view).strip())
def test_basic_default_commit_view(self):
view = self.window.new_file()
self.addCleanup(view.close)
exists = os.path.exists
when(os.path).exists(...).thenAnswer(exists)
when(os.path).exists("/foo").thenReturn(True)
when(gs_prepare_commit_refresh_diff).git("diff", ...).thenReturn(dedent("""\
diff --git a/bar/test.txt b/bar/test.txt
index 9303f2c..5a9ce64 100644
--- a/bar/test.txt
+++ b/bar/test.txt
@@ -1,14 +1,22 @@
This is a diff
""".rstrip()).encode())
self.window.run_command("gs_commit", {"repo_path": "/foo"})
yield self.window.active_view().name() == "COMMIT: foo"
commit_view = self.window.active_view()
self.assertTrue(commit_view.find_by_selector("meta.dropped.git.commit"))
self.assertTrue(commit_view.find_by_selector("git-savvy.diff"))
self.assertEquals("", extract_commit_message(commit_view).rstrip())