645
|
1 |
#============================================================================
|
|
2 |
#Name : test_sphinx_ext.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
|
19 |
|
|
20 |
""" Test sphinx_ext module. """
|
|
21 |
import re
|
|
22 |
|
|
23 |
import logging
|
|
24 |
import os
|
|
25 |
import time
|
|
26 |
import unittest
|
|
27 |
import sys
|
|
28 |
import mocker
|
|
29 |
import sphinx_ext
|
|
30 |
|
|
31 |
_logger = logging.getLogger('test.sphinx_ext')
|
|
32 |
random_number = 10
|
|
33 |
|
|
34 |
class SphinxTest(mocker.MockerTestCase):
|
|
35 |
""" Class for testing sphinx_ext module """
|
|
36 |
def __init__(self, methodName="runTest"):
|
|
37 |
mocker.MockerTestCase.__init__(self, methodName)
|
|
38 |
|
|
39 |
def setUp(self):
|
|
40 |
# some dummy input
|
|
41 |
self.inlineDocument = r'<document source="C:\helium-working\helium\build\temp\doc\api\helium\macros_list.rst"><section ids="macros-list" names="macros\ list"><title>Macros list</title></section></document>'
|
|
42 |
sphinx_ext.exit_with_failure = 0
|
|
43 |
sphinx_ext.database_path = os.path.join(os.environ['TEST_DATA'], "data", "test_database.xml")
|
|
44 |
|
|
45 |
def test_handle_hlm_role_callback(self):
|
|
46 |
""" Check roles and description unit."""
|
|
47 |
obj = _MockApp()
|
|
48 |
sphinx_ext.setup(obj)
|
|
49 |
assert 'hlm-t' in obj.dict.keys()
|
|
50 |
assert 'hlm-p' in obj.dict.keys()
|
|
51 |
assert 'hlm-m' in obj.dict.keys()
|
|
52 |
assert sphinx_ext.handle_hlm_role == obj.dict['hlm-t']
|
|
53 |
assert sphinx_ext.handle_hlm_role == obj.dict['hlm-p']
|
|
54 |
assert sphinx_ext.handle_hlm_role == obj.dict['hlm-m']
|
|
55 |
assert ['property', 'ant-prop', 'pair: %s; property'] in obj.descUnit
|
|
56 |
assert ['target', 'ant-target', 'pair: %s; target'] in obj.descUnit
|
|
57 |
|
|
58 |
def test_handle_hlm_role_target(self):
|
|
59 |
""" Check target to build the link """
|
|
60 |
obj = self.mocker.mock(count=False)
|
|
61 |
mocker.expect(obj.document).result(self.inlineDocument)
|
|
62 |
self.mocker.replay()
|
|
63 |
response = sphinx_ext.handle_hlm_role('hlm-t' , "", 'cmaker-install', random_number, obj)
|
|
64 |
assert "../../api/helium/project-compile.cmaker.html#cmaker-install" in response[0][0].children[0].attributes['refuri']
|
|
65 |
|
|
66 |
def test_handle_hlm_role_property(self):
|
|
67 |
""" Check property to build the link """
|
|
68 |
obj = self.mocker.mock(count=False)
|
|
69 |
mocker.expect(obj.document).result(self.inlineDocument)
|
|
70 |
self.mocker.replay()
|
|
71 |
response = sphinx_ext.handle_hlm_role('hlm-p' , "", 'cmaker-export', random_number, obj)
|
|
72 |
assert "../../api/helium/project-compile.cmaker.html#cmaker-export" in response[0][0].children[0].attributes['refuri']
|
|
73 |
|
|
74 |
|
|
75 |
def test_handle_hlm_role_macro(self):
|
|
76 |
""" Check macro to build the link """
|
|
77 |
obj = self.mocker.mock(count=False)
|
|
78 |
mocker.expect(obj.document).result(self.inlineDocument)
|
|
79 |
self.mocker.replay()
|
|
80 |
response = sphinx_ext.handle_hlm_role('hlm-m' , "", 'cmaker-export', random_number, obj)
|
|
81 |
assert "../../api/helium/project-compile.cmaker.html#cmaker-export" in response[0][0].children[0].attributes['refuri']
|
|
82 |
|
|
83 |
def test_handle_hlm_role_missing_api(self):
|
|
84 |
""" Check for failure when there are missing api's """
|
|
85 |
error = ""
|
|
86 |
line = ""
|
|
87 |
obj = self.mocker.mock(count=False)
|
|
88 |
mocker.expect(obj.document).result(self.inlineDocument)
|
|
89 |
mocker.expect(obj.reporter.error('Missing API doc for "cmaker-clean".', line=random_number)).result('Missing API doc for "cmaker-clean".')
|
|
90 |
self.mocker.replay()
|
|
91 |
sphinx_ext.handle_hlm_role('hlm-t' , "", 'cmaker-clean', random_number, obj)
|
|
92 |
|
|
93 |
def test_handle_hlm_role_missing_field_value(self):
|
|
94 |
""" Check for failure when there are missing fields for api's """
|
|
95 |
error = ""
|
|
96 |
line = ""
|
|
97 |
obj = self.mocker.mock(count=False)
|
|
98 |
mocker.expect(obj.document).result(self.inlineDocument)
|
|
99 |
mocker.expect(obj.reporter.error('Field value cannot be found for API field: "cmaker-export[summary]".', line=random_number)).result('Field value cannot be found for API field: "cmaker-export[summary]".')
|
|
100 |
self.mocker.replay()
|
|
101 |
sphinx_ext.handle_hlm_role('hlm-t' , "", 'cmaker-export[summary]', random_number, obj)
|
|
102 |
|
|
103 |
def test_handle_hlm_role_valid_field_value(self):
|
|
104 |
""" Check when there is '[' present """
|
|
105 |
obj = self.mocker.mock(count=False)
|
|
106 |
mocker.expect(obj.document).result(self.inlineDocument)
|
|
107 |
self.mocker.replay()
|
|
108 |
response = sphinx_ext.handle_hlm_role('hlm-t' , "", 'cmaker-export[location]', random_number, obj)
|
|
109 |
assert r"C:\Helium_svn\helium\tools\compile\cmaker.ant.xml:87:" in response[0][0].data
|
|
110 |
|
|
111 |
class _MockApp:
|
|
112 |
|
|
113 |
def __init__(self):
|
|
114 |
self.dict = {}
|
|
115 |
self.descUnit = []
|
|
116 |
|
|
117 |
def add_role(self, role, ref):
|
|
118 |
self.dict[role] = ref
|
|
119 |
|
|
120 |
def add_description_unit(self, text1, text2, text3):
|
|
121 |
self.descUnit.append([text1, text2, text3]) |