Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

# Copyright (C) 2015 Chintalagiri Shashank 

# 

# This file is part of Tendril. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU Affero General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 

# GNU Affero General Public License for more details. 

# 

# You should have received a copy of the GNU Affero General Public License 

# along with this program.  If not, see <http://www.gnu.org/licenses/>. 

""" 

Testing Dox Module (:mod:`tendril.dox.testing`) 

=============================================== 

 

This module provides functions to generate testing documents. 

 

The functions here use the :mod:`tendril.dox.render` module to actually 

produce the output files after constructing the appropriate stage. 

 

.. seealso:: :mod:`tendril.testing.analysis`, which does much of 

             the heavy lifting 

 

.. rubric:: Document Generators 

 

.. autosummary:: 

 

    render_test_report 

    render_device_summary 

 

""" 

 

import os 

 

from tendril.testing import analysis 

from tendril.utils.db import with_db 

from tendril.entityhub import serialnos 

from tendril.entityhub import projects 

from tendril.gedaif.conffile import ConfigsFile 

from tendril.utils import vcs 

from tendril.entityhub.db.model import SerialNumber 

from tendril.entityhub.db import controller as sno_controller 

 

from render import render_pdf 

import docstore 

 

from tendril.utils.config import INSTANCE_ROOT 

from tendril.utils import log 

 

logger = log.get_logger(__name__, log.DEFAULT) 

default_target = os.path.join(INSTANCE_ROOT, 'scratch', 'testing') 

 

 

@with_db 

def render_test_report(serialno=None, outfolder=None, session=None): 

    """ 

    Renders the latest test results marked against the specified ``serialno``. 

 

    Since this function is defined against the database, all arguments should 

    be keyword arguments. 

 

    :param serialno: The serial number of the device. 

    :type serialno: :class:`str` or :class:`tendril.entityhub.db.SerialNumber` 

    :param outfolder: The folder in which the output file should be created. 

    :type outfolder: str 

    :param session: The database session. If None, the function will make 

                    it's own. 

    :return: The output file path. 

 

    .. rubric:: Template Used 

 

    ``tendril/dox/templates/testing/test_report_template.tex`` 

    (:download:`Included version 

    <../../tendril/dox/templates/testing/test_report_template.tex>`) 

 

    .. rubric:: Stage Keys Provided 

    .. list-table:: 

 

        * - ``sno`` 

          - Serial number of the device. 

        * - ``testdate`` 

          - The timestamp of the latest test suite. 

        * - ``devicetype`` 

          - The device type. 

        * - ``desc`` 

          - The device description. 

        * - ``svnrevision`` 

          - The VCS revision of the project config file. 

        * - ``svnrepo`` 

          - The VCS repository containing the project 

        * - ``graphs`` 

          - A list of graphs, each graph being a list of tuples of 

            (graphpath, graphtitle) 

        * - ``instruments`` 

          - A list of instrument ident strings, one for each unique 

            instrument used in the suites. 

        * - ``suites`` 

          - A list of instances of 

            :class:`tendril.testing.testbase.TestSuiteBase` or its subclasses. 

 

    Note that the ``suites`` provided to the template are typically 

    expected to be offline test suites which are reconstructed from the 

    database. 

 

    .. seealso:: :func:`tendril.testing.analysis.get_test_suite_objects` 

 

    """ 

    if serialno is None: 

        raise ValueError("serialno cannot be None") 

    if not isinstance(serialno, SerialNumber): 

        serialno = sno_controller.get_serialno_object(sno=serialno, 

                                                      session=session) 

    if outfolder is None: 

        outfolder = os.path.join(INSTANCE_ROOT, 'scratch', 'testing') 

 

    template = os.path.join('testing', 'test_report_template.tex') 

    outpath = os.path.join(outfolder, 

                           'TEST-REPORT-' + serialno.sno + '.pdf') 

 

    devicetype = serialnos.get_serialno_efield(sno=serialno.sno, 

                                               session=session) 

    projectfolder = projects.cards[devicetype] 

    gcf = ConfigsFile(projectfolder) 

 

    suites = analysis.get_test_suite_objects(serialno=serialno.sno, 

                                             session=session) 

    graphs = [] 

    instruments = {} 

    for suite in suites: 

        for test in suite._tests: 

            graphs.extend(test.graphs) 

            graphs.extend(test.histograms) 

            if test._inststr is not None and \ 

                    test._inststr not in instruments.keys(): 

                instruments[test._inststr] = len(instruments.keys()) + 1 

 

    stage = {'suites': [x.render_dox() for x in suites], 

             'sno': serialno.sno, 

             'testdate': max([x.ts for x in suites]).format(), 

             'devicetype': devicetype, 

             'desc': gcf.description(devicetype), 

             'svnrevision': vcs.get_path_revision(projectfolder), 

             'svnrepo': vcs.get_path_repository(projectfolder), 

             'graphs': graphs, 

             'instruments': instruments 

             } 

 

    return render_pdf(stage, template, outpath) 

 

 

