Skip to content
This repository was archived by the owner on May 4, 2020. It is now read-only.

Commit 5e479b8

Browse files
committed
Merge pull request #46 from takluyver/py3
Python 3 support
2 parents a063d90 + efc7c36 commit 5e479b8

40 files changed

+441
-357
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.pyc
22
/dist
33
*.egg-info
4-
/build
4+
/build
5+
/tests/output
6+
.tox

.travis.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
language: python
2-
python:
3-
- "2.7"
4-
# command to run tests, e.g. python setup.py test
5-
script: nosetests
2+
3+
sudo: false
4+
env:
5+
- TOXENV=py27
6+
- TOXENV=py33
7+
- TOXENV=py34
8+
- TOXENV=pypy
9+
10+
install:
11+
- travis_retry pip install tox coveralls
12+
13+
script:
14+
- tox
15+
16+
after_success:
17+
- coveralls

setup.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[pytest]
2+
norecursedirs =
3+
.git
4+
.tox
5+
dist
6+
build
7+
*.egg
8+
9+
addopts =
10+
-rxEfs
11+
--strict
12+
--doctest-modules
13+
--doctest-glob \*.rst
14+
--tb short
15+
--ignore setup.py
16+
--ignore xlwt/examples/
17+
18+
markers =
19+
unit

test-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nose
2+
pytest
3+
tox

tests/RKbug.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ def cellname(rowx, colx):
88

99
def RK_pack_check(num, anint, case=None):
1010
if not(-0x7fffffff - 1 <= anint <= 0x7fffffff):
11-
print "RK_pack_check: not a signed 32-bit int: %r (%r); case: %r" \
12-
% (anint, hex(anint), case)
11+
print("RK_pack_check: not a signed 32-bit int: %r (%r); case: %r" \
12+
% (anint, hex(anint), case))
1313
pstr = pack("<i", anint)
1414
actual = unpack_RK(pstr)
1515
if actual != num:
16-
print "RK_pack_check: round trip failure: %r (%r); case %r; %r in, %r out" \
17-
% (anint, hex(anint), case, num, actual)
18-
16+
print("RK_pack_check: round trip failure: %r (%r); case %r; %r in, %r out" \
17+
% (anint, hex(anint), case, num, actual))
18+
1919

