1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2011-2012 Osmo Salomaa
5
# This file is part of Gaupol.
7
# Gaupol is free software: you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation, either version 3 of the License, or (at your option) any later
12
# Gaupol is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along with
17
# Gaupol. If not, see <http://www.gnu.org/licenses/>.
25
from gi.repository import Gtk
28
class TestAddBookmarkDialog(gaupol.TestCase):
30
def run__dialog(self):
34
def setup_method(self, method):
35
directory = os.path.abspath(os.path.dirname(__file__))
36
directory = os.path.abspath(os.path.join(directory, ".."))
37
sys.path.insert(0, directory)
38
try: mobj = __import__("bookmarks", {}, {}, [])
40
return traceback.print_exc()
41
finally: sys.path.pop(0)
42
self.application = self.new_application()
43
self.page = self.application.get_current_page()
44
self.page.view.select_rows((1,))
45
self.dialog = mobj.AddBookmarkDialog(Gtk.Window(), self.page)
48
def test_get_description(self):
49
self.dialog._description_entry.set_text("test")
50
text = self.dialog.get_description()
53
def test_get_row(self):
54
self.dialog._subtitle_spin.set_value(3)
55
row = self.dialog.get_row()
59
class TestBookmarksExtension(gaupol.TestCase):
61
@aeidon.deco.monkey_patch(gaupol.util, "run_dialog")
62
def bookmark_subtitles(self):
63
gaupol.util.run_dialog = lambda *args: Gtk.ResponseType.OK
64
action = self.application.get_action("add_bookmark")
66
self.page.view.select_rows((i,))
69
def import_side_pane(self):
70
directory = os.path.abspath(os.path.dirname(__file__))
71
directory = os.path.abspath(os.path.join(directory,
76
sys.path.insert(0, directory)
77
try: mobj = __import__("side-pane", {}, {}, [])
79
return traceback.print_exc()
80
finally: sys.path.pop(0)
83
def setup_method(self, method):
84
self.application = self.new_application()
85
mobj_sp = self.import_side_pane()
86
self.extension_sp = mobj_sp.SidePaneExtension()
87
self.extension_sp.setup(self.application)
88
directory = os.path.abspath(os.path.dirname(__file__))
89
directory = os.path.abspath(os.path.join(directory, ".."))
90
sys.path.insert(0, directory)
91
try: mobj = __import__("bookmarks", {}, {}, [])
93
return traceback.print_exc()
94
finally: sys.path.pop(0)
95
self.extension = mobj.BookmarksExtension()
96
self.extension.setup(self.application)
97
self.page = self.application.get_current_page()
98
self.bookmark_subtitles()
99
self.page.view.select_rows((1,))
101
def teardown_method(self, method):
102
self.extension.teardown(self.application)
103
self.extension_sp.teardown(self.application)
104
gaupol.TestCase.teardown_method(self, self.application)
106
@aeidon.deco.monkey_patch(gaupol.util, "run_dialog")
107
def test__on_add_bookmark_activate(self):
108
gaupol.util.run_dialog = lambda *args: Gtk.ResponseType.OK
109
action = self.application.get_action("add_bookmark")
112
def test__on_application_page_added(self):
113
self.application.open_main(self.new_subrip_file())
115
def test__on_application_page_closed(self):
116
self.application.close(self.page)
118
def test__on_application_page_switched(self):
119
self.application.open_main(self.new_subrip_file())
120
for page in self.application.pages:
121
self.application.set_current_page(page)
123
def test__on_edit_bookmarks_activate(self):
124
action = self.application.get_action("edit_bookmarks")
127
def test__on_next_bookmark_activate(self):
128
action = self.application.get_action("next_bookmark")
133
def test__on_project_main_file_saved(self):
134
self.application.save_main(self.page)
136
def test__on_project_subtitles_inserted(self):
137
self.page.project.insert_subtitles(list(range(7)))
139
def test__on_project_subtitles_removed(self):
140
self.bookmark_subtitles()
141
self.page.project.remove_subtitles(list(range(7)))
143
def test__on_previous_bookmark_activate(self):
144
action = self.application.get_action("previous_bookmark")
149
def test__on_search_entry_changed(self):
150
self.extension._search_entry.set_text("a")
151
self.extension._search_entry.set_text("x")
153
def test__on_tree_view_selection_changed(self):
154
selection = self.extension._tree_view.get_selection()
155
selection.select_path(1)
156
selection.select_path(2)
157
selection.select_path(3)
159
def test__read_bookmarks(self):
160
path = self.new_subrip_file()
161
path_bookmarks = path.replace(".srt", ".gaupol-bookmarks")
162
fobj = open(path_bookmarks, "a")
163
fobj.write("1 test\n")
164
fobj.write("2 test\n")
165
fobj.write("3 test\n")
167
self.application.open_main(path)
169
def test_setup(self):
170
page = self.application.side_pane.get_current_page()
171
assert page is self.extension._side_container
173
def test_teardown(self):
174
self.extension.teardown(self.application)
175
page = self.application.side_pane.get_current_page()
177
self.extension.setup(self.application)
179
def test_update(self):
180
self.extension.update(self.application, self.page)