Skip to content

Commit 762cd2c

Browse files
author
Steve Canny
committed
test: add Python 3.4 compatibility
* remove 3.2 compatibility claim from setup.py * add 3.4 environment to tox.ini * add version-dependent mock imports, becomes unittest.mock from 3.3 forward. Put all the imports in tests.unittest and import locally from there to centralize version-detection logic.
1 parent f74dcd2 commit 762cd2c

14 files changed

+43
-35
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: python
22
python:
3+
- "3.4"
34
- "3.3"
45
- "2.7"
56
- "2.6"

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def text_of(relpath):
5151
'Programming Language :: Python :: 2.6',
5252
'Programming Language :: Python :: 2.7',
5353
'Programming Language :: Python :: 3',
54-
'Programming Language :: Python :: 3.2',
5554
'Programming Language :: Python :: 3.3',
55+
'Programming Language :: Python :: 3.4',
5656
'Topic :: Office/Business :: Office Suites',
5757
'Topic :: Software Development :: Libraries'
5858
]

tests/image/test_jpeg.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from mock import call
12-
1311
from docx.compat import BytesIO
1412
from docx.image.constants import JPEG_MARKER_CODE, MIME_TYPE
1513
from docx.image.helpers import BIG_ENDIAN, StreamReader
@@ -20,7 +18,7 @@
2018
from docx.image.tiff import Tiff
2119

2220
from ..unitutil import (
23-
initializer_mock, class_mock, instance_mock, method_mock
21+
call, class_mock, initializer_mock, instance_mock, method_mock
2422
)
2523

2624

tests/image/test_png.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from mock import call
12-
1311
from docx.compat import BytesIO
1412
from docx.image.constants import MIME_TYPE, PNG_CHUNK_TYPE
1513
from docx.image.exceptions import InvalidImageStreamError
@@ -20,7 +18,8 @@
2018
)
2119

2220
from ..unitutil import (
23-
function_mock, class_mock, initializer_mock, instance_mock, method_mock
21+
call, class_mock, function_mock, initializer_mock, instance_mock,
22+
method_mock
2423
)
2524

2625

tests/image/test_tiff.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from mock import call
12-
1311
from docx.compat import BytesIO
1412
from docx.image.constants import MIME_TYPE, TIFF_TAG
1513
from docx.image.helpers import BIG_ENDIAN, LITTLE_ENDIAN, StreamReader
@@ -19,8 +17,8 @@
1917
)
2018

2119
from ..unitutil import (
22-
function_mock, class_mock, initializer_mock, instance_mock, loose_mock,
23-
method_mock
20+
call, class_mock, function_mock, initializer_mock, instance_mock,
21+
loose_mock, method_mock
2422
)
2523

2624

tests/opc/test_package.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from mock import call, Mock, patch, PropertyMock
12-
1311
from docx.opc.oxml import CT_Relationships
1412
from docx.opc.packuri import PACKAGE_URI, PackURI
1513
from docx.opc.package import (
@@ -19,8 +17,8 @@
1917
from docx.opc.pkgreader import PackageReader
2018

2119
from ..unitutil import (
22-
cls_attr_mock, class_mock, function_mock, instance_mock, loose_mock,
23-
method_mock
20+
call, class_mock, cls_attr_mock, function_mock, instance_mock,
21+
loose_mock, method_mock, Mock, patch, PropertyMock
2422
)
2523

2624

tests/opc/test_phys_pkg.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import hashlib
1515
import pytest
1616

17-
from mock import Mock
1817
from zipfile import ZIP_DEFLATED, ZipFile
1918

2019
from docx.opc.exceptions import PackageNotFoundError
@@ -23,7 +22,7 @@
2322
_DirPkgReader, PhysPkgReader, PhysPkgWriter, _ZipPkgReader, _ZipPkgWriter
2423
)
2524

26-
from ..unitutil import absjoin, class_mock, loose_mock, test_file_dir
25+
from ..unitutil import absjoin, class_mock, loose_mock, Mock, test_file_dir
2726

2827

2928
test_docx_path = absjoin(test_file_dir, 'test.docx')

tests/opc/test_pkgreader.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from mock import call, Mock, patch
12-
1311
from docx.opc.constants import (
1412
CONTENT_TYPE as CT, RELATIONSHIP_TARGET_MODE as RTM
1513
)
@@ -22,8 +20,8 @@
2220

