test_Workbook.py :  » XML » pyXLWriter » pyXLWriter-0.4a3 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » XML » pyXLWriter 
pyXLWriter » pyXLWriter 0.4a3 » tests » test_Workbook.py
#!/usr/bin/env python
__revision__ = """$Id: test_Workbook.py,v 1.10 2004/04/14 11:06:37 fufff Exp $"""

import os, os.path
import unittest

import testsupport
from pyXLWriter.Workbook import Workbook
from testsupport import is_equal_files


class WorkbookTest(unittest.TestCase):

    filename = "test.xls"
    perldir = "perl_sample/"
    
    def setUp(self):
        self.wb = Workbook(self.filename)

    def tearDown(self):
        if self.wb:
            self.wb.close()
            self.wb = None
        if os.path.exists(self.filename):
            os.remove(self.filename)

    def _compare_files(self, filename1, filename2):
        if not is_equal_files(filename1, filename2):
            self.fail("Files are not equals")

    def test_add_worksheet(self):
        ws = self.wb.add_worksheet()

    def test_calc_sheet_offsets(self):
        ws = self.wb.add_worksheet()
        self.wb._calc_sheet_offsets()

    def test_add_format(self):
        self.wb.add_format()
        self.assertEqual(5, len(self.wb._formats), "Bad number of formats")

    def test_etalon_worksheet(self):
        wb = self.wb
        perl_filename = os.path.join(self.perldir, "worksheet.xls")
        ws = wb.add_worksheet()
        self.wb.close()
        self._compare_files(self.filename, perl_filename)

    def test_etalon_write(self):
        wb = self.wb
        perl_filename = os.path.join(self.perldir, "write.xls")
        ws1 = wb.add_worksheet("List1")
        ws2 = wb.add_worksheet("List2")
        ws1.write("AA4", "AA4!")
        ws2.write("C1", "C1!")
        ws1.write("A3", "!A3!")
        self.wb.close()
        self._compare_files(self.filename, perl_filename)

    def test_etalon_selection(self):
        wb = self.wb
        perl_filename = os.path.join(self.perldir, "selection.xls")
        ws = wb.add_worksheet("Sheet 1")
        ws.set_selection([4, 6, 10, 100])
        wb.close()
        self._compare_files(self.filename, perl_filename)


class WorkbookBigTest(unittest.TestCase):
    
    filename = "test.xls"
    perldir = "perl_sample/"
    
    def setUp(self):
        self.wb = Workbook(self.filename, big=True)

    def tearDown(self):
        if self.wb:
            self.wb.close()
            self.wb = None
        if os.path.exists(self.filename):
            os.remove(self.filename)

    def _compare_files(self, filename1, filename2):
        if not is_equal_files(filename1, filename2):
            self.fail("Files are not equals")

    def test_addworksheet(self):
        self.wb.add_worksheet()
        self.wb.close()
        self.wb = None

    def test_write(self):
        ws = self.wb.add_worksheet()
        ws.write((0, 0), "(0, 0)")
        self.wb.close()
        self.wb = None

    def test_etalon_write_small_big(self):
        ws = self.wb.add_worksheet()
        ws.write("A1", "Used OLEWriterBig!")
        self.wb.close()
        self.wb = None
        perl_filename = os.path.join(self.perldir, "small_big.xls")
        self._compare_files(self.filename, perl_filename)

    def test_etalon_write_big(self):
        ws = self.wb.add_worksheet()
        ws.set_column((0, 50), 18)
        for col in xrange(50+1):
            for row in xrange(60+1):
                ws.write((row, col), "Row: %d Col: %d" % (row, col))
        self.wb.close()
        self.wb = None
        perl_filename = os.path.join(self.perldir, "big.xls")
        self._compare_files(self.filename, perl_filename)


if __name__ == "__main__":
    unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.