1
2
# -*- coding: utf-8 -*-
3
from gi.repository import Dee
4
from unittest import TestCase, main
5
from src import unity_texdoc_daemon as scope
8
searches = ['submarine']
9
mock_data = {'should_pass': 'file:tests/data/mock_texdoc_pass#',
10
'should_fail': 'file:tests/data/mock_texdoc_fail#'}
12
class TestTexdoc(TestCase):
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],
23
self.assertEqual(model[0][1],
25
self.assertEqual(model[0][5],
27
self.assertEqual(model[0][6],
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
8
class ResultSet(Unity.ResultSet):
10
Unity.ResultSet.__init__(self)
13
def do_add_result(self, result):
14
self.results.append({'uri':result.uri,
16
'comment':result.comment,
17
'icon':result.icon_hint})
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()
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)
33
class TestAskUbuntu(ScopeTestCase):
35
self.init_scope('src/unity_texdoc_daemon.py')
39
self.scope_module = None
41
def test_questions_search(self):
42
expected_results = ["file:///usr/share/texlive/texmf-dist/doc/texdoc/texdoc.pdf",
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)
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)
39
57
if __name__ == '__main__':