~mvo/software-center/trivial-renaming

« back to all changes in this revision

Viewing changes to tests/gtk3/test_installedpane.py

  • Committer: Natalia B. Bidart
  • Date: 2012-05-30 18:39:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3030.
  • Revision ID: natalia.bidart@canonical.com-20120530183955-zbnjczayktmmg5tv
- Initial test cleanup:
  - Renamed test/ dir to tests/.
  - Isolated test code into tests/ directory, including moving all the
    get_test_window_foo from the gtk3 production modules to
    tests/gtk3/windows.py module.
  - Removed all the calls to Gtk.main() in gtk3 tests since that blocks the
    execution of the suite.
  - Pep8 and pyflakes fixes in the files already modified in this branch.
  - Minor bug fix in the softwarecenter/log.py module when trying to create a
    log dir with proper perms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
from gi.repository import Gtk, GObject
4
 
import time
5
1
import unittest
6
2
 
7
 
from testutils import setup_test_env
 
3
from tests.utils import (
 
4
    do_events_with_sleep,
 
5
    setup_test_env,
 
6
)
8
7
setup_test_env()
9
8
 
10
 
TIMEOUT=300
 
9
from tests.gtk3.windows import get_test_window_installedpane
 
10
 
11
11
 
12
12
class TestInstalledPane(unittest.TestCase):
13
13
 
14
14
    def test_installedpane(self):
15
 
        from softwarecenter.ui.gtk3.panes.installedpane import get_test_window
16
 
        win = get_test_window()
 
15
        win = get_test_window_installedpane()
 
16
        self.addCleanup(win.destroy)
17
17
        installedpane = win.get_data("pane")
18
 
        self._p()
 
18
        do_events_with_sleep()
19
19
        # safe initial show/hide label for later
20
20
        initial_actionbar_label = installedpane.action_bar._label_text
21
21
        # do simple search
22
22
        installedpane.on_search_terms_changed(None, "foo")
23
 
        self._p()
 
23
        do_events_with_sleep()
24
24
        model = installedpane.app_view.tree_view.get_model()
25
25
        # FIXME: len(model) *only* counts the size of the top level
26
 
        #        (category) hits. thats still ok, as non-apps will 
 
26
        #        (category) hits. thats still ok, as non-apps will
27
27
        #        add the "system" category
28
28
        len_only_apps = len(model)
29
29
        # set to show nonapps
30
30
        installedpane._show_nonapp_pkgs()
31
 
        self._p()
 
31
        do_events_with_sleep()
32
32
        len_with_nonapps = len(model)
33
33
        self.assertTrue(len_with_nonapps > len_only_apps)
34
34
        # set to hide nonapps again and ensure the size matches the
35
35
        # previous one
36
36
        installedpane._hide_nonapp_pkgs()
37
 
        self._p()
 
37
        do_events_with_sleep()
38
38
        self.assertEqual(len(model), len_only_apps)
39
39
        # clear sarch and ensure we get a expanded size again
40
40
        installedpane.on_search_terms_changed(None, "")
41
 
        self._p()
 
41
        do_events_with_sleep()
42
42
        all_apps = len(model)
43
43
        self.assertTrue(all_apps > len_only_apps)
44
44
        # ensure we have the same show/hide info as initially
45
45
        self.assertEqual(initial_actionbar_label,
46
46
                         installedpane.action_bar._label_text)
47
 
        GObject.timeout_add(TIMEOUT, lambda: win.destroy())
48
 
        Gtk.main()
49
 
 
50
 
    def _p(self):
51
 
        for i in range(10):
52
 
            time.sleep(0.1)
53
 
            while Gtk.events_pending():
54
 
                Gtk.main_iteration()
55
47
 
56
48
 
57
49
if __name__ == "__main__":
58
 
    import logging
59
 
    logging.basicConfig(level=logging.INFO)
60
50
    unittest.main()