Skip to content

Commit

Permalink
type: general modernization
Browse files Browse the repository at this point in the history
Add type-annotations broadly, but prioritizing interface objects and
methods. Adjust text-width to 100, remove Python 2 support, etc.
  • Loading branch information
scanny committed Aug 3, 2024
1 parent efb48f2 commit f39394b
Show file tree
Hide file tree
Showing 194 changed files with 6,311 additions and 7,751 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Philosophy
----------

|pp| aims to broadly support the PowerPoint format (PPTX, PowerPoint 2007 and later),
but its primary commitment is to be _industrial-grade_, that is, suitable for use in a
but its primary commitment is to be *industrial-grade*, that is, suitable for use in a
commercial setting. Maintaining this robustness requires a high engineering standard
which includes a comprehensive two-level (e2e + unit) testing regimen. This discipline
comes at a cost in development effort/time, but we consider reliability to be an
Expand Down
8 changes: 3 additions & 5 deletions features/steps/action.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# encoding: utf-8

"""Gherkin step implementations for click action-related features."""

from __future__ import annotations

from behave import given, then, when
from helpers import test_file

from pptx import Presentation
from pptx.action import Hyperlink
from pptx.enum.action import PP_ACTION

from helpers import test_file


# given ===================================================


Expand Down
28 changes: 7 additions & 21 deletions features/steps/axis.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
# encoding: utf-8

"""Gherkin step implementations for chart axis features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, then, when
from helpers import test_pptx

from pptx import Presentation
from pptx.enum.chart import XL_AXIS_CROSSES, XL_CATEGORY_TYPE

from helpers import test_pptx


# given ===================================================


@given("a {axis_type} axis")
def given_a_axis_type_axis(context, axis_type):
prs = Presentation(test_pptx("cht-axis-props"))
chart = prs.slides[0].shapes[0].chart
context.axis = {"category": chart.category_axis, "value": chart.value_axis}[
axis_type
]
context.axis = {"category": chart.category_axis, "value": chart.value_axis}[axis_type]


@given("a major gridlines")
Expand All @@ -33,9 +27,7 @@ def given_a_major_gridlines(context):

@given("a value axis having category axis crossing of {crossing}")
def given_a_value_axis_having_cat_ax_crossing_of(context, crossing):
slide_idx = {"automatic": 0, "maximum": 2, "minimum": 3, "2.75": 4, "-1.5": 5}[
crossing
]
slide_idx = {"automatic": 0, "maximum": 2, "minimum": 3, "2.75": 4, "-1.5": 5}[crossing]
prs = Presentation(test_pptx("cht-axis-props"))
context.value_axis = prs.slides[slide_idx].shapes[0].chart.value_axis

Expand Down Expand Up @@ -122,9 +114,7 @@ def when_I_assign_value_to_axis_has_title(context, value):


@when("I assign {value} to axis.has_{major_or_minor}_gridlines")
def when_I_assign_value_to_axis_has_major_or_minor_gridlines(
context, value, major_or_minor
):
def when_I_assign_value_to_axis_has_major_or_minor_gridlines(context, value, major_or_minor):
axis = context.axis
propname = "has_%s_gridlines" % major_or_minor
new_value = {"True": True, "False": False}[value]
Expand Down Expand Up @@ -210,9 +200,7 @@ def then_axis_has_title_is_value(context, value):


@then("axis.has_{major_or_minor}_gridlines is {value}")
def then_axis_has_major_or_minor_gridlines_is_expected_value(
context, major_or_minor, value
):
def then_axis_has_major_or_minor_gridlines_is_expected_value(context, major_or_minor, value):
axis = context.axis
actual_value = {
"major": axis.has_major_gridlines,
Expand All @@ -233,9 +221,7 @@ def then_axis_major_or_minor_unit_is_value(context, major_or_minor, value):
axis = context.axis
propname = "%s_unit" % major_or_minor
actual_value = getattr(axis, propname)
expected_value = {"20.0": 20.0, "8.4": 8.4, "5.0": 5.0, "4.2": 4.2, "None": None}[
value
]
expected_value = {"20.0": 20.0, "8.4": 8.4, "5.0": 5.0, "4.2": 4.2, "None": None}[value]
assert actual_value == expected_value, "got %s" % actual_value


Expand Down
8 changes: 2 additions & 6 deletions features/steps/background.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# encoding: utf-8

"""Gherkin step implementations for slide background-related features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, then

from pptx import Presentation

from helpers import test_pptx

from pptx import Presentation

# given ===================================================

Expand Down
8 changes: 2 additions & 6 deletions features/steps/category.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# encoding: utf-8

"""Gherkin step implementations for chart category features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, then

from pptx import Presentation

from helpers import test_pptx

from pptx import Presentation

# given ===================================================

Expand Down
13 changes: 3 additions & 10 deletions features/steps/chart.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# encoding: utf-8
"""Gherkin step implementations for chart features."""

"""
Gherkin step implementations for chart features.
"""

from __future__ import absolute_import, print_function
from __future__ import annotations

import hashlib

from itertools import islice

from behave import given, then, when
from helpers import count, test_pptx

from pptx import Presentation
from pptx.chart.chart import Legend
Expand All @@ -19,9 +15,6 @@
from pptx.parts.embeddedpackage import EmbeddedXlsxPart
from pptx.util import Inches

from helpers import count, test_pptx


# given ===================================================


Expand Down
5 changes: 1 addition & 4 deletions features/steps/chartdata.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# encoding: utf-8

"""Gherkin step implementations for chart data features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

