File: test_formatters.py

package info (click to toggle)
flent 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,156 kB
  • sloc: python: 11,662; ansic: 626; sh: 257; makefile: 225; javascript: 72; xml: 58
file content (89 lines) | stat: -rw-r--r-- 2,975 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
#
# test_formatters.py
#
# Author:   Toke Høiland-Jørgensen (toke@toke.dk)
# Date:      9 July 2019
# Copyright (c) 2019, Toke Høiland-Jørgensen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import absolute_import, division, print_function, unicode_literals

import os
import shutil
import tempfile
import unittest
import traceback

from unittest.util import strclass

from .test_helpers import get_test_data_files

from flent import resultset, formatters, combiners
from flent.settings import parser, Settings, DEFAULT_SETTINGS
settings = parser.parse_args(args=[], namespace=Settings(DEFAULT_SETTINGS))

TEST_FORMATTERS = ['table', 'org_table', 'csv', 'summary', 'metadata']
if combiners.HAS_NUMPY:
    TEST_FORMATTERS.append('stats')


class TestFormatters(unittest.TestCase):

    def __init__(self, filename):
        self.filename = filename
        unittest.TestCase.__init__(self)

    def setUp(self):
        self.output_dir = tempfile.mkdtemp()
        self.settings = settings.copy()

    def tearDown(self):
        shutil.rmtree(self.output_dir)

    def __str__(self):
        return "format %s (%s)" % (os.path.basename(self.filename),
                                   strclass(self.__class__))

    def runTest(self):
        r = resultset.load(self.filename)
        self.settings.update(r.meta())
        self.settings.load_test(informational=True)
        self.settings.compute_missing_results(r)
        self.settings.FORMAT = 'metadata'

        for f in TEST_FORMATTERS:
            try:
                self.settings.FORMAT = f
                self.settings.OUTPUT = os.path.join(
                    self.output_dir, "%s.txt" % f)
                formatter = formatters.new(self.settings)
                formatter.format([r])
                res, _ = formatter.verify()
                if not res:
                    raise self.failureException(
                        "Verification of formatter '%s' failed" % f)
            except self.failureException:
                raise
            except Exception:
                tb = traceback.format_exc()
                new_exc = Exception("Error creating formatter '%s'" % f)
                new_exc.orig_tb = tb
                raise new_exc


test_suite = unittest.TestSuite()
for fname in get_test_data_files():
    test_suite.addTest(TestFormatters(fname))