-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
test_graph_walk_reflog.py
90 lines (70 loc) · 3.22 KB
/
test_graph_walk_reflog.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
import sublime
from typing import Final
from mockito import unstub, when
from unittesting import DeferrableTestCase
from GitSavvy.core.git_command import GitCommand
from GitSavvy.tests.parameterized import parameterized as p
from GitSavvy.core.commands.log_graph import gs_log_graph_refresh
class _TestBase(DeferrableTestCase):
@classmethod
def setUpClass(cls):
s = sublime.load_settings("Preferences.sublime-settings")
s.set("close_windows_when_empty", False)
sublime.run_command("new_window")
cls.window: Final[sublime.Window]
cls.window = window = sublime.active_window()
cls.addClassCleanup(lambda: window.run_command('close_window'))
def tearDown(self):
unstub()
def await_string_in_view(self, view, needle):
yield lambda: view.find(needle, 0, sublime.LITERAL)
def await_active_panel_to_be(self, name):
yield lambda: self.window.active_panel() == name
def create_new_window(self):
sublime.run_command("new_window")
window = sublime.active_window()
self.addCleanup(lambda: window.run_command('close_window'))
return window
def create_new_view(self, window=None):
if window is None:
window = self.window
view = window.new_file()
self.addCleanup(self.close_view, view)
return view
def close_view(self, view):
view.set_scratch(True)
view.close()
class TestRebaseActions(_TestBase):
@p.expand([
("main", "", "main@{1}"),
("main", "main@{1}", "main@{2}"),
("main", "main@{1} main@{3}", "main@{1} main@{4}"),
("main", "main@{3} main@{1}", "main@{3} main@{2}"),
("main", "main@{3} main@{2}", "main@{3} main@{3}"),
("main", "main@{3} main@{3}", "main@{3} main@{4}"),
])
def test_add_previous_tip(self, branch_name, input, expected):
when(GitCommand).git("rev-parse", "--short", ...).thenReturn("deadbee")
when(gs_log_graph_refresh).run(...).thenReturn()
view = self.create_new_view()
view.settings().set("git_savvy.log_graph_view.apply_filters", True)
view.settings().set("git_savvy.log_graph_view.filters", input)
view.run_command("gs_log_graph_add_previous_tip", {"branch_name": branch_name})
actual = view.settings().get("git_savvy.log_graph_view.filters")
self.assertEqual(expected, actual)
@p.expand([
("main", "main@{2}", "main@{1}"),
("main", "main@{1}", ""),
("main", "main@{1} main@{3}", "main@{1} main@{2}"),
("main", "main@{1} main@{2}", "main@{1} main@{1}"),
("main", "main@{1} main@{1}", "main@{1}"),
])
def test_remove_previous_tip(self, branch_name, input, expected):
when(GitCommand).git("rev-parse", "--short", ...).thenReturn("deadbee")
when(gs_log_graph_refresh).run(...).thenReturn()
view = self.create_new_view()
view.settings().set("git_savvy.log_graph_view.apply_filters", True)
view.settings().set("git_savvy.log_graph_view.filters", input)
view.run_command("gs_log_graph_remove_previous_tip", {"branch_name": branch_name})
actual = view.settings().get("git_savvy.log_graph_view.filters")
self.assertEqual(expected, actual)