Skip to content

Commit d95e6dd

Browse files
committed
Add coverage report and several unit tests
1 parent 2798342 commit d95e6dd

File tree

9 files changed

+81
-2
lines changed

9 files changed

+81
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
# Unit test reports
77
.tox/
88
.cache
9+
.coverage

test-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# The order of packages is significant, because pip processes them in the order
22
# of appearance. Changing the order has an impact on the overall integration
33
# process, which may cause wedges in the gate later.
4+
coverage!=4.4,>=4.0 # Apache-2.0
45
pytest>=3.2.0 #MIT
56
pytest-mock>=1.6.3 #MIT

tests/__init__.py

Whitespace-only changes.

tests/unit/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

tests/unit/test_wrapper.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# Copyright 2018 Vitalii Kulanov
3+
#
4+
5+
import pytest
6+
7+
from docx import Document
8+
from docx.shared import Pt
9+
10+
from validocx import wrapper
11+
12+
13+
@pytest.fixture
14+
def document():
15+
doc = Document()
16+
doc.add_heading('Fake Title', 0)
17+
doc.add_heading('Fake Header 1', 1)
18+
doc.add_heading('Fake Header 2', 2)
19+
# Redefine font parameters for 'Normal' style
20+
style = doc.styles['Normal']
21+
font = style.font
22+
font.name = 'Calibri'
23+
font.size = Pt(12)
24+
# Add some text in 'Normal' style
25+
p = doc.add_paragraph('Some ')
26+
p.add_run('bold').bold = True
27+
p.add_run(' and some ')
28+
p.add_run('italic.').italic = True
29+
return doc
30+
31+
32+
@pytest.fixture
33+
def docx_wrapper(document):
34+
document_wrapper = wrapper.DocumentWrapper(document)
35+
return document_wrapper
36+
37+
38+
def test_fetch_author_data(docx_wrapper):
39+
assert docx_wrapper.author == 'python-docx'
40+
41+
42+
def test_fetch_date_of_creation(docx_wrapper):
43+
assert docx_wrapper.created.isoformat(' ') == '2013-12-23 23:15:00'
44+
45+
46+
def test_fetch_date_of_modification(docx_wrapper):
47+
assert docx_wrapper.modified.isoformat(' ') == '2013-12-23 23:15:00'
48+
49+
50+
def test_fetch_last_modifier_data(docx_wrapper):
51+
assert docx_wrapper.last_modified_by == ''
52+
53+
54+
@pytest.mark.parametrize('paragraph_styles, expected', [
55+
('Title', ['Fake Title']),
56+
(None, ['Fake Title', 'Fake Header 1',
57+
'Fake Header 2', 'Some bold and some italic.'])
58+
])
59+
def test_fetch_paragraph_data(docx_wrapper, paragraph_styles, expected):
60+
for item in docx_wrapper.iter_paragraphs(paragraph_styles):
61+
assert item.text in expected
62+
63+
64+
def test_fetch_section_data(docx_wrapper):
65+
assert len(list(docx_wrapper.iter_sections())) == 1
66+
67+
68+
@pytest.mark.parametrize('p_style, expected', [
69+
('Title', [[26.0, 'Calibri']]),
70+
('Normal', [[12.0, 'Calibri'], [12.0, 'Calibri', 'bold'],
71+
[12.0, 'Calibri'], [12.0, 'Calibri', 'italic']])
72+
])
73+
def test_fetch_font_attributes(docx_wrapper, p_style, expected):
74+
p = list(docx_wrapper.iter_paragraphs(p_style))[0]
75+
runs = docx_wrapper.get_font_attributes(p)
76+
assert runs == expected

tox.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ deps =
66
-r{toxinidir}/requirements.txt
77
-r{toxinidir}/test-requirements.txt
88
commands =
9-
{envpython} -m pytest -v {posargs:}
9+
{envpython} -m coverage run --source validocx -m pytest -v {posargs:}
10+
{envpython} -m coverage report -m
1011

1112
[testenv:metadata]
1213
deps =

validocx/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@ def run(arguments):
101101
mch.msg_level_count['WARNING']))
102102

103103

104-
def main(args=sys.argv[1:]):
104+
def main(args=sys.argv[1:]): # pragma: no cover
105105
sys.exit(run(arguments=parse_args(args=args)))

0 commit comments

Comments
 (0)