Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: toPython helpers for QDate and QTime #361

Merged
merged 4 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
from PyQt5.QtCore import QT_VERSION_STR as __version__

# For issue #153 and updated for issue #305
from PyQt5.QtCore import QDateTime
from PyQt5.QtCore import QDate, QDateTime, QTime
QDate.toPython = lambda self, *args, **kwargs: self.toPyDate(*args, **kwargs)
QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs)
QTime.toPython = lambda self, *args, **kwargs: self.toPyTime(*args, **kwargs)

# Map missing methods on PyQt5 5.12
QTextStreamManipulator.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
Expand All @@ -39,8 +41,10 @@
from PyQt6.QtCore import QT_VERSION_STR as __version__

# For issue #153 and updated for issue #305
from PyQt6.QtCore import QDateTime
from PyQt6.QtCore import QDate, QDateTime, QTime
QDate.toPython = lambda self, *args, **kwargs: self.toPyDate(*args, **kwargs)
QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs)
QTime.toPython = lambda self, *args, **kwargs: self.toPyTime(*args, **kwargs)

# For issue #311
# Seems like there is an error with sip. Without first
Expand Down
18 changes: 17 additions & 1 deletion qtpy/tests/test_qtcore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test QtCore."""

from datetime import datetime
from datetime import date, datetime, time
import sys

import pytest
Expand Down Expand Up @@ -30,6 +30,22 @@ def test_qdatetime_toPython():
assert isinstance(py_date, datetime)


def test_qdate_toPython():
"""Test QDate.toPython"""
q_date = QtCore.QDate.currentDate()
assert QtCore.QDate.toPython is not None
py_date = q_date.toPython()
assert isinstance(py_date, date)


def test_qtime_toPython():
"""Test QTime.toPython"""
q_time = QtCore.QTime.currentTime()
assert QtCore.QTime.toPython is not None
py_time = q_time.toPython()
assert isinstance(py_time, time)


@pytest.mark.skipif(
sys.platform.startswith('linux') and not_using_conda(),
reason="Fatal Python error: Aborted on Linux CI when not using conda")
Expand Down