import datetime

Expand All @@ -12,7 +10,6 @@
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches


# given ===================================================


Expand Down
10 changes: 3 additions & 7 deletions features/steps/color.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# encoding: utf-8

"""Gherkin step implementations for ColorFormat-related features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, when, then
from behave import given, then, when
from helpers import test_pptx

from pptx import Presentation
from pptx.dml.color import RGBColor
from pptx.enum.dml import MSO_THEME_COLOR

from helpers import test_pptx


# given ====================================================


Expand Down
16 changes: 5 additions & 11 deletions features/steps/coreprops.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# encoding: utf-8
"""Gherkin step implementations for core properties-related features."""

"""
Gherkin step implementations for core properties-related features.
"""

from __future__ import absolute_import
from __future__ import annotations

from datetime import datetime, timedelta

from behave import given, when, then
from behave import given, then, when
from helpers import no_core_props_pptx_path, saved_pptx_path

from pptx import Presentation

from helpers import saved_pptx_path, no_core_props_pptx_path


# given ===================================================


Expand Down Expand Up @@ -49,7 +43,7 @@ def step_when_set_core_doc_props_to_valid_values(context):
("revision", 9),
("subject", "Subject"),
# --- exercise unicode-text case for Python 2.7 ---
("title", u"åß∂Title°"),
("title", "åß∂Title°"),
("version", "Version"),
)
for name, value in context.propvals:
Expand Down
8 changes: 2 additions & 6 deletions features/steps/datalabel.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# encoding: utf-8

"""Gherkin step implementations for chart data label features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, then, when
from helpers import test_pptx

from pptx import Presentation
from pptx.enum.chart import XL_DATA_LABEL_POSITION

from helpers import test_pptx


# given ===================================================


Expand Down
8 changes: 2 additions & 6 deletions features/steps/effect.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# encoding: utf-8

"""Gherkin step implementations for ShadowFormat-related features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, then, when

from pptx import Presentation

from helpers import test_pptx

from pptx import Presentation

# given ====================================================

Expand Down
24 changes: 6 additions & 18 deletions features/steps/fill.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# encoding: utf-8

"""Gherkin step implementations for FillFormat-related features."""

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations

from behave import given, then, when
from helpers import test_pptx

from pptx import Presentation
from pptx.enum.dml import MSO_FILL, MSO_PATTERN # noqa

from helpers import test_pptx


# given ====================================================


Expand All @@ -23,9 +19,7 @@ def given_a_FillFormat_object_as_fill(context):

@given("a FillFormat object as fill having {pattern} fill")
def given_a_FillFormat_object_as_fill_having_pattern(context, pattern):
shape_idx = {"no pattern": 0, "MSO_PATTERN.DIVOT": 1, "MSO_PATTERN.WAVE": 2}[
pattern
]
shape_idx = {"no pattern": 0, "MSO_PATTERN.DIVOT": 1, "MSO_PATTERN.WAVE": 2}[pattern]
slide = Presentation(test_pptx("dml-fill")).slides[1]
fill = slide.shapes[shape_idx].fill
context.fill = fill
Expand Down Expand Up @@ -102,18 +96,14 @@ def when_I_call_fill_solid(context):
def then_fill_back_color_is_a_ColorFormat_object(context):
actual_value = context.fill.back_color.__class__.__name__
expected_value = "ColorFormat"
assert actual_value == expected_value, (
"fill.back_color is a %s object" % actual_value
)
assert actual_value == expected_value, "fill.back_color is a %s object" % actual_value


@then("fill.fore_color is a ColorFormat object")
def then_fill_fore_color_is_a_ColorFormat_object(context):
actual_value = context.fill.fore_color.__class__.__name__
expected_value = "ColorFormat"
assert actual_value == expected_value, (
"fill.fore_color is a %s object" % actual_value
)
assert actual_value == expected_value, "fill.fore_color is a %s object" % actual_value


@then("fill.gradient_angle == {value}")
Expand All @@ -127,9 +117,7 @@ def then_fill_gradient_angle_eq_value(context, value):
def then_fill_gradient_stops_is_a_GradientStops_object(context):
expected_value = "_GradientStops"
actual_value = context.fill.gradient_stops.__class__.__name__
assert actual_value == expected_value, (
"fill.gradient_stops is a %s object" % actual_value
)
assert actual_value == expected_value, "fill.gradient_stops is a %s object" % actual_value


@then("fill.pattern is {value}")
Expand Down
12 changes: 3 additions & 9 deletions features/steps/font.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# encoding: utf-8
"""Step implementations for run property (font)-related features."""

"""
Step implementations for run property (font)-related features
"""

from __future__ import absolute_import
from __future__ import annotations

from behave import given, then, when
from helpers import test_pptx

from pptx import Presentation
from pptx.enum.lang import MSO_LANGUAGE_ID
from pptx.enum.text import MSO_UNDERLINE

from helpers import test_pptx


# given ===================================================


Expand Down
Loading

0 comments on commit f39394b

Please sign in to comment.