2321
from .unitdata.types import a_Default, a_Types, an_Override
2422
from ..unitutil import (
25-
initializer_mock, class_mock, function_mock, instance_mock, loose_mock,
26-
method_mock
23+
call, class_mock, function_mock, initializer_mock, instance_mock,
24+
loose_mock, method_mock, Mock, patch
2725
)
2826

2927

tests/opc/test_pkgwriter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
import pytest
88

9-
from mock import call, MagicMock, Mock, patch
10-
119
from docx.opc.constants import CONTENT_TYPE as CT
1210
from docx.opc.package import Part
1311
from docx.opc.packuri import PackURI
1412
from docx.opc.phys_pkg import _ZipPkgWriter
1513
from docx.opc.pkgwriter import _ContentTypesItem, PackageWriter
1614

1715
from .unitdata.types import a_Default, a_Types, an_Override
18-
from ..unitutil import class_mock, instance_mock, method_mock
16+
from ..unitutil import (
17+
call, class_mock, instance_mock, MagicMock, method_mock, Mock, patch
18+
)
1919

2020

2121
class DescribePackageWriter(object):

tests/opc/test_rels.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import pytest
1010

11-
from mock import call, Mock, patch, PropertyMock
12-
1311
from docx.opc.constants import RELATIONSHIP_TYPE as RT
1412
from docx.opc.oxml import CT_Relationships
1513
from docx.opc.package import Part, _Relationship, Relationships
1614
from docx.opc.packuri import PackURI
1715

18-
from ..unitutil import class_mock, instance_mock, loose_mock
16+
from ..unitutil import (
17+
call, class_mock, instance_mock, loose_mock, Mock, patch, PropertyMock
18+
)
1919

2020

2121
class Describe_Relationship(object):

tests/parts/test_document.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import pytest
1010

11-
from mock import Mock
12-
1311
from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT
1412
from docx.opc.package import PartFactory
1513
from docx.opc.packuri import PackURI
@@ -32,7 +30,7 @@
3230
from ..oxml.unitdata.text import a_p, a_pPr, a_sectPr, an_r
3331
from ..unitutil import (
3432
function_mock, class_mock, initializer_mock, instance_mock, loose_mock,
35-
method_mock, property_mock
33+
method_mock, Mock, property_mock
3634
)
3735

3836

tests/test_text.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414

1515
import pytest
1616

17-
from mock import call, Mock
18-
1917
from .oxml.unitdata.text import (
2018
a_b, a_bCs, a_br, a_caps, a_cs, a_dstrike, a_p, a_shadow, a_smallCaps,
2119
a_snapToGrid, a_specVanish, a_strike, a_t, a_u, a_vanish, a_webHidden,
2220
an_emboss, an_i, an_iCs, an_imprint, an_oMath, a_noProof, an_outline,
2321
an_r, an_rPr, an_rStyle, an_rtl
2422
)
25-
from .unitutil import class_mock, instance_mock
23+
from .unitutil import call, class_mock, instance_mock, Mock
2624

2725

2826
class DescribeParagraph(object):

tests/unitutil.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
"""
66

77
import os
8+
import sys
9+
10+
if sys.version_info >= (3, 3):
11+
from unittest import mock # noqa
12+
from unittest.mock import call, MagicMock # noqa
13+
from unittest.mock import create_autospec, Mock, patch, PropertyMock
14+
else:
15+
import mock # noqa
16+
from mock import call, MagicMock # noqa
17+
from mock import create_autospec, Mock, patch, PropertyMock
818

9-
from mock import create_autospec, Mock, patch, PropertyMock
1019

1120
from docx.oxml.xmlchemy import serialize_for_reading
1221

tox.ini

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ python_classes = Test Describe
88
python_functions = it_ they_
99

1010
[tox]
11-
envlist = py26, py27, py33
11+
envlist = py26, py27, py33, py34
1212

1313
[testenv]
1414
deps =
@@ -20,3 +20,15 @@ deps =
2020
commands =
2121
py.test -qx
2222
behave --format progress --stop --tags=-wip
23+
24+
[testenv:py33]
25+
deps =
26+
behave
27+
lxml
28+
pytest
29+
30+
[testenv:py34]
31+
deps =
32+
behave
33+
lxml
34+
pytest

0 commit comments

Comments
 (0)