~ps-jenkins/unity-scope-texdoc/latestsnapshot-0.1daily13.05.31ubuntu.unity.next-0ubuntu1

« back to all changes in this revision

Viewing changes to tests/test_texdoc.py

  • Committer: Mark Tully
  • Date: 2013-02-25 23:56:38 UTC
  • Revision ID: markjtully@gmail.com-20130225235638-yls7e7n1g0d48d6e
Updated to new API
Converted to Python 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python3
1
2
# -*- coding: utf-8 -*-
2
 
 
3
 
from gi.repository import Dee
4
 
from unittest import TestCase, main
5
 
from src import unity_texdoc_daemon as scope
6
 
 
7
 
d = scope.Daemon()
8
 
searches = ['submarine']
9
 
mock_data = {'should_pass': 'file:tests/data/mock_texdoc_pass#',
10
 
             'should_fail': 'file:tests/data/mock_texdoc_fail#'}
11
 
 
12
 
class TestTexdoc(TestCase):
13
 
 
14
 
    def test_search(self):
15
 
        scope.SEARCH_URI = mock_data['should_pass']
16
 
        model = Dee.SequenceModel.new()
17
 
        model.set_schema('s', 's', 'u', 'u', 's', 's', 's', 's')
18
 
        model.set_column_names('uri', 'icon_hint', 'category', 'result_type',
19
 
                               'mimetype', 'title', 'comment', 'dnd_uri')
20
 
        scope.Daemon.update_results_model(d, searches[0], model)
21
 
        self.assertEqual(model[0][0],
22
 
                         '')
23
 
        self.assertEqual(model[0][1],
24
 
                         '')
25
 
        self.assertEqual(model[0][5],
26
 
                         '')
27
 
        self.assertEqual(model[0][6],
28
 
                         '')
29
 
 
30
 
    def test_failing_search(self):
31
 
        scope.SEARCH_URI = mock_data['should_fail']
32
 
        model = Dee.SequenceModel.new()
33
 
        model.set_schema('s', 's', 'u', 'u', 's', 's', 's', 's')
34
 
        model.set_column_names('uri', 'icon_hint', 'category', 'result_type',
35
 
                               'mimetype', 'title', 'comment', 'dnd_uri')
36
 
        scope.Daemon.update_results_model(d, searches[0], model)
37
 
        self.assertEqual(len(model), 0)
 
3
from gi.repository import Unity
 
4
from unittest import TestCase
 
5
import imp
 
6
 
 
7
 
 
8
class ResultSet(Unity.ResultSet):
 
9
    def __init__(self):
 
10
        Unity.ResultSet.__init__(self)
 
11
        self.results = []
 
12
 
 
13
    def do_add_result(self, result):
 
14
        self.results.append({'uri':result.uri,
 
15
                             'title':result.title,
 
16
                             'comment':result.comment,
 
17
                             'icon':result.icon_hint})
 
18
 
 
19
class ScopeTestCase(TestCase):
 
20
    def init_scope(self, scope_path):
 
21
        self.scope_module = imp.load_source('scope', scope_path)
 
22
        self.scope = self.scope_module.load_scope()
 
23
 
 
24
    def perform_query(self, query, filter_set = Unity.FilterSet.new()):
 
25
        result_set = ResultSet()
 
26
        ctx = Unity.SearchContext.create(query, 0, filter_set,
 
27
                                         None, result_set, None)
 
28
        s = self.scope.create_search_for_query(ctx)
 
29
        s.run()
 
30
        return result_set
 
31
 
 
32
 
 
33
class TestAskUbuntu(ScopeTestCase):
 
34
    def setUp(self):
 
35
        self.init_scope('src/unity_texdoc_daemon.py')
 
36
 
 
37
    def tearDown(self):
 
38
        self.scope = None
 
39
        self.scope_module = None
 
40
 
 
41
    def test_questions_search(self):
 
42
        expected_results = ["file:///usr/share/texlive/texmf-dist/doc/texdoc/texdoc.pdf",
 
43
                            "texdoc.pdf"]
 
44
        results = []
 
45
        for s in ['texdoc']:
 
46
            result_set = self.perform_query(s)
 
47
            results.append(result_set.results[0]['uri'])
 
48
            results.append(result_set.results[0]['title'])
 
49
        self.assertEqual(results, expected_results)
 
50
 
 
51
 
 
52
    def test_questions_failing_search(self):        
 
53
        for s in ['upnriitnyt']:
 
54
            result_set = self.perform_query(s)
 
55
            self.assertEqual(len(result_set.results), 0)
38
56
 
39
57
if __name__ == '__main__':
40
 
    main()
 
58
    unittest.main()