Skip to content

Commit

Permalink
Merge pull request #472 from radish-bdd/bugfix/utc-datetime
Browse files Browse the repository at this point in the history
Bugfix utc datetime and drop old stuff
  • Loading branch information
fliiiix authored Nov 10, 2024
2 parents 2d6997e + ef075a4 commit 2d2523e
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 63 deletions.
24 changes: 9 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v4
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: 3.12
python-version: 3.13
- name: Setup and install tools
run: |
python -m pip install --upgrade black
Expand All @@ -22,19 +22,17 @@ jobs:
fail-fast: false
max-parallel: 8
matrix:
python-version: [3.7, 3.12]
python-version: [3.7, 3.13]
os: [ubuntu-latest, windows-latest, macOS-latest]
include:
- os: ubuntu-20.04
python-version: 3.5
- os: ubuntu-20.04
python-version: 3.6
exclude:
- os: macos-latest
python-version: 3.7

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup build and test environment
Expand All @@ -43,10 +41,6 @@ jobs:
- name: Build Python Package
run: |
python -m pip install -r requirements-dev.txt
- name: Update pytest on >= Python3.10
if: ${{ matrix.python-version == '3.12' }}
run: |
python -m pip install pytest==7.0.1
- name: Unit Test with pytest
run: |
coverage run -p --source radish -m pytest tests/unit/ --junitxml=junit/unit-test-results.xml
Expand All @@ -67,7 +61,7 @@ jobs:
- name: Upload coverage to Codecov
# codecov only runs on Linux
if: startsWith(matrix.os, 'ubuntu-')
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
9 changes: 0 additions & 9 deletions .pyup.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

*Stay tuned...*
### Fixed
- utcnow deprecation

### Changes
- Drop Python 3.6 and Python 3.7