def render_device_summary(devicetype, include_failed=False, outfolder=None): 

    """ 

    Renders a summary of all of the latest test results marked against the 

    serial numbers of the specified ``devicetype``. 

 

    :param devicetype: The type of device for which a summary is desired. 

    :type devicetype: str 

    :param outfolder: The folder in which the output file should be created. 

    :type outfolder: str 

    :param include_failed: Whether failed test results should be included in 

                      the graphs and the statistical analysis. Default False. 

    :type include_failed: bool 

    :return: The output file path. 

 

    .. rubric:: Template Used 

 

    ``tendril/dox/templates/testing/test_device_summary_template.tex`` 

    (:download:`Included version 

    <../../tendril/dox/templates/testing/test_device_summary_template.tex>`) 

 

    .. rubric:: Stage Keys Provided 

    .. list-table:: 

 

        * - ``devicetype`` 

          - The device type. 

        * - ``desc`` 

          - The device description. 

        * - ``svnrevision`` 

          - The VCS revision of the project config file. 

        * - ``svnrepo`` 

          - The VCS repository containing the project 

        * - ``graphs`` 

          - A list of graphs, each graph being a list of tuples of 

            (graphpath, graphtitle) 

        * - ``collector`` 

          - An instance of :class:`tendril.testing.analysis.ResultCollector`, 

            containing the collated test results. 

 

    .. seealso:: :func:`tendril.testing.analysis.get_device_test_summary` 

 

    """ 

    if outfolder is None: 

        outfolder = os.path.join(INSTANCE_ROOT, 'scratch', 'testing') 

    template = os.path.join('testing', 'test_device_summary_template.tex') 

    outpath = os.path.join(outfolder, 

                           'TEST-DEVICE-SUMMARY-' + devicetype + '.pdf') 

 

    projectfolder = projects.cards[devicetype] 

    gcf = ConfigsFile(projectfolder) 

 

    summary = analysis.get_device_test_summary(devicetype=devicetype, 

                                               include_failed=include_failed) 

    graphs = summary.graphs 

 

    stage = {'devicetype': devicetype, 

             'desc': gcf.description(devicetype), 

             'svnrevision': vcs.get_path_revision(projectfolder), 

             'svnrepo': vcs.get_path_repository(projectfolder), 

             'graphs': graphs, 

             'collector': summary 

             } 

 

    return render_pdf(stage, template, outpath) 

 

 

def get_all_test_reports(limit=None): 

    return docstore.get_docs_list_for_sno_doctype(serialno=None, 

                                                  doctype='TEST-RESULT', 

                                                  limit=limit) 

 

 

def get_latest_test_report(serialno=None): 

    return docstore.get_docs_list_for_sno_doctype(serialno=serialno, 

                                                  doctype='TEST-RESULT', 

                                                  limit=1)