~ubuntu-branches/ubuntu/saucy/gaupol/saucy-proposed

« back to all changes in this revision

Viewing changes to data/extensions/bookmarks/test/test_bookmarks.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-01-06 17:10:10 UTC
  • mfrom: (1.2.8)
  • mto: (10.2.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20130106171010-kmlq0sy324jlp9zz
Tags: upstream-0.21
Import upstream version 0.21

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (C) 2011-2012 Osmo Salomaa
 
4
#
 
5
# This file is part of Gaupol.
 
6
#
 
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
 
10
# version.
 
11
#
 
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.
 
15
#
 
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/>.
 
18
 
 
19
import aeidon
 
20
import gaupol
 
21
import os
 
22
import sys
 
23
import traceback
 
24
 
 
25
from gi.repository import Gtk
 
26
 
 
27
 
 
28
class TestAddBookmarkDialog(gaupol.TestCase):
 
29
 
 
30
    def run__dialog(self):
 
31
        self.dialog.run()
 
32
        self.dialog.destroy()
 
33
 
 
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", {}, {}, [])
 
39
        except ImportError:
 
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)
 
46
        self.dialog.show()
 
47
 
 
48
    def test_get_description(self):
 
49
        self.dialog._description_entry.set_text("test")
 
50
        text = self.dialog.get_description()
 
51
        assert text == "test"
 
52
 
 
53
    def test_get_row(self):
 
54
        self.dialog._subtitle_spin.set_value(3)
 
55
        row = self.dialog.get_row()
 
56
        assert row == 2
 
57
 
 
58
 
 
59
class TestBookmarksExtension(gaupol.TestCase):
 
60
 
 
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")
 
65
        for i in range(5):
 
66
            self.page.view.select_rows((i,))
 
67
            action.activate()
 
68
 
 
69
    def import_side_pane(self):
 
70
        directory = os.path.abspath(os.path.dirname(__file__))
 
71
        directory = os.path.abspath(os.path.join(directory,
 
72
                                                 "..",
 
73
                                                 "..",
 
74
                                                 "side-pane"))
 
75
 
 
76
        sys.path.insert(0, directory)
 
77
        try: mobj = __import__("side-pane", {}, {}, [])
 
78
        except ImportError:
 
79
            return traceback.print_exc()
 
80
        finally: sys.path.pop(0)
 
81
        return(mobj)
 
82
 
 
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", {}, {}, [])
 
92
        except ImportError:
 
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,))
 
100
 
 
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)
 
105
 
 
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")
 
110
        action.activate()
 
111
 
 
112
    def test__on_application_page_added(self):
 
113
        self.application.open_main(self.new_subrip_file())
 
114
 
 
115
    def test__on_application_page_closed(self):
 
116
        self.application.close(self.page)
 
117
 
 
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)
 
122
 
 
123
    def test__on_edit_bookmarks_activate(self):
 
124
        action = self.application.get_action("edit_bookmarks")
 
125
        action.activate()
 
126
 
 
127
    def test__on_next_bookmark_activate(self):
 
128
        action = self.application.get_action("next_bookmark")
 
129
        action.activate()
 
130
        action.activate()
 
131
        action.activate()
 
132
 
 
133
    def test__on_project_main_file_saved(self):
 
134
        self.application.save_main(self.page)
 
135
 
 
136
    def test__on_project_subtitles_inserted(self):
 
137
        self.page.project.insert_subtitles(list(range(7)))
 
138
 
 
139
    def test__on_project_subtitles_removed(self):
 
140
        self.bookmark_subtitles()
 
141
        self.page.project.remove_subtitles(list(range(7)))
 
142
 
 
143
    def test__on_previous_bookmark_activate(self):
 
144
        action = self.application.get_action("previous_bookmark")
 
145
        action.activate()
 
146
        action.activate()
 
147
        action.activate()
 
148
 
 
149
    def test__on_search_entry_changed(self):
 
150
        self.extension._search_entry.set_text("a")
 
151
        self.extension._search_entry.set_text("x")
 
152
 
 
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)
 
158
 
 
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")
 
166
        fobj.close()
 
167
        self.application.open_main(path)
 
168
 
 
169
    def test_setup(self):
 
170
        page = self.application.side_pane.get_current_page()
 
171
        assert page is self.extension._side_container
 
172
 
 
173
    def test_teardown(self):
 
174
        self.extension.teardown(self.application)
 
175
        page = self.application.side_pane.get_current_page()
 
176
        assert page is None
 
177
        self.extension.setup(self.application)
 
178
 
 
179
    def test_update(self):
 
180
        self.extension.update(self.application, self.page)