## [v0.17.1]

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tool.black]
line-length = 88
py36 = true
include = '\.pyi?$'
exclude = '''
/(
Expand Down
4 changes: 2 additions & 2 deletions radish/extensions/cucumber_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module provides a hook which generates a cucumber json result file at the end of the run.
"""

from datetime import timedelta, datetime
from datetime import timedelta, datetime, timezone
import json

from radish.terrain import world
Expand Down Expand Up @@ -44,7 +44,7 @@ def generate_ccjson(self, features, marker):
if feature.starttime is not None:
# feature file run not finished
if feature.endtime is None:
duration += feature.starttime - datetime.utcnow()
duration += feature.starttime - datetime.now(timezone.utc)
# feature file run finished
else:
duration += feature.duration
Expand Down
14 changes: 7 additions & 7 deletions radish/extensions/time_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module is a REQUIRED extension to record the time of Features, Scenarios and Steps
"""

from datetime import datetime
from datetime import datetime, timezone

from radish.hookregistry import after, before
from radish.extensionregistry import extension
Expand Down Expand Up @@ -33,34 +33,34 @@ def time_recorder_before_each_feature(self, feature):
"""
Sets the starttime of the feature
"""
feature.starttime = datetime.utcnow()
feature.starttime = datetime.now(timezone.utc)

def time_recorder_before_each_scenario(self, scenario):
"""
Sets the starttime of the scenario
"""
scenario.starttime = datetime.utcnow()
scenario.starttime = datetime.now(timezone.utc)

def time_recorder_before_each_step(self, step):
"""
Sets the starttime of the step
"""
step.starttime = datetime.utcnow()
step.starttime = datetime.now(timezone.utc)

def time_recorder_after_each_feature(self, feature):
"""
Sets the endtime of the feature
"""
feature.endtime = datetime.utcnow()
feature.endtime = datetime.now(timezone.utc)

def time_recorder_after_each_scenario(self, scenario):
"""
Sets the endtime of the scenario
"""
scenario.endtime = datetime.utcnow()
scenario.endtime = datetime.now(timezone.utc)

def time_recorder_after_each_step(self, step):
"""
Sets the endtime of the step
"""
step.endtime = datetime.utcnow()
step.endtime = datetime.now(timezone.utc)
4 changes: 2 additions & 2 deletions radish/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pydoc
import itertools
import calendar
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone


class Failure(object): # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -110,7 +110,7 @@ def format_utc_to_local_tz(utc_dt, fmt="%Y-%m-%dT%H:%M:%S"):

def utc_to_local(utc_dt):
timestamp = calendar.timegm(utc_dt.timetuple())
local_dt = datetime.fromtimestamp(timestamp)
local_dt = datetime.fromtimestamp(timestamp, tz=timezone.utc)
assert utc_dt.resolution >= timedelta(microseconds=1)
return local_dt.replace(microsecond=utc_dt.microsecond)

Expand Down
8 changes: 4 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
freezegun==1.1.0
pytest==6.1.2
pytest-mock==3.5.1
sphinx==3.5.4
freezegun==1.5.1
pytest==7.4.4
pytest-mock==3.11.1
sphinx==5.3.0
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pysingleton==0.2.1
colorful==0.5.5
colorful==0.5.6
docopt==0.6.2
ipython==7.9.0
ipython==7.34.0
tag-expressions>=2.0.0
lxml==4.9.3
parse_type==0.6.0
coverage==5.5
PyYAML==5.3.1
humanize==2.6.0
lxml==5.3.0
parse_type==0.6.4
coverage==7.2.7
PyYAML==6.0.1
humanize==4.6.0
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ def get_meta(name):
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation",
"Topic :: Education :: Testing",
"Topic :: Software Development",
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/extensions/test_junit_xml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import pytest

from datetime import datetime
from datetime import datetime, timezone

from radish.terrain import world
from radish.exceptions import RadishError
Expand All @@ -33,8 +33,8 @@ def test_singel_feature_list(mocker):
stub = mocker.patch("radish.extensions.junit_xml_writer.JUnitXMLWriter._write_xml_to_disk")

first_feature = Feature(1, "Feature", "I am a feature", "foo.feature", 1, tags=None)
first_feature.starttime = datetime.utcnow()
first_feature.endtime = datetime.utcnow()
first_feature.starttime = datetime.now(timezone.utc)
first_feature.endtime = datetime.now(timezone.utc)

features = [first_feature]

Expand All @@ -61,12 +61,12 @@ def test_normal_feature_list(mocker):
preconditions=None,
background=None,
)
first_scenario.starttime = datetime.utcnow()
first_scenario.endtime = datetime.utcnow()
first_scenario.starttime = datetime.now(timezone.utc)
first_scenario.endtime = datetime.now(timezone.utc)

first_feature = Feature(1, "Feature", "I am a feature", "foo.feature", 1, tags=None)
first_feature.starttime = datetime.utcnow()
first_feature.endtime = datetime.utcnow()
first_feature.starttime = datetime.now(timezone.utc)
first_feature.endtime = datetime.now(timezone.utc)
first_feature.scenarios.append(first_scenario)

features = [first_feature]
Expand Down Expand Up @@ -95,12 +95,12 @@ def test_relaxed_mode_adding_tags_to_junit(mocker):
preconditions=None,
background=None,
)
first_scenario.starttime = datetime.utcnow()
first_scenario.endtime = datetime.utcnow()
first_scenario.starttime = datetime.now(timezone.utc)
first_scenario.endtime = datetime.now(timezone.utc)

first_feature = Feature(1, "Feature", "I am a feature", "foo.feature", 1, tags=None)
first_feature.starttime = datetime.utcnow()
first_feature.endtime = datetime.utcnow()
first_feature.starttime = datetime.now(timezone.utc)
first_feature.endtime = datetime.now(timezone.utc)
first_feature.scenarios.append(first_scenario)

features = [first_feature]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Copyright: MIT, Timo Furrer <[email protected]>
"""

from datetime import datetime
from datetime import datetime, timezone

import pytest
from freezegun import freeze_time
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_date_time_formatter():
Test datetime to string format
"""
# given
utc_dt = datetime.utcnow()
utc_dt = datetime.now(timezone.utc)
expected_datetime_string = "2015-10-21T05:29:00"
actual_datetime_string = utils.format_utc_to_local_tz(utc_dt)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py35,py36,py37,py38,py39,py310,py311
envlist = py37,py38,py39,py310,py311

[testenv]
commands =
Expand Down

0 comments on commit 2d2523e

Please sign in to comment.