File: base_test_class.py

package info (click to toggle)
libxlsxwriter 1.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,888 kB
  • sloc: ansic: 65,861; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (68 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download
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
###############################################################################
#
# Base test class for libxlsxwriter functional tests.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2014-2026, John McNamara, jmcnamara@cpan.org.
#

import unittest
import os
import sys
from helper_functions import _compare_xlsx_files


class XLSXBaseTest(unittest.TestCase):
    """
    Test file created with libxlsxwriter against a file created by Excel.

    """

    def setUp(self):
        self.maxDiff = None

        self.no_system_error = 0
        self.got_filename = ''
        self.exp_filename = ''
        self.ignore_files = []
        self.ignore_elements = {}

    def run_exe_test(self, exe_name, exp_filename=None):
        """Run C exe and compare output xlsx file with the Excel file."""

        # Create the executable command
        if sys.platform == 'win32':
            command = r'cd test\functional\src && %s.exe' % exe_name
        else:
            command = 'cd test/functional/src && ./%s' % exe_name

        # Run the C executable to generate the "got" xlsx file.
        got = os.system(command)
        self.assertEqual(got, self.no_system_error)

        # Create the path/file names for the xlsx/xlsm files to compare.
        if exp_filename and exp_filename.endswith('.xlsm'):
            got_filename = exe_name.replace('test_', '') + '.xlsm'
        else:
            got_filename = exe_name.replace('test_', '') + '.xlsx'

        if not exp_filename:
            exp_filename = got_filename

        self.got_filename = 'test/functional/src/test_' + got_filename
        self.exp_filename = 'test/functional/xlsx_files/' + exp_filename

        # Do the comparison between the files.
        got, exp = _compare_xlsx_files(self.got_filename,
                                       self.exp_filename,
                                       self.ignore_files,
                                       self.ignore_elements)
        self.assertEqual(exp, got)

    def tearDown(self):
        # Cleanup.
        if os.path.exists(self.got_filename):
            os.remove(self.got_filename)

        self.ignore_files = []
        self.ignore_elements = {}