Skip to content

Commit

Permalink
dev: add GitHub CI test run
Browse files Browse the repository at this point in the history
  • Loading branch information
scanny committed Aug 2, 2024
1 parent dad340a commit c6a49f3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: ci

on:
pull_request:
branches: [ master ]
push:
branches:
- master
- develop

permissions:
contents: write

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install test dependencies
run: |
pip install .
pip install -r requirements-test.txt
- name: Test with pytest
run: pytest --cov=pptx --cov-report term-missing tests
- name: Acceptance tests with behave
behave --stop
8 changes: 4 additions & 4 deletions src/pptx/parts/coreprops.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: utf-8

"""Core properties part, corresponds to ``/docProps/core.xml`` part in package."""

from datetime import datetime
from __future__ import annotations

import datetime as dt

from pptx.opc.constants import CONTENT_TYPE as CT
from pptx.opc.package import XmlPart
Expand All @@ -27,7 +27,7 @@ def default(cls, package):
core_props.title = "PowerPoint Presentation"
core_props.last_modified_by = "python-pptx"
core_props.revision = 1
core_props.modified = datetime.utcnow()
core_props.modified = dt.datetime.now(dt.timezone.utc).replace(tzinfo=None)
return core_props

@property
Expand Down
28 changes: 14 additions & 14 deletions tests/parts/test_coreprops.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# encoding: utf-8

"""Unit-test suite for `pptx.parts.coreprops` module."""

import pytest
from __future__ import annotations

from datetime import datetime, timedelta
import datetime as dt

import pytest

from pptx.opc.constants import CONTENT_TYPE as CT
from pptx.oxml.coreprops import CT_CoreProperties
Expand Down Expand Up @@ -55,16 +55,18 @@ def it_can_construct_a_default_core_props(self):
assert core_props.revision == 1
# core_props.modified only stores time with seconds resolution, so
# comparison needs to be a little loose (within two seconds)
modified_timedelta = datetime.utcnow() - core_props.modified
max_expected_timedelta = timedelta(seconds=2)
modified_timedelta = (
dt.datetime.now(dt.timezone.utc).replace(tzinfo=None) - core_props.modified
)
max_expected_timedelta = dt.timedelta(seconds=2)
assert modified_timedelta < max_expected_timedelta

# fixtures -------------------------------------------------------

@pytest.fixture(
params=[
("created", datetime(2012, 11, 17, 16, 37, 40)),
("last_printed", datetime(2014, 6, 4, 4, 28)),
("created", dt.datetime(2012, 11, 17, 16, 37, 40)),
("last_printed", dt.datetime(2014, 6, 4, 4, 28)),
("modified", None),
]
)
Expand All @@ -77,21 +79,21 @@ def date_prop_get_fixture(self, request, core_properties):
(
"created",
"dcterms:created",
datetime(2001, 2, 3, 4, 5),
dt.datetime(2001, 2, 3, 4, 5),
"2001-02-03T04:05:00Z",
' xsi:type="dcterms:W3CDTF"',
),
(
"last_printed",
"cp:lastPrinted",
datetime(2014, 6, 4, 4),
dt.datetime(2014, 6, 4, 4),
"2014-06-04T04:00:00Z",
"",
),
(
"modified",
"dcterms:modified",
datetime(2005, 4, 3, 2, 1),
dt.datetime(2005, 4, 3, 2, 1),
"2005-04-03T02:01:00Z",
' xsi:type="dcterms:W3CDTF"',
),
Expand Down Expand Up @@ -145,9 +147,7 @@ def str_prop_set_fixture(self, request):
expected_xml = self.coreProperties(tagname, value)
return core_properties, prop_name, value, expected_xml

@pytest.fixture(
params=[("42", 42), (None, 0), ("foobar", 0), ("-17", 0), ("32.7", 0)]
)
@pytest.fixture(params=[("42", 42), (None, 0), ("foobar", 0), ("-17", 0), ("32.7", 0)])
def revision_get_fixture(self, request):
str_val, expected_revision = request.param
tagname = "" if str_val is None else "cp:revision"
Expand Down

0 comments on commit c6a49f3

Please sign in to comment.