2020
def RK_encode(num, blah=0):
2121
"""\
@@ -25,22 +25,22 @@ def RK_encode(num, blah=0):
2525
rk_encoded = 0
2626
packed = pack('<d', num)
2727

28-
if blah: print
29-
if blah: print repr(num)
28+
if blah: print()
29+
if blah: print(repr(num))
3030
w01, w23 = unpack('<2i', packed)
3131
if not w01 and not(w23 & 3):
3232
# 34 lsb are 0
33-
if blah: print "float RK", w23, hex(w23)
33+
if blah: print("float RK", w23, hex(w23))
3434
return RK_pack_check(num, w23, 0)
3535
# return RKRecord(
3636
# self.__parent.get_index(), self.__idx, self.__xf_idx, w23).get()
3737

3838
if -0x20000000 <= num < 0x20000000:
3939
inum = int(num)
4040
if inum == num:
41-
if blah: print "30-bit integer RK", inum, hex(inum)
41+
if blah: print("30-bit integer RK", inum, hex(inum))
4242
rk_encoded = 2 | (inum << 2)
43-
if blah: print "rk", rk_encoded, hex(rk_encoded)
43+
if blah: print("rk", rk_encoded, hex(rk_encoded))
4444
return RK_pack_check(num, rk_encoded, 2)
4545
# return RKRecord(
4646
# self.__parent.get_index(), self.__idx, self.__xf_idx, rk_encoded).get()
@@ -50,22 +50,22 @@ def RK_encode(num, blah=0):
5050
w01, w23 = unpack('<2i', packed100)
5151
if not w01 and not(w23 & 3):
5252
# 34 lsb are 0
53-
if blah: print "float RK*100", w23, hex(w23)
53+
if blah: print("float RK*100", w23, hex(w23))
5454
return RK_pack_check(num, w23 | 1, 1)
5555
# return RKRecord(
5656
# self.__parent.get_index(), self.__idx, self.__xf_idx, w23 | 1).get()
5757

5858
if -0x20000000 <= temp < 0x20000000:
5959
itemp = int(round(temp, 0))
60-
if blah: print (itemp == temp), (itemp / 100.0 == num)
60+
if blah: print((itemp == temp), (itemp / 100.0 == num))
6161
if itemp / 100.0 == num:
62-
if blah: print "30-bit integer RK*100", itemp, hex(itemp)
62+
if blah: print("30-bit integer RK*100", itemp, hex(itemp))
6363
rk_encoded = 3 | (itemp << 2)
6464
return RK_pack_check(num, rk_encoded, 3)
6565
# return RKRecord(
6666
# self.__parent.get_index(), self.__idx, self.__xf_idx, rk_encoded).get()
6767

68-
if blah: print "Number"
68+
if blah: print("Number" )
6969
# return NumberRecord(
7070
# self.__parent.get_index(), self.__idx, self.__xf_idx, num).get()
7171

tests/mini.xls

0 Bytes
Binary file not shown.

tests/simple.xls

0 Bytes
Binary file not shown.

tests/test_easyxf.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
# Copyright (C) 2010, Manfred Moitzi
77
# License: BSD licence
88

9-
import sys
10-
import os
119
import unittest
1210
import filecmp
1311
import datetime
1412

13+
from utils import in_tst_dir, in_tst_output_dir
14+
1515
import xlwt as xlwt
1616
ezxf = xlwt.easyxf
1717

@@ -30,13 +30,10 @@ def write_xls(file_name, sheet_name, headings, data, heading_xf, data_xfs):
3030
sheet.write(rowx, colx, value, data_xfs[colx])
3131
book.save(file_name)
3232

33-
def from_tst_dir(filename):
34-
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
35-
3633
EXAMPLE_XLS = 'xlwt_easyxf_simple_demo.xls'
3734

3835
class TestUnicode0(unittest.TestCase):
39-
def create_example_xls(self):
36+
def create_example_xls(self, filename):
4037
mkd = datetime.date
4138
hdngs = ['Date', 'Stock Code', 'Quantity', 'Unit Price', 'Value', 'Message']
4239
kinds = 'date text int price money text'.split()
@@ -57,12 +54,12 @@ def create_example_xls(self):
5754
'text': ezxf(),
5855
}
5956
data_xfs = [kind_to_xf_map[k] for k in kinds]
60-
write_xls(EXAMPLE_XLS, 'Demo', hdngs, data, heading_xf, data_xfs)
57+
write_xls(filename, 'Demo', hdngs, data, heading_xf, data_xfs)
6158

6259
def test_example_xls(self):
63-
self.create_example_xls()
64-
self.assertTrue(filecmp.cmp(from_tst_dir(EXAMPLE_XLS),
65-
from_tst_dir('output-0.7.2/'+EXAMPLE_XLS),
60+
self.create_example_xls(in_tst_output_dir(EXAMPLE_XLS))
61+
self.assertTrue(filecmp.cmp(in_tst_dir(EXAMPLE_XLS),
62+
in_tst_output_dir(EXAMPLE_XLS),
6663
shallow=False))
6764

6865
if __name__=='__main__':

tests/test_mini.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import unittest
1212
import filecmp
1313

14+
from utils import in_tst_dir, in_tst_output_dir
15+
1416
import xlwt
1517

1618
def from_tst_dir(filename):
@@ -20,10 +22,10 @@ class TestMini(unittest.TestCase):
2022
def test_create_mini_xls(self):
2123
book = xlwt.Workbook()
2224
sheet = book.add_sheet('xlwt was here')
23-
book.save('mini.xls')
25+
book.save(in_tst_output_dir('mini.xls'))
2426

25-
self.assertTrue(filecmp.cmp(from_tst_dir('mini.xls'),
26-
from_tst_dir(os.path.join('output-0.7.2', 'mini.xls')),
27+
self.assertTrue(filecmp.cmp(in_tst_dir('mini.xls'),
28+
in_tst_output_dir('mini.xls'),
2729
shallow=False))
2830

2931
if __name__=='__main__':

tests/test_simple.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
import filecmp
1313
from datetime import datetime
1414

15-
import xlwt
15+
from utils import in_tst_dir, in_tst_output_dir
1616

17-
def from_tst_dir(filename):
18-
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
17+
import xlwt
1918

2019
class TestSimple(unittest.TestCase):
2120
def create_simple_xls(self):
@@ -39,12 +38,12 @@ def create_simple_xls(self):
3938
ws.write(2, 1, 1)
4039
ws.write(2, 2, xlwt.Formula("A3+B3"))
4140

42-
wb.save('simple.xls')
41+
wb.save(in_tst_output_dir('simple.xls'))
4342

4443
def test_create_simple_xls(self):
4544
self.create_simple_xls()
46-
self.assertTrue(filecmp.cmp(from_tst_dir('simple.xls'),
47-
from_tst_dir(os.path.join('output-0.7.2', 'simple.xls')),
45+
self.assertTrue(filecmp.cmp(in_tst_dir('simple.xls'),
46+
in_tst_output_dir('simple.xls'),
4847
shallow=False))
4948

5049
if __name__=='__main__':

tests/test_unicode1.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
# Copyright (C) 2010, Manfred Moitzi
77
# License: BSD licence
88

9-
import sys
109
import os
1110
import unittest
1211
import filecmp
1312

1413
import xlwt
1514

16-
def from_tst_dir(filename):
17-
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
15+
from utils import in_tst_dir, in_tst_output_dir
1816

1917
def create_example_xls(filename):
2018
w = xlwt.Workbook()
@@ -44,9 +42,9 @@ def create_example_xls(filename):
4442
class TestUnicode1(unittest.TestCase):
4543

4644
def test_example_xls(self):
47-
create_example_xls(EXAMPLE_XLS)
48-
self.assertTrue(filecmp.cmp(from_tst_dir(EXAMPLE_XLS),
49-
from_tst_dir(os.path.join('output-0.7.2', EXAMPLE_XLS)),
45+
create_example_xls(in_tst_output_dir(EXAMPLE_XLS))
46+
self.assertTrue(filecmp.cmp(in_tst_dir(EXAMPLE_XLS),
47+
in_tst_output_dir(EXAMPLE_XLS),
5048
shallow=False))
5149
if __name__=='__main__':
5250
unittest.main()

tests/unicode1.xls

0 Bytes
Binary file not shown.

tests/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
from os.path import join, dirname, abspath, isdir
3+
4+
def in_tst_dir(filename):
5+
return join(dirname(abspath(__file__)), filename)
6+
7+
def in_tst_output_dir(filename):
8+
output_dir = join(dirname(abspath(__file__)), 'output')
9+
if not isdir(output_dir):
10+
os.mkdir(output_dir, 0o755)
11+
return join(output_dir, filename)

tests/xlwt_easyxf_simple_demo.xls

0 Bytes
Binary file not shown.

tox.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[tox]
2+
skipsdist = True
3+
envlist = py27, py33, py34, pypy
4+
5+
[base]
6+
commands =
7+
pip install -e . -r test-requirements.txt
8+
9+
[testenv]
10+
pip_pre=False
11+
commands =
12+
{[base]commands}
13+
py.test {posargs} tests/

0 commit comments

Comments
 (0)