File: test_cell.py

package info (click to toggle)
python-xlrd 2.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,832 kB
  • sloc: python: 7,531; makefile: 118; sh: 7
file content (50 lines) | stat: -rw-r--r-- 1,901 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
# Portions Copyright (C) 2010, Manfred Moitzi under a BSD licence

import unittest

import xlrd
from xlrd.timemachine import UNICODE_LITERAL

from .helpers import from_sample


class TestCell(unittest.TestCase):

    def setUp(self):
        self.book = xlrd.open_workbook(from_sample('profiles.xls'), formatting_info=True)
        self.sheet = self.book.sheet_by_name('PROFILEDEF')

    def test_empty_cell(self):
        sheet = self.book.sheet_by_name('TRAVERSALCHAINAGE')
        cell = sheet.cell(0, 0)
        self.assertEqual(cell.ctype, xlrd.book.XL_CELL_EMPTY)
        self.assertEqual(cell.value, '')
        self.assertEqual(type(cell.value), type(UNICODE_LITERAL('')))
        self.assertTrue(cell.xf_index > 0)

    def test_string_cell(self):
        cell = self.sheet.cell(0, 0)
        self.assertEqual(cell.ctype, xlrd.book.XL_CELL_TEXT)
        self.assertEqual(cell.value, 'PROFIL')
        self.assertEqual(type(cell.value), type(UNICODE_LITERAL('')))
        self.assertTrue(cell.xf_index > 0)

    def test_number_cell(self):
        cell = self.sheet.cell(1, 1)
        self.assertEqual(cell.ctype, xlrd.book.XL_CELL_NUMBER)
        self.assertEqual(cell.value, 100)
        self.assertTrue(cell.xf_index > 0)

    def test_calculated_cell(self):
        sheet2 = self.book.sheet_by_name('PROFILELEVELS')
        cell = sheet2.cell(1, 3)
        self.assertEqual(cell.ctype, xlrd.book.XL_CELL_NUMBER)
        self.assertAlmostEqual(cell.value, 265.131, places=3)
        self.assertTrue(cell.xf_index > 0)

    def test_merged_cells(self):
        book = xlrd.open_workbook(from_sample('xf_class.xls'), formatting_info=True)
        sheet3 = book.sheet_by_name('table2')
        row_lo, row_hi, col_lo, col_hi = sheet3.merged_cells[0]
        self.assertEqual(sheet3.cell(row_lo, col_lo).value, 'MERGED')
        self.assertEqual((row_lo, row_hi, col_lo, col_hi), (3, 7, 2, 5))