diff --git a/.isort.cfg b/.isort.cfg index 352064e4..aa9496b0 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -4,5 +4,5 @@ include_trailing_comma=True force_grid_wrap=0 use_parentheses=True line_length=88 -known_third_party=deprecated,httpretty,jwt,nacl,pytest,requests,setuptools,urllib3 +known_third_party=dateutil,deprecated,httpretty,jwt,nacl,pytest,requests,setuptools,urllib3 known_first_party=github diff --git a/github/Auth.py b/github/Auth.py index d18b4c20..dc73667e 100644 --- a/github/Auth.py +++ b/github/Auth.py @@ -307,8 +307,7 @@ class AppInstallationAuth(Auth, WithRequester["AppInstallationAuth"]): self.__installation_authorization.expires_at - TOKEN_REFRESH_THRESHOLD_TIMEDELTA ) - # to be fixed by https://github.com/PyGithub/PyGithub/pull/1831 - return token_expires_at < datetime.now(timezone.utc).replace(tzinfo=None) + return token_expires_at < datetime.now(timezone.utc) def _get_installation_authorization(self) -> InstallationAuthorization: assert ( diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 0639fed7..4625c2f6 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -39,8 +39,8 @@ # # ################################################################################ -import datetime from collections import namedtuple +from datetime import datetime, timezone import github.Authorization import github.Event @@ -114,7 +114,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -354,7 +354,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -855,12 +855,10 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): def get_gists(self, since=github.GithubObject.NotSet): """ :calls: `GET /gists `_ - :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ + :param since: datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -885,7 +883,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param labels: list of :class:`github.Label.Label` :param sort: string :param direction: string - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter @@ -897,9 +895,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -934,7 +930,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param labels: list of :class:`github.Label.Label` :param sort: string :param direction: string - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter @@ -946,9 +942,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -1010,8 +1004,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :calls: `GET /notifications `_ :param all: bool :param participating: bool - :param since: datetime.datetime - :param before: datetime.datetime + :param since: datetime + :param before: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` """ @@ -1019,11 +1013,9 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): assert participating is github.GithubObject.NotSet or isinstance( participating, bool ), participating - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since assert before is github.GithubObject.NotSet or isinstance( - before, datetime.datetime + before, datetime ), before params = dict() @@ -1229,14 +1221,12 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): ) return status == 200 - def mark_notifications_as_read( - self, last_read_at=datetime.datetime.now(datetime.timezone.utc) - ): + def mark_notifications_as_read(self, last_read_at=datetime.now(timezone.utc)): """ :calls: `PUT /notifications `_ :param last_read_at: datetime """ - assert isinstance(last_read_at, datetime.datetime) + assert isinstance(last_read_at, datetime) put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} headers, data = self._requester.requestJsonAndCheck( diff --git a/github/CheckRun.py b/github/CheckRun.py index dfe16f6a..0091f293 100644 --- a/github/CheckRun.py +++ b/github/CheckRun.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime import github.CheckRunAnnotation import github.CheckRunOutput @@ -60,7 +60,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject): @property def completed_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._completed_at) return self._completed_at.value @@ -148,7 +148,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject): @property def started_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._started_at) return self._started_at.value @@ -202,9 +202,9 @@ class CheckRun(github.GithubObject.CompletableGithubObject): :param details_url: string :param external_id: string :param status: string - :param started_at: datetime.datetime + :param started_at: datetime :param conclusion: string - :param completed_at: datetime.datetime + :param completed_at: datetime :param output: dict :param actions: list of dict :rtype: None @@ -221,13 +221,13 @@ class CheckRun(github.GithubObject.CompletableGithubObject): ), external_id assert status is github.GithubObject.NotSet or isinstance(status, str), status assert started_at is github.GithubObject.NotSet or isinstance( - started_at, datetime.datetime + started_at, datetime ), started_at assert conclusion is github.GithubObject.NotSet or isinstance( conclusion, str ), conclusion assert completed_at is github.GithubObject.NotSet or isinstance( - completed_at, datetime.datetime + completed_at, datetime ), completed_at assert output is github.GithubObject.NotSet or isinstance(output, dict), output assert actions is github.GithubObject.NotSet or all( diff --git a/github/Environment.py b/github/Environment.py index fb8a2730..0c4dbb00 100644 --- a/github/Environment.py +++ b/github/Environment.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime from typing import List import github.EnvironmentDeploymentBranchPolicy @@ -37,7 +37,7 @@ class Environment(github.GithubObject.CompletableGithubObject): return self.get__repr__({"name": self._name.value}) @property - def created_at(self) -> datetime.datetime: + def created_at(self) -> datetime: self._completeIfNotSet(self._created_at) return self._created_at.value @@ -69,7 +69,7 @@ class Environment(github.GithubObject.CompletableGithubObject): return self._protection_rules.value @property - def updated_at(self) -> datetime.datetime: + def updated_at(self) -> datetime: self._completeIfNotSet(self._updated_at) return self._updated_at.value diff --git a/github/GithubObject.py b/github/GithubObject.py index 21fa736a..54199469 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -38,8 +38,8 @@ # # ################################################################################ -import datetime import typing +from datetime import datetime, timezone from operator import itemgetter from typing import ( TYPE_CHECKING, @@ -53,6 +53,8 @@ from typing import ( Union, ) +from dateutil import parser + from . import Consts from .GithubException import BadAttributeException, IncompletableObject @@ -225,28 +227,14 @@ class GithubObject: @staticmethod def _makeTimestampAttribute(value: int) -> Attribute[int]: return GithubObject.__makeTransformedAttribute( - value, int, datetime.datetime.utcfromtimestamp + value, + int, + lambda t: datetime.fromtimestamp(t, tz=timezone.utc), ) @staticmethod def _makeDatetimeAttribute(value: Optional[Union[int, str]]) -> Attribute: - def parseDatetime(s): - if ( - len(s) == 24 - ): # pragma no branch (This branch was used only when creating a download) - # The Downloads API has been removed. I'm keeping this branch because I have no mean - # to check if it's really useless now. - return datetime.datetime.strptime( - s, "%Y-%m-%dT%H:%M:%S.000Z" - ) # pragma no cover (This branch was used only when creating a download) - elif len(s) >= 25: - return datetime.datetime.strptime(s[:19], "%Y-%m-%dT%H:%M:%S") + ( - 1 if s[19] == "-" else -1 - ) * datetime.timedelta(hours=int(s[20:22]), minutes=int(s[23:25])) - else: - return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ") - - return GithubObject.__makeTransformedAttribute(value, str, parseDatetime) + return GithubObject.__makeTransformedAttribute(value, str, parser.parse) def _makeClassAttribute(self, klass: Any, value: Any) -> Attribute: return GithubObject.__makeTransformedAttribute( diff --git a/github/Issue.py b/github/Issue.py index 26ff556b..b5bacdbc 100644 --- a/github/Issue.py +++ b/github/Issue.py @@ -42,8 +42,8 @@ # # ################################################################################ -import datetime import urllib.parse +from datetime import datetime import github.GithubObject import github.IssueComment @@ -97,7 +97,7 @@ class Issue(github.GithubObject.CompletableGithubObject): @property def closed_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._closed_at) return self._closed_at.value @@ -129,7 +129,7 @@ class Issue(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -241,7 +241,7 @@ class Issue(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -472,12 +472,10 @@ class Issue(github.GithubObject.CompletableGithubObject): def get_comments(self, since=github.GithubObject.NotSet): """ :calls: `GET /repos/{owner}/{repo}/issues/{number}/comments `_ - :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ + :param since: datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` """ - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") diff --git a/github/MainClass.py b/github/MainClass.py index 26fbbc86..ab5d143b 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -47,9 +47,9 @@ # # ################################################################################ -import datetime import pickle import warnings +from datetime import datetime from typing import List import urllib3 @@ -440,12 +440,10 @@ class Github: def get_gists(self, since=github.GithubObject.NotSet): """ :calls: `GET /gists/public `_ - :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ + :param since: datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") diff --git a/github/Milestone.py b/github/Milestone.py index cb8d6140..ae5cdaae 100644 --- a/github/Milestone.py +++ b/github/Milestone.py @@ -28,7 +28,7 @@ # # ################################################################################ -import datetime +from datetime import date import github.GithubObject import github.Label @@ -57,7 +57,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -81,7 +81,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): @property def due_on(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._due_on) return self._due_on.value @@ -137,7 +137,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -177,9 +177,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): assert description is github.GithubObject.NotSet or isinstance( description, str ), description - assert due_on is github.GithubObject.NotSet or isinstance( - due_on, datetime.date - ), due_on + assert due_on is github.GithubObject.NotSet or isinstance(due_on, date), due_on post_parameters = { "title": title, } diff --git a/github/NamedUser.py b/github/NamedUser.py index df5dc5ba..86d8bd11 100644 --- a/github/NamedUser.py +++ b/github/NamedUser.py @@ -35,7 +35,7 @@ # # ################################################################################ -import datetime +from datetime import datetime import github.Event import github.Gist @@ -135,7 +135,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -383,7 +383,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): @property def suspended_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._suspended_at) return self._suspended_at.value @@ -415,7 +415,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -458,12 +458,10 @@ class NamedUser(github.GithubObject.CompletableGithubObject): def get_gists(self, since=github.GithubObject.NotSet): """ :calls: `GET /users/{user}/gists `_ - :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ + :param since: datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") diff --git a/github/Organization.py b/github/Organization.py index 2d843386..d4e5aa10 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -39,7 +39,7 @@ # # ################################################################################ -import datetime +from datetime import datetime import github.Event import github.GithubObject @@ -104,7 +104,7 @@ class Organization(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -344,7 +344,7 @@ class Organization(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -928,7 +928,7 @@ class Organization(github.GithubObject.CompletableGithubObject): :param labels: list of :class:`github.Label.Label` :param sort: string :param direction: string - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter @@ -940,9 +940,7 @@ class Organization(github.GithubObject.CompletableGithubObject): assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter diff --git a/github/PullRequest.py b/github/PullRequest.py index d30e2272..db968ef3 100644 --- a/github/PullRequest.py +++ b/github/PullRequest.py @@ -40,8 +40,8 @@ # # ################################################################################ -import datetime import urllib.parse +from datetime import datetime import github.Commit import github.File @@ -119,7 +119,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): @property def closed_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._closed_at) return self._closed_at.value @@ -159,7 +159,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -263,7 +263,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): @property def merged_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._merged_at) return self._merged_at.value @@ -351,7 +351,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -685,7 +685,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/pulls/{number}/comments `_ :param sort: string 'created' or 'updated' :param direction: string 'asc' or 'desc' - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` """ return self.get_review_comments(sort=sort, direction=direction, since=since) @@ -702,16 +702,14 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/pulls/{number}/comments `_ :param sort: string 'created' or 'updated' :param direction: string 'asc' or 'desc' - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` """ assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if sort is not github.GithubObject.NotSet: url_parameters["sort"] = sort diff --git a/github/Repository.py b/github/Repository.py index 5bf14d10..1710bb45 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -124,10 +124,10 @@ ################################################################################ import collections -import datetime import typing import urllib.parse from base64 import b64encode +from datetime import date, datetime, timezone from deprecated import deprecated @@ -351,7 +351,7 @@ class Repository(github.GithubObject.CompletableGithubObject): @property def created_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._created_at) return self._created_at.value @@ -735,7 +735,7 @@ class Repository(github.GithubObject.CompletableGithubObject): @property def pushed_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._pushed_at) return self._pushed_at.value @@ -865,7 +865,7 @@ class Repository(github.GithubObject.CompletableGithubObject): @property def updated_at(self): """ - :type: datetime.datetime + :type: datetime """ self._completeIfNotSet(self._updated_at) return self._updated_at.value @@ -1412,7 +1412,7 @@ class Repository(github.GithubObject.CompletableGithubObject): description, str ), description assert due_on is github.GithubObject.NotSet or isinstance( - due_on, (datetime.datetime, datetime.date) + due_on, (datetime, date) ), due_on post_parameters = { "title": title, @@ -1422,7 +1422,7 @@ class Repository(github.GithubObject.CompletableGithubObject): if description is not github.GithubObject.NotSet: post_parameters["description"] = description if due_on is not github.GithubObject.NotSet: - if isinstance(due_on, datetime.date): + if isinstance(due_on, date): post_parameters["due_on"] = due_on.strftime("%Y-%m-%dT%H:%M:%SZ") else: post_parameters["due_on"] = due_on.isoformat() @@ -2044,19 +2044,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/commits `_ :param sha: string :param path: string - :param since: datetime.datetime - :param until: datetime.datetime + :param since: datetime + :param until: datetime :param author: string or :class:`github.NamedUser.NamedUser` or :class:`github.AuthenticatedUser.AuthenticatedUser` :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit` """ assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha assert path is github.GithubObject.NotSet or isinstance(path, str), path - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert until is github.GithubObject.NotSet or isinstance( - until, datetime.datetime - ), until + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since + assert until is github.GithubObject.NotSet or isinstance(until, datetime), until assert author is github.GithubObject.NotSet or isinstance( author, ( @@ -2868,7 +2864,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :param labels: list of string or :class:`github.Label.Label` :param sort: string :param direction: string - :param since: datetime.datetime + :param since: datetime :param creator: string or :class:`github.NamedUser.NamedUser` :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ @@ -2895,9 +2891,7 @@ class Repository(github.GithubObject.CompletableGithubObject): assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since assert ( creator is github.GithubObject.NotSet or isinstance(creator, github.NamedUser.NamedUser) @@ -2950,16 +2944,14 @@ class Repository(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/issues/comments `_ :param sort: string :param direction: string - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` """ assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if sort is not github.GithubObject.NotSet: url_parameters["sort"] = sort @@ -3209,7 +3201,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/pulls/comments `_ :param sort: string :param direction: string - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` """ return self.get_pulls_review_comments(sort, direction, since) @@ -3224,16 +3216,14 @@ class Repository(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/pulls/comments `_ :param sort: string 'created', 'updated', 'created_at' :param direction: string 'asc' or 'desc' - :param since: datetime.datetime + :param since: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` """ assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort assert direction is github.GithubObject.NotSet or isinstance( direction, str ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since url_parameters = dict() if sort is not github.GithubObject.NotSet: url_parameters["sort"] = sort @@ -3705,8 +3695,8 @@ class Repository(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/{owner}/{repo}/notifications `_ :param all: bool :param participating: bool - :param since: datetime.datetime - :param before: datetime.datetime + :param since: datetime + :param before: datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` """ @@ -3714,11 +3704,9 @@ class Repository(github.GithubObject.CompletableGithubObject): assert participating is github.GithubObject.NotSet or isinstance( participating, bool ), participating - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime), since assert before is github.GithubObject.NotSet or isinstance( - before, datetime.datetime + before, datetime ), before params = dict() @@ -3738,14 +3726,12 @@ class Repository(github.GithubObject.CompletableGithubObject): params, ) - def mark_notifications_as_read( - self, last_read_at=datetime.datetime.now(datetime.timezone.utc) - ): + def mark_notifications_as_read(self, last_read_at=datetime.now(timezone.utc)): """ :calls: `PUT /repos/{owner}/{repo}/notifications `_ :param last_read_at: datetime """ - assert isinstance(last_read_at, datetime.datetime) + assert isinstance(last_read_at, datetime) put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} headers, data = self._requester.requestJsonAndCheck( @@ -4026,9 +4012,9 @@ class Repository(github.GithubObject.CompletableGithubObject): :param details_url: string :param external_id: string :param status: string - :param started_at: datetime.datetime + :param started_at: datetime :param conclusion: string - :param completed_at: datetime.datetime + :param completed_at: datetime :param output: dict :param actions: list of dict :rtype: :class:`github.CheckRun.CheckRun` @@ -4043,13 +4029,13 @@ class Repository(github.GithubObject.CompletableGithubObject): ), external_id assert status is github.GithubObject.NotSet or isinstance(status, str), status assert started_at is github.GithubObject.NotSet or isinstance( - started_at, datetime.datetime + started_at, datetime ), started_at assert conclusion is github.GithubObject.NotSet or isinstance( conclusion, str ), conclusion assert completed_at is github.GithubObject.NotSet or isinstance( - completed_at, datetime.datetime + completed_at, datetime ), completed_at assert output is github.GithubObject.NotSet or isinstance(output, dict), output assert actions is github.GithubObject.NotSet or all( diff --git a/github/RepositoryAdvisory.py b/github/RepositoryAdvisory.py index 459ff493..9de08e7f 100644 --- a/github/RepositoryAdvisory.py +++ b/github/RepositoryAdvisory.py @@ -20,8 +20,8 @@ # # ################################################################################ -import datetime import typing +from datetime import datetime import github.GithubObject import github.NamedUser @@ -54,16 +54,16 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject): return self._author.value @property - def closed_at(self) -> datetime.datetime: + def closed_at(self) -> datetime: """ - :type: datetime.datetime + :type: datetime """ return self._closed_at.value @property - def created_at(self) -> datetime.datetime: + def created_at(self) -> datetime: """ - :type: datetime.datetime + :type: datetime """ return self._created_at.value @@ -128,9 +128,9 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject): return self._html_url.value @property - def published_at(self) -> datetime.datetime: + def published_at(self) -> datetime: """ - :type: datetime.datetime + :type: datetime """ return self._published_at.value @@ -156,9 +156,9 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject): return self._summary.value @property - def updated_at(self) -> datetime.datetime: + def updated_at(self) -> datetime: """ - :type: datetime.datetime + :type: datetime """ return self._updated_at.value @@ -179,9 +179,9 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject): return self._vulnerabilities.value @property - def withdrawn_at(self) -> datetime.datetime: + def withdrawn_at(self) -> datetime: """ - :type: datetime.datetime + :type: datetime """ return self._withdrawn_at.value diff --git a/github/Topic.pyi b/github/Topic.pyi index f8a35a56..b77fb068 100644 --- a/github/Topic.pyi +++ b/github/Topic.pyi @@ -1,4 +1,4 @@ -import datetime +from datetime import datetime from typing import Any, Dict @@ -21,9 +21,9 @@ class Topic(NonCompletableGithubObject): @property def released(self) -> str: ... @property - def created_at(self) -> datetime.datetime: ... + def created_at(self) -> datetime: ... @property - def updated_at(self) -> datetime.datetime: ... + def updated_at(self) -> datetime: ... @property def featured(self) -> bool: ... @property diff --git a/requirements-types.txt b/requirements-types.txt index be0ced3e..39a80e21 100644 --- a/requirements-types.txt +++ b/requirements-types.txt @@ -1,4 +1,5 @@ mypy types-deprecated types-jwt +types-python-dateutil types-requests diff --git a/requirements.txt b/requirements.txt index d8e40426..ccffb419 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pynacl>=1.4.0 +python-dateutil requests>=2.14.0 pyjwt[crypto]>=2.4.0 urllib3 diff --git a/setup.py b/setup.py index 36e36826..137401f6 100755 --- a/setup.py +++ b/setup.py @@ -115,6 +115,7 @@ if __name__ == "__main__": "pyjwt[crypto]>=2.4.0", "pynacl>=1.4.0", "requests>=2.14.0", + "python-dateutil", ], # can be removed, still here to avoid breaking user code extras_require={"integrations": []}, diff --git a/tests/ApplicationOAuth.py b/tests/ApplicationOAuth.py index 2102a9ae..b0e7c414 100644 --- a/tests/ApplicationOAuth.py +++ b/tests/ApplicationOAuth.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from unittest import mock import github @@ -84,9 +84,7 @@ class ApplicationOAuth(Framework.TestCase): def testGetAccessTokenWithExpiry(self): with mock.patch("github.AccessToken.datetime") as dt: dt.now = mock.Mock( - return_value=datetime.datetime( - 2023, 6, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc) ) access_token = self.app.get_access_token( "oauth_code_removed", state="state_removed" @@ -103,13 +101,13 @@ class ApplicationOAuth(Framework.TestCase): self.assertEqual(access_token.expires_in, 28800) self.assertEqual( access_token.expires_at, - datetime.datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(access_token.refresh_token, "refresh_token_removed") self.assertEqual(access_token.refresh_expires_in, 15811200) self.assertEqual( access_token.refresh_expires_at, - datetime.datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) def testRefreshAccessToken(self): @@ -119,9 +117,7 @@ class ApplicationOAuth(Framework.TestCase): with mock.patch("github.AccessToken.datetime") as dt: dt.now = mock.Mock( - return_value=datetime.datetime( - 2023, 6, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc) ) refreshed = self.app.refresh_access_token(access_token.refresh_token) @@ -139,18 +135,18 @@ class ApplicationOAuth(Framework.TestCase): self.assertEqual(refreshed.scope, "") self.assertEqual( refreshed.created, - datetime.datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(refreshed.expires_in, 28800) self.assertEqual( refreshed.expires_at, - datetime.datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(refreshed.refresh_token, "another_refresh_token_removed") self.assertEqual(refreshed.refresh_expires_in, 15811200) self.assertEqual( refreshed.refresh_expires_at, - datetime.datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) def testGetAccessTokenBadCode(self): diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index ca0b999f..6da03f24 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -30,7 +30,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone import github @@ -51,7 +51,10 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(self.user.blog, "http://vincent-jacques.net") self.assertEqual(self.user.collaborators, 0) self.assertEqual(self.user.company, "Criteo") - self.assertEqual(self.user.created_at, datetime.datetime(2010, 7, 9, 6, 10, 6)) + self.assertEqual( + self.user.created_at, + datetime(2010, 7, 9, 6, 10, 6, tzinfo=timezone.utc), + ) self.assertEqual(self.user.disk_usage, 16692) self.assertEqual(self.user.email, "vincent@vincent-jacques.net") self.assertEqual(self.user.followers, 13) @@ -431,7 +434,7 @@ class AuthenticatedUser(Framework.TestCase): ], ) self.assertListKeyEqual( - self.user.get_gists(since=datetime.datetime(2012, 3, 1, 23, 0, 0)), + self.user.get_gists(since=datetime(2012, 3, 1, 23, 0, 0)), lambda g: g.id, ["2793505", "2793179", "11cb445f8197e17d303d"], ) @@ -474,7 +477,7 @@ class AuthenticatedUser(Framework.TestCase): [requestedByUser], "comments", "asc", - datetime.datetime(2012, 5, 28, 23, 0, 0), + datetime(2012, 5, 28, 23, 0, 0), ) self.assertListKeyEqual( issues, @@ -552,7 +555,7 @@ class AuthenticatedUser(Framework.TestCase): [requestedByUser], "comments", "asc", - datetime.datetime(2012, 5, 28, 23, 0, 0), + datetime(2012, 5, 28, 23, 0, 0), ) self.assertListKeyEqual( issues, @@ -699,7 +702,8 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(notification.subject.type, "PullRequest") self.assertEqual(notification.repository.id, 8432784) self.assertEqual( - notification.updated_at, datetime.datetime(2013, 3, 15, 5, 43, 11) + notification.updated_at, + datetime(2013, 3, 15, 5, 43, 11, tzinfo=timezone.utc), ) self.assertEqual(notification.url, None) self.assertEqual(notification.subject.url, None) @@ -723,9 +727,7 @@ class AuthenticatedUser(Framework.TestCase): ) def testMarkNotificationsAsRead(self): - self.user.mark_notifications_as_read( - datetime.datetime(2018, 10, 18, 18, 20, 0o1, 0) - ) + self.user.mark_notifications_as_read(datetime(2018, 10, 18, 18, 20, 0o1, 0)) def testGetTeams(self): self.assertListKeyEqual( @@ -753,7 +755,7 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(repr(invitation), "Invitation(id=17285388)") self.assertEqual(invitation.id, 17285388) self.assertEqual(invitation.permissions, "write") - created_at = datetime.datetime(2019, 6, 27, 11, 47) + created_at = datetime(2019, 6, 27, 11, 47, tzinfo=timezone.utc) self.assertEqual(invitation.created_at, created_at) self.assertEqual( invitation.url, diff --git a/tests/Authentication.py b/tests/Authentication.py index 9f9e7e0b..97c343aa 100644 --- a/tests/Authentication.py +++ b/tests/Authentication.py @@ -25,7 +25,8 @@ # along with PyGithub. If not, see . # # # ################################################################################ -import datetime + +from datetime import datetime, timezone from unittest import mock import jwt @@ -110,24 +111,20 @@ class Authentication(Framework.BasicTestCase): self.assertFalse(installation_auth._is_expired) self.assertEqual( installation_auth._AppInstallationAuth__installation_authorization.expires_at, - datetime.datetime(2024, 11, 25, 1, 0, 2), + datetime(2024, 11, 25, 1, 0, 2, tzinfo=timezone.utc), ) # forward the clock so token expires with mock.patch("github.Auth.datetime") as dt: # just before expiry dt.now = mock.Mock( - return_value=datetime.datetime( - 2024, 11, 25, 0, 59, 3, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2024, 11, 25, 0, 59, 3, tzinfo=timezone.utc) ) self.assertFalse(installation_auth._is_expired) # just after expiry dt.now = mock.Mock( - return_value=datetime.datetime( - 2024, 11, 25, 1, 0, 3, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2024, 11, 25, 1, 0, 3, tzinfo=timezone.utc) ) self.assertTrue(installation_auth._is_expired) @@ -137,7 +134,7 @@ class Authentication(Framework.BasicTestCase): self.assertFalse(installation_auth._is_expired) self.assertEqual( installation_auth._AppInstallationAuth__installation_authorization.expires_at, - datetime.datetime(2025, 11, 25, 1, 0, 2), + datetime(2025, 11, 25, 1, 0, 2, tzinfo=timezone.utc), ) # use the token @@ -153,9 +150,7 @@ class Authentication(Framework.BasicTestCase): app = g.get_oauth_application(client_id, client_secret) with mock.patch("github.AccessToken.datetime") as dt: dt.now = mock.Mock( - return_value=datetime.datetime( - 2023, 6, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc) ) token = app.refresh_access_token(refresh_token) self.assertEqual(token.token, "fresh access token") @@ -164,21 +159,19 @@ class Authentication(Framework.BasicTestCase): self.assertEqual(token.expires_in, 28800) self.assertEqual( token.expires_at, - datetime.datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(token.refresh_token, "fresh refresh token") self.assertEqual(token.refresh_expires_in, 15811200) self.assertEqual( token.refresh_expires_at, - datetime.datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=datetime.timezone.utc), + datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) auth = app.get_app_user_auth(token) with mock.patch("github.Auth.datetime") as dt: dt.now = mock.Mock( - return_value=datetime.datetime( - 2023, 6, 7, 20, 0, 0, 123, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc) ) self.assertEqual(auth._is_expired, False) self.assertEqual(auth.token, "fresh access token") @@ -188,9 +181,7 @@ class Authentication(Framework.BasicTestCase): # expire auth token with mock.patch("github.Auth.datetime") as dt: dt.now = mock.Mock( - return_value=datetime.datetime( - 2023, 6, 7, 20, 0, 1, 123, tzinfo=datetime.timezone.utc - ) + return_value=datetime(2023, 6, 7, 20, 0, 1, 123, tzinfo=timezone.utc) ) self.assertEqual(auth._is_expired, True) self.assertEqual(auth.token, "another access token") diff --git a/tests/Authorization.py b/tests/Authorization.py index 2e05cb7d..7f3adda5 100644 --- a/tests/Authorization.py +++ b/tests/Authorization.py @@ -25,7 +25,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -42,7 +42,8 @@ class Authorization(Framework.TestCase): ) self.assertEqual(self.authorization.app.name, "GitHub API") self.assertEqual( - self.authorization.created_at, datetime.datetime(2012, 5, 22, 18, 3, 17) + self.authorization.created_at, + datetime(2012, 5, 22, 18, 3, 17, tzinfo=timezone.utc), ) self.assertEqual(self.authorization.id, 372259) self.assertEqual(self.authorization.note, None) @@ -52,7 +53,8 @@ class Authorization(Framework.TestCase): self.authorization.token, "82459c4500086f8f0cc67d2936c17d1e27ad1c33" ) self.assertEqual( - self.authorization.updated_at, datetime.datetime(2012, 5, 22, 18, 3, 17) + self.authorization.updated_at, + datetime(2012, 5, 22, 18, 3, 17, tzinfo=timezone.utc), ) self.assertEqual( self.authorization.url, "https://api.github.com/authorizations/372259" diff --git a/tests/BadAttributes.py b/tests/BadAttributes.py index 4aba0284..fd101b0b 100755 --- a/tests/BadAttributes.py +++ b/tests/BadAttributes.py @@ -24,7 +24,9 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone + +from dateutil.parser import ParserError import github @@ -35,7 +37,10 @@ from . import Framework class BadAttributes(Framework.TestCase): def testBadSimpleAttribute(self): user = self.g.get_user("klmitch") - self.assertEqual(user.created_at, datetime.datetime(2011, 3, 23, 15, 42, 9)) + self.assertEqual( + user.created_at, + datetime(2011, 3, 23, 15, 42, 9, tzinfo=timezone.utc), + ) with self.assertRaises(github.BadAttributeException) as raisedexp: user.name @@ -52,11 +57,11 @@ class BadAttributes(Framework.TestCase): self.assertEqual(raisedexp.exception.actual_value, "foobar") self.assertEqual(raisedexp.exception.expected_type, str) self.assertEqual( - raisedexp.exception.transformation_exception.__class__, ValueError + raisedexp.exception.transformation_exception.__class__, ParserError ) self.assertEqual( raisedexp.exception.transformation_exception.args, - ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",), + ("Unknown string format: %s", "foobar"), ) def testBadTransformedAttribute(self): diff --git a/tests/CheckRun.py b/tests/CheckRun.py index 818371b5..ab86f333 100644 --- a/tests/CheckRun.py +++ b/tests/CheckRun.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -40,7 +40,8 @@ class CheckRun(Framework.TestCase): self.assertEqual(self.check_run.app.slug, "github-actions") self.assertEqual(self.check_run.check_suite_id, 1110219217) self.assertEqual( - self.check_run.completed_at, datetime.datetime(2020, 8, 28, 4, 21, 21) + self.check_run.completed_at, + datetime(2020, 8, 28, 4, 21, 21, tzinfo=timezone.utc), ) self.assertEqual(self.check_run.conclusion, "success") self.assertEqual( @@ -63,7 +64,8 @@ class CheckRun(Framework.TestCase): self.assertEqual(self.check_run.output.annotations_count, 0) self.assertEqual(len(self.check_run.pull_requests), 0) self.assertEqual( - self.check_run.started_at, datetime.datetime(2020, 8, 28, 4, 20, 27) + self.check_run.started_at, + datetime(2020, 8, 28, 4, 20, 27, tzinfo=timezone.utc), ) self.assertEqual(self.check_run.status, "completed") self.assertEqual( @@ -137,14 +139,17 @@ class CheckRun(Framework.TestCase): status="in_progress", external_id="50", details_url="https://www.example.com", - started_at=datetime.datetime(2020, 9, 4, 1, 14, 52), + started_at=datetime(2020, 9, 4, 1, 14, 52), output={"title": "PyGithub Check Run Test", "summary": "Test summary"}, ) self.assertEqual(check_run.name, "basic_check_run") self.assertEqual(check_run.head_sha, "0283d46537193f1fed7d46859f15c5304b9836f9") self.assertEqual(check_run.status, "in_progress") self.assertEqual(check_run.external_id, "50") - self.assertEqual(check_run.started_at, datetime.datetime(2020, 9, 4, 1, 14, 52)) + self.assertEqual( + check_run.started_at, + datetime(2020, 9, 4, 1, 14, 52, tzinfo=timezone.utc), + ) self.assertEqual(check_run.output.title, "PyGithub Check Run Test") self.assertEqual(check_run.output.summary, "Test summary") self.assertIsNone(check_run.output.text) @@ -159,9 +164,9 @@ class CheckRun(Framework.TestCase): name="completed_check_run", head_sha="0283d46537193f1fed7d46859f15c5304b9836f9", status="completed", - started_at=datetime.datetime(2020, 10, 20, 10, 30, 29), + started_at=datetime(2020, 10, 20, 10, 30, 29), conclusion="success", - completed_at=datetime.datetime(2020, 10, 20, 11, 30, 50), + completed_at=datetime(2020, 10, 20, 11, 30, 50), output={ "title": "Readme report", "summary": "There are 0 failures, 2 warnings, and 1 notices.", @@ -205,11 +210,13 @@ class CheckRun(Framework.TestCase): self.assertEqual(check_run.head_sha, "0283d46537193f1fed7d46859f15c5304b9836f9") self.assertEqual(check_run.status, "completed") self.assertEqual( - check_run.started_at, datetime.datetime(2020, 10, 20, 10, 30, 29) + check_run.started_at, + datetime(2020, 10, 20, 10, 30, 29, tzinfo=timezone.utc), ), self.assertEqual(check_run.conclusion, "success") self.assertEqual( - check_run.completed_at, datetime.datetime(2020, 10, 20, 11, 30, 50) + check_run.completed_at, + datetime(2020, 10, 20, 11, 30, 50, tzinfo=timezone.utc), ), self.assertEqual(check_run.output.annotations_count, 2) @@ -220,7 +227,7 @@ class CheckRun(Framework.TestCase): head_sha="0283d46537193f1fed7d46859f15c5304b9836f9", status="in_progress", external_id="100", - started_at=datetime.datetime(2020, 10, 20, 14, 24, 31), + started_at=datetime(2020, 10, 20, 14, 24, 31), output={"title": "Check run for testing edit method", "summary": ""}, ) self.assertEqual(check_run.name, "edit_check_run") @@ -250,7 +257,7 @@ class CheckRun(Framework.TestCase): head_sha="0283d46537193f1fed7d46859f15c5304b9836f9", status="in_progress", external_id="101", - started_at=datetime.datetime(2020, 10, 20, 10, 14, 51), + started_at=datetime(2020, 10, 20, 10, 14, 51), output={"title": "Check run for testing failure", "summary": ""}, ) self.assertEqual(check_run.name, "fail_check_run") @@ -294,8 +301,8 @@ class CheckRun(Framework.TestCase): head_sha="0283d46537193f1fed7d46859f15c5304b9836f9", details_url="https://www.example-url.com", external_id="49", - started_at=datetime.datetime(2020, 10, 20, 1, 10, 20), - completed_at=datetime.datetime(2020, 10, 20, 2, 20, 30), + started_at=datetime(2020, 10, 20, 1, 10, 20), + completed_at=datetime(2020, 10, 20, 2, 20, 30), actions=[ { "label": "Hello World!", @@ -309,10 +316,12 @@ class CheckRun(Framework.TestCase): self.assertEqual(check_run.details_url, "https://www.example-url.com") self.assertEqual(check_run.external_id, "49") self.assertEqual( - check_run.started_at, datetime.datetime(2020, 10, 20, 1, 10, 20) + check_run.started_at, + datetime(2020, 10, 20, 1, 10, 20, tzinfo=timezone.utc), ) self.assertEqual( - check_run.completed_at, datetime.datetime(2020, 10, 20, 2, 20, 30) + check_run.completed_at, + datetime(2020, 10, 20, 2, 20, 30, tzinfo=timezone.utc), ) def testCheckRunAnnotationAttributes(self): diff --git a/tests/CheckSuite.py b/tests/CheckSuite.py index 9dafaeb6..4d7512b2 100644 --- a/tests/CheckSuite.py +++ b/tests/CheckSuite.py @@ -21,7 +21,7 @@ # # ################################################################################ -from datetime import datetime +from datetime import datetime, timezone from . import Framework @@ -48,7 +48,9 @@ class CheckSuite(Framework.TestCase): "https://api.github.com/repos/wrecker/PySample/check-suites/1004503837/check-runs", ) self.assertEqual(cs.conclusion, "success") - self.assertEqual(cs.created_at, datetime(2020, 8, 4, 5, 6, 54)) + self.assertEqual( + cs.created_at, datetime(2020, 8, 4, 5, 6, 54, tzinfo=timezone.utc) + ) self.assertEqual(cs.head_branch, "wrecker-patch-1") self.assertEqual(cs.head_commit.sha, "fd09d934bcce792176d6b79d6d0387e938b62b7a") self.assertEqual(cs.head_sha, "fd09d934bcce792176d6b79d6d0387e938b62b7a") @@ -61,7 +63,9 @@ class CheckSuite(Framework.TestCase): cs.repository.url, "https://api.github.com/repos/wrecker/PySample" ) self.assertEqual(cs.status, "completed") - self.assertEqual(cs.updated_at, datetime(2020, 8, 4, 5, 7, 40)) + self.assertEqual( + cs.updated_at, datetime(2020, 8, 4, 5, 7, 40, tzinfo=timezone.utc) + ) self.assertEqual( cs.url, "https://api.github.com/repos/wrecker/PySample/check-suites/1004503837", diff --git a/tests/CommitCombinedStatus.py b/tests/CommitCombinedStatus.py index c51588e9..76ce7649 100644 --- a/tests/CommitCombinedStatus.py +++ b/tests/CommitCombinedStatus.py @@ -24,7 +24,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -55,11 +55,11 @@ class CommitCombinedStatus(Framework.TestCase): ) self.assertEqual( self.combined_status.statuses[4].created_at, - datetime.datetime(2015, 12, 14, 13, 24, 18), + datetime(2015, 12, 14, 13, 24, 18, tzinfo=timezone.utc), ) self.assertEqual( self.combined_status.statuses[3].updated_at, - datetime.datetime(2015, 12, 14, 13, 23, 35), + datetime(2015, 12, 14, 13, 23, 35, tzinfo=timezone.utc), ) self.assertEqual( self.combined_status.sha, "74e70119a23fa3ffb3db19d4590eccfebd72b659" diff --git a/tests/CommitComment.py b/tests/CommitComment.py index 8f1a58fb..8a59e2ca 100644 --- a/tests/CommitComment.py +++ b/tests/CommitComment.py @@ -28,7 +28,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -44,7 +44,8 @@ class CommitComment(Framework.TestCase): self.comment.commit_id, "6945921c529be14c3a8f566dd1e483674516d46d" ) self.assertEqual( - self.comment.created_at, datetime.datetime(2012, 5, 22, 18, 40, 18) + self.comment.created_at, + datetime(2012, 5, 22, 18, 40, 18, tzinfo=timezone.utc), ) self.assertEqual( self.comment.html_url, @@ -55,7 +56,8 @@ class CommitComment(Framework.TestCase): self.assertEqual(self.comment.path, None) self.assertEqual(self.comment.position, None) self.assertEqual( - self.comment.updated_at, datetime.datetime(2012, 5, 22, 18, 40, 18) + self.comment.updated_at, + datetime(2012, 5, 22, 18, 40, 18, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, diff --git a/tests/CommitStatus.py b/tests/CommitStatus.py index b94cf424..e0e512a6 100644 --- a/tests/CommitStatus.py +++ b/tests/CommitStatus.py @@ -28,7 +28,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -45,10 +45,12 @@ class CommitStatus(Framework.TestCase): def testAttributes(self): self.assertEqual( - self.statuses[0].created_at, datetime.datetime(2012, 9, 8, 11, 30, 56) + self.statuses[0].created_at, + datetime(2012, 9, 8, 11, 30, 56, tzinfo=timezone.utc), ) self.assertEqual( - self.statuses[0].updated_at, datetime.datetime(2012, 9, 8, 11, 30, 56) + self.statuses[0].updated_at, + datetime(2012, 9, 8, 11, 30, 56, tzinfo=timezone.utc), ) self.assertEqual(self.statuses[0].creator.login, "jacquev6") self.assertEqual( diff --git a/tests/Deployment.py b/tests/Deployment.py index 5ab757e1..95adb555 100644 --- a/tests/Deployment.py +++ b/tests/Deployment.py @@ -21,7 +21,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -51,7 +51,7 @@ class Deployment(Framework.TestCase): self.assertEqual(self.deployment.environment, "test") self.assertEqual(self.deployment.description, "Test deployment") self.assertEqual(self.deployment.creator.login, "jacquev6") - created_at = datetime.datetime(2020, 8, 26, 11, 44, 53) + created_at = datetime(2020, 8, 26, 11, 44, 53, tzinfo=timezone.utc) self.assertEqual(self.deployment.created_at, created_at) self.assertEqual(self.deployment.updated_at, created_at) self.assertEqual(self.deployment.transient_environment, True) diff --git a/tests/DeploymentStatus.py b/tests/DeploymentStatus.py index 0b4a2266..7b01a72c 100644 --- a/tests/DeploymentStatus.py +++ b/tests/DeploymentStatus.py @@ -21,7 +21,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -36,7 +36,7 @@ class DeploymentStatus(Framework.TestCase): def testAttributes(self): self.assertEqual(self.status.id, 388454671) - created_at = datetime.datetime(2020, 8, 26, 14, 32, 51) + created_at = datetime(2020, 8, 26, 14, 32, 51, tzinfo=timezone.utc) self.assertEqual(self.status.created_at, created_at) self.assertEqual(self.status.creator.login, "jacquev6") self.assertEqual( diff --git a/tests/Download.py b/tests/Download.py index d1c3e752..39c81663 100644 --- a/tests/Download.py +++ b/tests/Download.py @@ -26,7 +26,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -42,7 +42,8 @@ class Download(Framework.TestCase): self.assertEqual(self.download.bucket, None) self.assertEqual(self.download.content_type, "text/plain") self.assertEqual( - self.download.created_at, datetime.datetime(2012, 5, 22, 18, 58, 32) + self.download.created_at, + datetime(2012, 5, 22, 18, 58, 32, tzinfo=timezone.utc), ) self.assertEqual(self.download.description, None) self.assertEqual(self.download.download_count, 0) diff --git a/tests/Environment.py b/tests/Environment.py index b540fb51..d80c93a9 100644 --- a/tests/Environment.py +++ b/tests/Environment.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone import pytest # type: ignore @@ -54,10 +54,12 @@ class Environment(Framework.TestCase): "https://github.com/alson/PyGithub/deployments/activity_log?environments_filter=dev", ) self.assertEqual( - self.environment.created_at, datetime.datetime(2022, 4, 13, 15, 6, 32) + self.environment.created_at, + datetime(2022, 4, 13, 15, 6, 32, tzinfo=timezone.utc), ) self.assertEqual( - self.environment.updated_at, datetime.datetime(2022, 4, 13, 15, 6, 32) + self.environment.updated_at, + datetime(2022, 4, 13, 15, 6, 32, tzinfo=timezone.utc), ) self.assertTrue(self.environment.deployment_branch_policy.protected_branches) self.assertFalse( @@ -122,10 +124,12 @@ class Environment(Framework.TestCase): "https://github.com/alson/PyGithub/deployments/activity_log?environments_filter=test", ) self.assertEqual( - environment.created_at, datetime.datetime(2022, 4, 19, 14, 4, 32) + environment.created_at, + datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual( - environment.updated_at, datetime.datetime(2022, 4, 19, 14, 4, 32) + environment.updated_at, + datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual(len(environment.protection_rules), 0) self.assertIsNone(environment.deployment_branch_policy) @@ -155,10 +159,12 @@ class Environment(Framework.TestCase): "https://github.com/alson/PyGithub/deployments/activity_log?environments_filter=test", ) self.assertEqual( - environment.created_at, datetime.datetime(2022, 4, 19, 14, 4, 32) + environment.created_at, + datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual( - environment.updated_at, datetime.datetime(2022, 4, 19, 14, 4, 32) + environment.updated_at, + datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual(len(environment.protection_rules), 3) self.assertEqual(environment.protection_rules[0].type, "required_reviewers") diff --git a/tests/Event.py b/tests/Event.py index 1be98f42..348e224a 100644 --- a/tests/Event.py +++ b/tests/Event.py @@ -26,7 +26,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -39,7 +39,8 @@ class Event(Framework.TestCase): def testAttributes(self): self.assertEqual(self.event.actor.login, "jacquev6") self.assertEqual( - self.event.created_at, datetime.datetime(2012, 5, 26, 10, 1, 39) + self.event.created_at, + datetime(2012, 5, 26, 10, 1, 39, tzinfo=timezone.utc), ) self.assertEqual(self.event.id, "1556114751") self.assertEqual(self.event.org, None) diff --git a/tests/Gist.py b/tests/Gist.py index a2127d3a..3bc83d5e 100644 --- a/tests/Gist.py +++ b/tests/Gist.py @@ -26,7 +26,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone import github @@ -37,7 +37,10 @@ class Gist(Framework.TestCase): def testAttributes(self): gist = self.g.get_gist("6296732") self.assertEqual(gist.comments, 0) - self.assertEqual(gist.created_at, datetime.datetime(2013, 8, 21, 16, 28, 24)) + self.assertEqual( + gist.created_at, + datetime(2013, 8, 21, 16, 28, 24, tzinfo=timezone.utc), + ) self.assertEqual(gist.description, "Github API") self.assertEqual(list(gist.files.keys()), ["GithubAPI.lua"]) self.assertEqual(gist.files["GithubAPI.lua"].size, 21229) @@ -56,7 +59,8 @@ class Gist(Framework.TestCase): self.assertEqual(gist.history[0].change_status.deletions, 0) self.assertEqual(gist.history[0].change_status.total, 793) self.assertEqual( - gist.history[0].committed_at, datetime.datetime(2013, 8, 21, 16, 12, 27) + gist.history[0].committed_at, + datetime(2013, 8, 21, 16, 12, 27, tzinfo=timezone.utc), ) self.assertEqual( gist.history[0].url, @@ -70,7 +74,10 @@ class Gist(Framework.TestCase): self.assertEqual(gist.html_url, "https://gist.github.com/6296732") self.assertEqual(gist.id, "6296732") self.assertTrue(gist.public) - self.assertEqual(gist.updated_at, datetime.datetime(2013, 8, 21, 16, 28, 24)) + self.assertEqual( + gist.updated_at, + datetime(2013, 8, 21, 16, 28, 24, tzinfo=timezone.utc), + ) self.assertEqual(gist.url, "https://api.github.com/gists/6296732") self.assertEqual(gist.user, None) self.assertEqual(gist.owner.login, "jacquev6") @@ -87,7 +94,10 @@ class Gist(Framework.TestCase): gist = self.g.get_gist("2729810") gist.edit() self.assertEqual(gist.description, "Gist created by PyGithub") - self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 0, 58)) + self.assertEqual( + gist.updated_at, + datetime(2012, 5, 19, 7, 0, 58, tzinfo=timezone.utc), + ) def testEditWithAllParameters(self): gist = self.g.get_gist("2729810") @@ -96,7 +106,10 @@ class Gist(Framework.TestCase): {"barbaz.txt": github.InputFileContent("File also created by PyGithub")}, ) self.assertEqual(gist.description, "Description edited by PyGithub") - self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 6, 10)) + self.assertEqual( + gist.updated_at, + datetime(2012, 5, 19, 7, 6, 10, tzinfo=timezone.utc), + ) self.assertEqual(set(gist.files.keys()), {"foobar.txt", "barbaz.txt"}) def testDeleteFile(self): diff --git a/tests/GistComment.py b/tests/GistComment.py index 0853fc2f..671d2b6a 100644 --- a/tests/GistComment.py +++ b/tests/GistComment.py @@ -26,7 +26,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -39,11 +39,13 @@ class GistComment(Framework.TestCase): def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") self.assertEqual( - self.comment.created_at, datetime.datetime(2012, 5, 19, 7, 7, 57) + self.comment.created_at, + datetime(2012, 5, 19, 7, 7, 57, tzinfo=timezone.utc), ) self.assertEqual(self.comment.id, 323629) self.assertEqual( - self.comment.updated_at, datetime.datetime(2012, 5, 19, 7, 7, 57) + self.comment.updated_at, + datetime(2012, 5, 19, 7, 7, 57, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, "https://api.github.com/gists/2729810/comments/323629" @@ -58,7 +60,8 @@ class GistComment(Framework.TestCase): self.comment.edit("Comment edited by PyGithub") self.assertEqual(self.comment.body, "Comment edited by PyGithub") self.assertEqual( - self.comment.updated_at, datetime.datetime(2012, 5, 19, 7, 12, 32) + self.comment.updated_at, + datetime(2012, 5, 19, 7, 12, 32, tzinfo=timezone.utc), ) def testDelete(self): diff --git a/tests/GitCommit.py b/tests/GitCommit.py index 66564537..e8eedfe5 100644 --- a/tests/GitCommit.py +++ b/tests/GitCommit.py @@ -27,7 +27,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -45,12 +45,14 @@ class GitCommit(Framework.TestCase): self.assertEqual(self.commit.author.name, "Vincent Jacques") self.assertEqual(self.commit.author.email, "vincent@vincent-jacques.net") self.assertEqual( - self.commit.author.date, datetime.datetime(2012, 4, 17, 17, 55, 16) + self.commit.author.date, + datetime(2012, 4, 17, 17, 55, 16, tzinfo=timezone.utc), ) self.assertEqual(self.commit.committer.name, "Vincent Jacques") self.assertEqual(self.commit.committer.email, "vincent@vincent-jacques.net") self.assertEqual( - self.commit.committer.date, datetime.datetime(2012, 4, 17, 17, 55, 16) + self.commit.committer.date, + datetime(2012, 4, 17, 17, 55, 16, tzinfo=timezone.utc), ) self.assertEqual(self.commit.message, "Merge branch 'develop'\n") self.assertEqual(len(self.commit.parents), 2) diff --git a/tests/GitRelease.py b/tests/GitRelease.py index 7a6a5722..c855eda9 100644 --- a/tests/GitRelease.py +++ b/tests/GitRelease.py @@ -32,9 +32,9 @@ # # ################################################################################ -import datetime import os import zipfile +from datetime import datetime, timezone from github import GithubException @@ -64,8 +64,8 @@ user = "rickrickston123" release_id = 28524234 author_id = 64711998 tag = "v1.0" -create_date = datetime.datetime(2020, 7, 12, 7, 34, 42) -publish_date = datetime.datetime(2020, 7, 14, 0, 58, 20) +create_date = datetime(2020, 7, 12, 7, 34, 42, tzinfo=timezone.utc) +publish_date = datetime(2020, 7, 14, 0, 58, 20, tzinfo=timezone.utc) class GitRelease(Framework.TestCase): diff --git a/tests/GitTag.py b/tests/GitTag.py index d827282f..6771446e 100644 --- a/tests/GitTag.py +++ b/tests/GitTag.py @@ -27,7 +27,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -54,7 +54,8 @@ class GitTag(Framework.TestCase): self.assertEqual(self.tag.sha, "f5f37322407b02a80de4526ad88d5f188977bc3c") self.assertEqual(self.tag.tag, "v0.6") self.assertEqual( - self.tag.tagger.date, datetime.datetime(2012, 5, 10, 18, 14, 15) + self.tag.tagger.date, + datetime(2012, 5, 10, 18, 14, 15, tzinfo=timezone.utc), ) self.assertEqual(self.tag.tagger.email, "vincent@vincent-jacques.net") self.assertEqual(self.tag.tagger.name, "Vincent Jacques") diff --git a/tests/GithubApp.py b/tests/GithubApp.py index b0710ff7..9ab0ddf8 100644 --- a/tests/GithubApp.py +++ b/tests/GithubApp.py @@ -20,7 +20,7 @@ # # ################################################################################ -from datetime import datetime +from datetime import datetime, timezone import github @@ -35,7 +35,9 @@ class GithubApp(Framework.TestCase): def testGetPublicApp(self): app = self.g.get_app(slug=self.app_slug) - self.assertEqual(app.created_at, datetime(2018, 7, 30, 9, 30, 17)) + self.assertEqual( + app.created_at, datetime(2018, 7, 30, 9, 30, 17, tzinfo=timezone.utc) + ) self.assertEqual( app.description, "Automate your workflow from idea to production" ) @@ -98,7 +100,9 @@ class GithubApp(Framework.TestCase): }, ) self.assertEqual(app.slug, "github-actions") - self.assertEqual(app.updated_at, datetime(2019, 12, 10, 19, 4, 12)) + self.assertEqual( + app.updated_at, datetime(2019, 12, 10, 19, 4, 12, tzinfo=timezone.utc) + ) self.assertEqual(app.url, "/apps/github-actions") def testGetAuthenticatedApp(self): @@ -116,7 +120,9 @@ class GithubApp(Framework.TestCase): "please use github.GithubIntegration(auth=github.Auth.AppAuth(...)).get_app() instead", ) - self.assertEqual(app.created_at, datetime(2020, 8, 1, 17, 23, 46)) + self.assertEqual( + app.created_at, datetime(2020, 8, 1, 17, 23, 46, tzinfo=timezone.utc) + ) self.assertEqual(app.description, "Sample App to test PyGithub") self.assertListEqual( app.events, @@ -143,5 +149,7 @@ class GithubApp(Framework.TestCase): }, ) self.assertEqual(app.slug, "pygithubtest") - self.assertEqual(app.updated_at, datetime(2020, 8, 1, 17, 44, 31)) + self.assertEqual( + app.updated_at, datetime(2020, 8, 1, 17, 44, 31, tzinfo=timezone.utc) + ) self.assertEqual(app.url, "/apps/pygithubtest") diff --git a/tests/GithubObject.py b/tests/GithubObject.py new file mode 100644 index 00000000..7da4357f --- /dev/null +++ b/tests/GithubObject.py @@ -0,0 +1,120 @@ +############################ Copyrights and license ############################ +# # +# Copyright 2023 Enrico Minack # +# # +# This file is part of PyGithub. # +# http://pygithub.readthedocs.io/ # +# # +# PyGithub is free software: you can redistribute it and/or modify it under # +# the terms of the GNU Lesser General Public License as published by the Free # +# Software Foundation, either version 3 of the License, or (at your option) # +# any later version. # +# # +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # +# details. # +# # +# You should have received a copy of the GNU Lesser General Public License # +# along with PyGithub. If not, see . # +# # +################################################################################ + +import unittest +from datetime import datetime, timedelta, timezone + +from dateutil.tz.tz import tzoffset + +from . import Framework + +gho = Framework.github.GithubObject + + +class GithubObject(unittest.TestCase): + def testMakeDatetimeAttribute(self): + for value, expected in [ + (None, None), + ( + "2021-01-23T12:34:56Z", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone.utc), + ), + ( + "2021-01-23T12:34:56.000Z", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone.utc), + ), + ( + "2021-01-23T12:34:56.000Z", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone.utc), + ), + ( + "2021-01-23T12:34:56+00:00", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone.utc), + ), + ( + "2021-01-23T12:34:56+01:00", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone(timedelta(hours=1))), + ), + ( + "2021-01-23T12:34:56-06:30", + datetime( + 2021, + 1, + 23, + 12, + 34, + 56, + tzinfo=timezone(timedelta(hours=-6, minutes=-30)), + ), + ), + ( + "2021-01-23T12:34:56.000+00:00", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone.utc), + ), + ( + "2021-01-23T12:34:56.000+01:00", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone(timedelta(hours=1))), + ), + ( + "2021-01-23T12:34:56.000-06:00", + datetime(2021, 1, 23, 12, 34, 56, tzinfo=tzoffset(None, -21600)), + ), + ]: + actual = gho.GithubObject._makeDatetimeAttribute(value) + self.assertEqual(gho._ValuedAttribute, type(actual), value) + self.assertEqual(expected, actual.value, value) + + def testMakeDatetimeAttributeBadValues(self): + for value in ["not a timestamp", 1234]: + actual = gho.GithubObject._makeDatetimeAttribute(value) + + self.assertEqual(gho._BadAttribute, type(actual)) + with self.assertRaises(Framework.github.BadAttributeException) as e: + value = actual.value + self.assertEqual(value, e.exception.actual_value) + self.assertEqual(str, e.exception.expected_type) + if isinstance(value, str): + self.assertIsNotNone(e.exception.transformation_exception) + else: + self.assertIsNone(e.exception.transformation_exception) + + def testMakeTimestampAttribute(self): + actual = gho.GithubObject._makeTimestampAttribute(None) + self.assertEqual(gho._ValuedAttribute, type(actual)) + self.assertIsNone(actual.value) + + actual = gho.GithubObject._makeTimestampAttribute(1611405296) + self.assertEqual(gho._ValuedAttribute, type(actual)) + self.assertEqual( + datetime(2021, 1, 23, 12, 34, 56, tzinfo=timezone.utc), actual.value + ) + + def testMakeTimetsampAttributeBadValues(self): + for value in ["1611405296", 1234.567]: + actual = gho.GithubObject._makeTimestampAttribute(value) + + self.assertEqual(gho._BadAttribute, type(actual)) + with self.assertRaises(Framework.github.BadAttributeException) as e: + value = actual.value + self.assertEqual(value, e.exception.actual_value) + self.assertEqual(int, e.exception.expected_type) + self.assertIsNone(e.exception.transformation_exception) diff --git a/tests/Github_.py b/tests/Github_.py index a87f4355..45eaef6e 100644 --- a/tests/Github_.py +++ b/tests/Github_.py @@ -30,11 +30,11 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone import github -from . import Framework, Time +from . import Framework class Github(Framework.TestCase): @@ -148,11 +148,7 @@ class Github(Framework.TestCase): def testGetGistsWithSince(self): self.assertListKeyBegin( - self.g.get_gists( - since=datetime.datetime( - 2018, 10, 2, 10, 38, 30, 00, tzinfo=Time.UTCtzinfo() - ) - ), + self.g.get_gists(since=datetime(2018, 10, 2, 10, 38, 30, 00)), lambda g: g.id, [ "69b8a5831b74946db944c5451017fa40", @@ -209,7 +205,8 @@ class Github(Framework.TestCase): self.assertEqual(delivery.id, 12345) self.assertEqual(delivery.guid, "abcde-12345") self.assertEqual( - delivery.delivered_at, datetime.datetime(2012, 5, 27, 6, 0, 32) + delivery.delivered_at, + datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(delivery.redelivery, False) self.assertEqual(delivery.duration, 0.27) @@ -237,7 +234,8 @@ class Github(Framework.TestCase): self.assertEqual(deliveries[0].id, 12345) self.assertEqual(deliveries[0].guid, "abcde-12345") self.assertEqual( - deliveries[0].delivered_at, datetime.datetime(2012, 5, 27, 6, 0, 32) + deliveries[0].delivered_at, + datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(deliveries[0].redelivery, False) self.assertEqual(deliveries[0].duration, 0.27) diff --git a/tests/Hook.py b/tests/Hook.py index 86c0257a..9912364a 100644 --- a/tests/Hook.py +++ b/tests/Hook.py @@ -27,7 +27,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -40,7 +40,10 @@ class Hook(Framework.TestCase): def testAttributes(self): self.assertTrue(self.hook.active) # WTF self.assertEqual(self.hook.config, {"url": "http://foobar.com"}) - self.assertEqual(self.hook.created_at, datetime.datetime(2012, 5, 19, 6, 1, 45)) + self.assertEqual( + self.hook.created_at, + datetime(2012, 5, 19, 6, 1, 45, tzinfo=timezone.utc), + ) self.assertEqual(self.hook.events, ["push"]) self.assertEqual(self.hook.id, 257993) self.assertEqual(self.hook.last_response.status, "ok") @@ -48,7 +51,8 @@ class Hook(Framework.TestCase): self.assertEqual(self.hook.last_response.code, 200) self.assertEqual(self.hook.name, "web") self.assertEqual( - self.hook.updated_at, datetime.datetime(2012, 5, 29, 18, 49, 47) + self.hook.updated_at, + datetime(2012, 5, 29, 18, 49, 47, tzinfo=timezone.utc), ) self.assertEqual( self.hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993" @@ -71,7 +75,10 @@ class Hook(Framework.TestCase): def testEditWithMinimalParameters(self): self.hook.edit("web", {"url": "http://foobar.com/hook"}) self.assertEqual(self.hook.config, {"url": "http://foobar.com/hook"}) - self.assertEqual(self.hook.updated_at, datetime.datetime(2012, 5, 19, 5, 8, 16)) + self.assertEqual( + self.hook.updated_at, + datetime(2012, 5, 19, 5, 8, 16, tzinfo=timezone.utc), + ) def testDelete(self): self.hook.delete() diff --git a/tests/Issue.py b/tests/Issue.py index 82cc8909..bf2b749e 100644 --- a/tests/Issue.py +++ b/tests/Issue.py @@ -32,7 +32,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -50,7 +50,8 @@ class Issue(Framework.TestCase): ) self.assertEqual(self.issue.body, "Body edited by PyGithub") self.assertEqual( - self.issue.closed_at, datetime.datetime(2012, 5, 26, 14, 59, 33) + self.issue.closed_at, + datetime(2012, 5, 26, 14, 59, 33, tzinfo=timezone.utc), ) self.assertEqual(self.issue.closed_by.login, "jacquev6") self.assertEqual(self.issue.comments, 0) @@ -59,7 +60,8 @@ class Issue(Framework.TestCase): "https://github.com/jacquev6/PyGithub/issues/28/comments", ) self.assertEqual( - self.issue.created_at, datetime.datetime(2012, 5, 19, 10, 38, 23) + self.issue.created_at, + datetime(2012, 5, 19, 10, 38, 23, tzinfo=timezone.utc), ) self.assertEqual( self.issue.events_url, @@ -87,7 +89,8 @@ class Issue(Framework.TestCase): self.assertEqual(self.issue.state_reason, "completed") self.assertEqual(self.issue.title, "Issue created by PyGithub") self.assertEqual( - self.issue.updated_at, datetime.datetime(2012, 5, 26, 14, 59, 33) + self.issue.updated_at, + datetime(2012, 5, 26, 14, 59, 33, tzinfo=timezone.utc), ) self.assertEqual( self.issue.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/28" @@ -161,7 +164,9 @@ class Issue(Framework.TestCase): def testGetCommentsSince(self): self.assertListKeyEqual( - self.issue.get_comments(datetime.datetime(2012, 5, 26, 13, 59, 33)), + self.issue.get_comments( + datetime(2012, 5, 26, 13, 59, 33, tzinfo=timezone.utc) + ), lambda c: c.user.login, ["jacquev6", "roskakori"], ) diff --git a/tests/Issue54.py b/tests/Issue54.py index d93ca051..1c351558 100644 --- a/tests/Issue54.py +++ b/tests/Issue54.py @@ -25,7 +25,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -41,4 +41,7 @@ class Issue54(Framework.TestCase): commit.message, "Test commit created around Fri, 13 Jul 2012 18:43:21 GMT, that is vendredi 13 juillet 2012 20:43:21 GMT+2\n", ) - self.assertEqual(commit.author.date, datetime.datetime(2012, 7, 13, 18, 47, 10)) + self.assertEqual( + commit.author.date, + datetime(2012, 7, 13, 18, 47, 10, tzinfo=timezone.utc), + ) diff --git a/tests/IssueComment.py b/tests/IssueComment.py index f517a712..5af024e7 100644 --- a/tests/IssueComment.py +++ b/tests/IssueComment.py @@ -28,7 +28,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -43,11 +43,13 @@ class IssueComment(Framework.TestCase): def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") self.assertEqual( - self.comment.created_at, datetime.datetime(2012, 5, 20, 11, 46, 42) + self.comment.created_at, + datetime(2012, 5, 20, 11, 46, 42, tzinfo=timezone.utc), ) self.assertEqual(self.comment.id, 5808311) self.assertEqual( - self.comment.updated_at, datetime.datetime(2012, 5, 20, 11, 46, 42) + self.comment.updated_at, + datetime(2012, 5, 20, 11, 46, 42, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, @@ -67,7 +69,8 @@ class IssueComment(Framework.TestCase): self.comment.edit("Comment edited by PyGithub") self.assertEqual(self.comment.body, "Comment edited by PyGithub") self.assertEqual( - self.comment.updated_at, datetime.datetime(2012, 5, 20, 11, 53, 59) + self.comment.updated_at, + datetime(2012, 5, 20, 11, 53, 59, tzinfo=timezone.utc), ) def testDelete(self): diff --git a/tests/IssueEvent.py b/tests/IssueEvent.py index 837d7bb0..de299d59 100644 --- a/tests/IssueEvent.py +++ b/tests/IssueEvent.py @@ -27,7 +27,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -76,7 +76,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_subscribed.actor.login, "jacquev6") self.assertEqual(self.event_subscribed.commit_id, None) self.assertEqual( - self.event_subscribed.created_at, datetime.datetime(2012, 5, 27, 5, 40, 15) + self.event_subscribed.created_at, + datetime(2012, 5, 27, 5, 40, 15, tzinfo=timezone.utc), ) self.assertEqual(self.event_subscribed.event, "subscribed") self.assertEqual(self.event_subscribed.id, 16347479) @@ -104,7 +105,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_assigned.actor.login, "jacquev6") self.assertEqual(self.event_assigned.commit_id, None) self.assertEqual( - self.event_assigned.created_at, datetime.datetime(2012, 5, 27, 5, 40, 15) + self.event_assigned.created_at, + datetime(2012, 5, 27, 5, 40, 15, tzinfo=timezone.utc), ) self.assertEqual(self.event_assigned.event, "assigned") self.assertEqual(self.event_assigned.id, 16347480) @@ -134,7 +136,8 @@ class IssueEvent(Framework.TestCase): self.event_referenced.commit_id, "ed866fc43833802ab553e5ff8581c81bb00dd433" ) self.assertEqual( - self.event_referenced.created_at, datetime.datetime(2012, 5, 27, 7, 29, 25) + self.event_referenced.created_at, + datetime(2012, 5, 27, 7, 29, 25, tzinfo=timezone.utc), ) self.assertEqual(self.event_referenced.event, "referenced") self.assertEqual(self.event_referenced.id, 16348656) @@ -165,7 +168,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_closed.actor.login, "jacquev6") self.assertEqual(self.event_closed.commit_id, None) self.assertEqual( - self.event_closed.created_at, datetime.datetime(2012, 5, 27, 11, 4, 25) + self.event_closed.created_at, + datetime(2012, 5, 27, 11, 4, 25, tzinfo=timezone.utc), ) self.assertEqual(self.event_closed.event, "closed") self.assertEqual(self.event_closed.id, 16351220) @@ -191,7 +195,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_labeled.actor.login, "jacquev6") self.assertEqual(self.event_labeled.commit_id, None) self.assertEqual( - self.event_labeled.created_at, datetime.datetime(2014, 3, 2, 18, 55, 10) + self.event_labeled.created_at, + datetime(2014, 3, 2, 18, 55, 10, tzinfo=timezone.utc), ) self.assertEqual(self.event_labeled.event, "labeled") self.assertEqual(self.event_labeled.id, 98136337) @@ -217,7 +222,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_mentioned.actor.login, "jzelinskie") self.assertEqual(self.event_mentioned.commit_id, None) self.assertEqual( - self.event_mentioned.created_at, datetime.datetime(2017, 3, 21, 17, 30, 14) + self.event_mentioned.created_at, + datetime(2017, 3, 21, 17, 30, 14, tzinfo=timezone.utc), ) self.assertEqual(self.event_mentioned.event, "mentioned") self.assertEqual(self.event_mentioned.id, 1009034767) @@ -247,7 +253,8 @@ class IssueEvent(Framework.TestCase): self.event_merged.commit_id, "2525515b094d7425f7018eb5b66171e21c5fbc10" ) self.assertEqual( - self.event_merged.created_at, datetime.datetime(2017, 3, 25, 16, 52, 49) + self.event_merged.created_at, + datetime(2017, 3, 25, 16, 52, 49, tzinfo=timezone.utc), ) self.assertEqual(self.event_merged.event, "merged") self.assertEqual(self.event_merged.id, 1015402964) @@ -279,7 +286,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_review_requested.commit_id, None) self.assertEqual( self.event_review_requested.created_at, - datetime.datetime(2017, 3, 22, 19, 6, 44), + datetime(2017, 3, 22, 19, 6, 44, tzinfo=timezone.utc), ) self.assertEqual(self.event_review_requested.event, "review_requested") self.assertEqual(self.event_review_requested.id, 1011101309) @@ -312,7 +319,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_reopened.actor.login, "sfdye") self.assertEqual(self.event_reopened.commit_id, None) self.assertEqual( - self.event_reopened.created_at, datetime.datetime(2018, 8, 10, 13, 10, 9) + self.event_reopened.created_at, + datetime(2018, 8, 10, 13, 10, 9, tzinfo=timezone.utc), ) self.assertEqual(self.event_reopened.event, "reopened") self.assertEqual(self.event_reopened.id, 1782463023) @@ -340,7 +348,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unassigned.actor.login, "sfdye") self.assertEqual(self.event_unassigned.commit_id, None) self.assertEqual( - self.event_unassigned.created_at, datetime.datetime(2018, 8, 10, 13, 10, 21) + self.event_unassigned.created_at, + datetime(2018, 8, 10, 13, 10, 21, tzinfo=timezone.utc), ) self.assertEqual(self.event_unassigned.event, "unassigned") self.assertEqual(self.event_unassigned.id, 1782463379) @@ -368,7 +377,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unlabeled.actor.login, "sfdye") self.assertEqual(self.event_unlabeled.commit_id, None) self.assertEqual( - self.event_unlabeled.created_at, datetime.datetime(2018, 8, 10, 13, 10, 38) + self.event_unlabeled.created_at, + datetime(2018, 8, 10, 13, 10, 38, tzinfo=timezone.utc), ) self.assertEqual(self.event_unlabeled.event, "unlabeled") self.assertEqual(self.event_unlabeled.id, 1782463917) @@ -396,7 +406,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_renamed.actor.login, "sfdye") self.assertEqual(self.event_renamed.commit_id, None) self.assertEqual( - self.event_renamed.created_at, datetime.datetime(2018, 8, 10, 13, 15, 18) + self.event_renamed.created_at, + datetime(2018, 8, 10, 13, 15, 18, tzinfo=timezone.utc), ) self.assertEqual(self.event_renamed.event, "renamed") self.assertEqual(self.event_renamed.id, 1782472556) @@ -431,7 +442,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_base_ref_changed.commit_id, None) self.assertEqual( self.event_base_ref_changed.created_at, - datetime.datetime(2018, 8, 10, 16, 38, 22), + datetime(2018, 8, 10, 16, 38, 22, tzinfo=timezone.utc), ) self.assertEqual(self.event_base_ref_changed.event, "base_ref_changed") self.assertEqual(self.event_base_ref_changed.id, 1782915693) @@ -461,7 +472,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_head_ref_deleted.commit_id, None) self.assertEqual( self.event_head_ref_deleted.created_at, - datetime.datetime(2018, 8, 10, 16, 39, 20), + datetime(2018, 8, 10, 16, 39, 20, tzinfo=timezone.utc), ) self.assertEqual(self.event_head_ref_deleted.event, "head_ref_deleted") self.assertEqual(self.event_head_ref_deleted.id, 1782917185) @@ -491,7 +502,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_head_ref_restored.commit_id, None) self.assertEqual( self.event_head_ref_restored.created_at, - datetime.datetime(2018, 8, 10, 16, 39, 23), + datetime(2018, 8, 10, 16, 39, 23, tzinfo=timezone.utc), ) self.assertEqual(self.event_head_ref_restored.event, "head_ref_restored") self.assertEqual(self.event_head_ref_restored.id, 1782917299) @@ -522,7 +533,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_milestoned.actor.login, "sfdye") self.assertEqual(self.event_milestoned.commit_id, None) self.assertEqual( - self.event_milestoned.created_at, datetime.datetime(2018, 8, 11, 0, 46, 19) + self.event_milestoned.created_at, + datetime(2018, 8, 11, 0, 46, 19, tzinfo=timezone.utc), ) self.assertEqual(self.event_milestoned.event, "milestoned") self.assertEqual(self.event_milestoned.id, 1783596418) @@ -551,7 +563,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_demilestoned.commit_id, None) self.assertEqual( self.event_demilestoned.created_at, - datetime.datetime(2018, 8, 11, 0, 46, 22), + datetime(2018, 8, 11, 0, 46, 22, tzinfo=timezone.utc), ) self.assertEqual(self.event_demilestoned.event, "demilestoned") self.assertEqual(self.event_demilestoned.id, 1783596452) @@ -580,7 +592,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_locked.actor.login, "PyGithub") self.assertEqual(self.event_locked.commit_id, None) self.assertEqual( - self.event_locked.created_at, datetime.datetime(2018, 8, 11, 0, 46, 56) + self.event_locked.created_at, + datetime(2018, 8, 11, 0, 46, 56, tzinfo=timezone.utc), ) self.assertEqual(self.event_locked.event, "locked") self.assertEqual(self.event_locked.id, 1783596743) @@ -608,7 +621,8 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unlocked.actor.login, "PyGithub") self.assertEqual(self.event_unlocked.commit_id, None) self.assertEqual( - self.event_unlocked.created_at, datetime.datetime(2018, 8, 11, 0, 47, 7) + self.event_unlocked.created_at, + datetime(2018, 8, 11, 0, 47, 7, tzinfo=timezone.utc), ) self.assertEqual(self.event_unlocked.event, "unlocked") self.assertEqual(self.event_unlocked.id, 1783596818) @@ -637,7 +651,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_review_dismissed.commit_id, None) self.assertEqual( self.event_review_dismissed.created_at, - datetime.datetime(2018, 8, 11, 1, 7, 10), + datetime(2018, 8, 11, 1, 7, 10, tzinfo=timezone.utc), ) self.assertEqual(self.event_review_dismissed.event, "review_dismissed") self.assertEqual(self.event_review_dismissed.id, 1783605084) @@ -674,7 +688,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_review_request_removed.commit_id, None) self.assertEqual( self.event_review_request_removed.created_at, - datetime.datetime(2018, 8, 11, 12, 32, 59), + datetime(2018, 8, 11, 12, 32, 59, tzinfo=timezone.utc), ) self.assertEqual( self.event_review_request_removed.event, "review_request_removed" @@ -712,7 +726,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_marked_as_duplicate.commit_id, None) self.assertEqual( self.event_marked_as_duplicate.created_at, - datetime.datetime(2018, 8, 11, 12, 32, 35), + datetime(2018, 8, 11, 12, 32, 35, tzinfo=timezone.utc), ) self.assertEqual(self.event_marked_as_duplicate.event, "marked_as_duplicate") self.assertEqual(self.event_marked_as_duplicate.id, 1783779725) @@ -744,7 +758,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unmarked_as_duplicate.commit_id, None) self.assertEqual( self.event_unmarked_as_duplicate.created_at, - datetime.datetime(2018, 8, 15, 2, 57, 46), + datetime(2018, 8, 15, 2, 57, 46, tzinfo=timezone.utc), ) self.assertEqual( self.event_unmarked_as_duplicate.event, "unmarked_as_duplicate" @@ -778,7 +792,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_added_to_project.commit_id, None) self.assertEqual( self.event_added_to_project.created_at, - datetime.datetime(2018, 8, 16, 8, 13, 24), + datetime(2018, 8, 16, 8, 13, 24, tzinfo=timezone.utc), ) self.assertEqual(self.event_added_to_project.event, "added_to_project") self.assertEqual(self.event_added_to_project.id, 1791766828) @@ -808,7 +822,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_moved_columns_in_project.commit_id, None) self.assertEqual( self.event_moved_columns_in_project.created_at, - datetime.datetime(2018, 8, 16, 8, 13, 55), + datetime(2018, 8, 16, 8, 13, 55, tzinfo=timezone.utc), ) self.assertEqual( self.event_moved_columns_in_project.event, "moved_columns_in_project" @@ -842,7 +856,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_removed_from_project.commit_id, None) self.assertEqual( self.event_removed_from_project.created_at, - datetime.datetime(2018, 8, 16, 8, 14, 8), + datetime(2018, 8, 16, 8, 14, 8, tzinfo=timezone.utc), ) self.assertEqual(self.event_removed_from_project.event, "removed_from_project") self.assertEqual(self.event_removed_from_project.id, 1791768212) @@ -874,7 +888,7 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_converted_note_to_issue.commit_id, None) self.assertEqual( self.event_converted_note_to_issue.created_at, - datetime.datetime(2018, 8, 16, 8, 14, 34), + datetime(2018, 8, 16, 8, 14, 34, tzinfo=timezone.utc), ) self.assertEqual( self.event_converted_note_to_issue.event, "converted_note_to_issue" diff --git a/tests/Migration.py b/tests/Migration.py index f503a6d2..cd343081 100644 --- a/tests/Migration.py +++ b/tests/Migration.py @@ -45,7 +45,9 @@ # # ################################################################################ -import datetime +from datetime import datetime + +from dateutil.tz.tz import tzoffset import github @@ -71,10 +73,12 @@ class Migration(Framework.TestCase): self.migration.url, "https://api.github.com/user/migrations/25320" ) self.assertEqual( - self.migration.created_at, datetime.datetime(2018, 9, 14, 1, 35, 35) + self.migration.created_at, + datetime(2018, 9, 14, 1, 35, 35, tzinfo=tzoffset(None, 19800)), ) self.assertEqual( - self.migration.updated_at, datetime.datetime(2018, 9, 14, 1, 35, 46) + self.migration.updated_at, + datetime(2018, 9, 14, 1, 35, 46, tzinfo=tzoffset(None, 19800)), ) self.assertEqual( repr(self.migration), diff --git a/tests/Milestone.py b/tests/Milestone.py index 82da2689..3c9820db 100644 --- a/tests/Milestone.py +++ b/tests/Milestone.py @@ -26,7 +26,7 @@ # # ################################################################################ -import datetime +from datetime import date, datetime, timezone from . import Framework @@ -39,10 +39,14 @@ class Milestone(Framework.TestCase): def testAttributes(self): self.assertEqual(self.milestone.closed_issues, 2) self.assertEqual( - self.milestone.created_at, datetime.datetime(2012, 3, 8, 12, 22, 10) + self.milestone.created_at, + datetime(2012, 3, 8, 12, 22, 10, tzinfo=timezone.utc), ) self.assertEqual(self.milestone.description, "") - self.assertEqual(self.milestone.due_on, datetime.datetime(2012, 3, 13, 7, 0, 0)) + self.assertEqual( + self.milestone.due_on, + datetime(2012, 3, 13, 7, 0, 0, tzinfo=timezone.utc), + ) self.assertEqual(self.milestone.id, 93546) self.assertEqual(self.milestone.number, 1) self.assertEqual(self.milestone.open_issues, 0) @@ -66,12 +70,15 @@ class Milestone(Framework.TestCase): "Title edited twice by PyGithub", "closed", "Description edited by PyGithub", - due_on=datetime.date(2012, 6, 16), + due_on=date(2012, 6, 16), ) self.assertEqual(self.milestone.title, "Title edited twice by PyGithub") self.assertEqual(self.milestone.state, "closed") self.assertEqual(self.milestone.description, "Description edited by PyGithub") - self.assertEqual(self.milestone.due_on, datetime.datetime(2012, 6, 16, 7, 0, 0)) + self.assertEqual( + self.milestone.due_on, + datetime(2012, 6, 16, 7, 0, 0, tzinfo=timezone.utc), + ) def testGetLabels(self): self.assertListKeyEqual( diff --git a/tests/NamedUser.py b/tests/NamedUser.py index 42dba7bc..ae24dd17 100644 --- a/tests/NamedUser.py +++ b/tests/NamedUser.py @@ -29,7 +29,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -50,7 +50,8 @@ class NamedUser(Framework.TestCase): self.assertEqual(self.user.collaborators, None) self.assertEqual(self.user.company, "3rd Cloud") self.assertEqual( - self.user.created_at, datetime.datetime(2009, 5, 12, 21, 19, 38) + self.user.created_at, + datetime(2009, 5, 12, 21, 19, 38, tzinfo=timezone.utc), ) self.assertEqual(self.user.disk_usage, None) self.assertEqual(self.user.email, "vincent@3rdcloud.com") @@ -85,7 +86,10 @@ class NamedUser(Framework.TestCase): self.assertEqual(self.user.blog, "http://vincent-jacques.net") self.assertEqual(self.user.collaborators, 0) self.assertEqual(self.user.company, "Criteo") - self.assertEqual(self.user.created_at, datetime.datetime(2010, 7, 9, 6, 10, 6)) + self.assertEqual( + self.user.created_at, + datetime(2010, 7, 9, 6, 10, 6, tzinfo=timezone.utc), + ) self.assertEqual(self.user.disk_usage, 17080) self.assertEqual(self.user.email, "vincent@vincent-jacques.net") self.assertEqual(self.user.followers, 13) @@ -106,7 +110,8 @@ class NamedUser(Framework.TestCase): self.assertEqual(self.user.public_gists, 2) self.assertEqual(self.user.public_repos, 11) self.assertEqual( - self.user.suspended_at, datetime.datetime(2013, 8, 10, 7, 11, 7) + self.user.suspended_at, + datetime(2013, 8, 10, 7, 11, 7, tzinfo=timezone.utc), ) self.assertEqual(self.user.total_private_repos, 5) self.assertIsNone(self.user.twitter_username) @@ -128,7 +133,7 @@ class NamedUser(Framework.TestCase): ], ) self.assertListKeyEqual( - self.user.get_gists(since=datetime.datetime(2012, 3, 1, 17, 0, 0)), + self.user.get_gists(since=datetime(2012, 3, 1, 17, 0, 0)), lambda g: g.description, ["Gist created by PyGithub", "FairThreadPoolPool.cpp"], ) diff --git a/tests/Organization.py b/tests/Organization.py index 9e77ac65..4504063f 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -32,7 +32,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from unittest import mock import github @@ -53,7 +53,10 @@ class Organization(Framework.TestCase): self.assertEqual(self.org.blog, "http://www.example.com") self.assertEqual(self.org.collaborators, 9) self.assertEqual(self.org.company, None) - self.assertEqual(self.org.created_at, datetime.datetime(2014, 1, 9, 16, 56, 17)) + self.assertEqual( + self.org.created_at, + datetime(2014, 1, 9, 16, 56, 17, tzinfo=timezone.utc), + ) self.assertEqual(self.org.default_repository_permission, "none") self.assertEqual(self.org.description, "BeaverSoftware writes software.") self.assertEqual(self.org.disk_usage, 2) @@ -190,7 +193,8 @@ class Organization(Framework.TestCase): self.assertEqual(delivery.id, 12345) self.assertEqual(delivery.guid, "abcde-12345") self.assertEqual( - delivery.delivered_at, datetime.datetime(2012, 5, 27, 6, 0, 32) + delivery.delivered_at, + datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(delivery.redelivery, False) self.assertEqual(delivery.duration, 0.27) @@ -218,7 +222,8 @@ class Organization(Framework.TestCase): self.assertEqual(deliveries[0].id, 12345) self.assertEqual(deliveries[0].guid, "abcde-12345") self.assertEqual( - deliveries[0].delivered_at, datetime.datetime(2012, 5, 27, 6, 0, 32) + deliveries[0].delivered_at, + datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(deliveries[0].redelivery, False) self.assertEqual(deliveries[0].duration, 0.27) @@ -243,7 +248,7 @@ class Organization(Framework.TestCase): [requestedByUser], "comments", "asc", - datetime.datetime(2012, 5, 28, 23, 0, 0), + datetime(2012, 5, 28, 23, 0, 0, tzinfo=timezone.utc), ) self.assertListKeyEqual(issues, lambda i: i.id, []) diff --git a/tests/ProjectColumn.py b/tests/ProjectColumn.py index 7df02fa5..f3bb0507 100644 --- a/tests/ProjectColumn.py +++ b/tests/ProjectColumn.py @@ -18,7 +18,7 @@ # # # ############################################################################## -import datetime +from datetime import datetime, timezone from . import Framework @@ -49,11 +49,11 @@ class ProjectColumn(Framework.TestCase): ) self.assertEqual( self.get_project_column.created_at, - datetime.datetime(2020, 4, 13, 20, 29, 53), + datetime(2020, 4, 13, 20, 29, 53, tzinfo=timezone.utc), ) self.assertEqual( self.get_project_column.updated_at, - datetime.datetime(2020, 4, 14, 18, 9, 38), + datetime(2020, 4, 14, 18, 9, 38, tzinfo=timezone.utc), ) def testGetAllCards(self): diff --git a/tests/PullRequest.py b/tests/PullRequest.py index 90010faf..91f9133b 100644 --- a/tests/PullRequest.py +++ b/tests/PullRequest.py @@ -29,7 +29,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -52,11 +52,11 @@ class PullRequest(Framework.TestCase): def testAttributesIssue256(self): self.assertEqual( self.pullIssue256Closed.closed_at, - datetime.datetime(2018, 5, 22, 14, 50, 43), + datetime(2018, 5, 22, 14, 50, 43, tzinfo=timezone.utc), ) self.assertEqual( self.pullIssue256Merged.closed_at, - datetime.datetime(2018, 5, 22, 14, 53, 13), + datetime(2018, 5, 22, 14, 53, 13, tzinfo=timezone.utc), ) self.assertEqual(self.pullIssue256Conflict.closed_at, None) self.assertEqual(self.pullIssue256Uncached.closed_at, None) @@ -94,11 +94,15 @@ class PullRequest(Framework.TestCase): self.assertEqual(self.pull.base.repo.full_name, "PyGithub/PyGithub") self.assertEqual(self.pull.body, "Body edited by PyGithub\n") self.assertEqual(self.pull.changed_files, 45) - self.assertEqual(self.pull.closed_at, datetime.datetime(2012, 5, 27, 10, 29, 7)) + self.assertEqual( + self.pull.closed_at, + datetime(2012, 5, 27, 10, 29, 7, tzinfo=timezone.utc), + ) self.assertEqual(self.pull.comments, 1) self.assertEqual(self.pull.commits, 3) self.assertEqual( - self.pull.created_at, datetime.datetime(2012, 5, 27, 9, 25, 36) + self.pull.created_at, + datetime(2012, 5, 27, 9, 25, 36, tzinfo=timezone.utc), ) self.assertEqual(self.pull.deletions, 384) self.assertEqual( @@ -117,7 +121,10 @@ class PullRequest(Framework.TestCase): self.assertFalse(self.pull.mergeable) self.assertFalse(self.pull.rebaseable) self.assertTrue(self.pull.merged) - self.assertEqual(self.pull.merged_at, datetime.datetime(2012, 5, 27, 10, 29, 7)) + self.assertEqual( + self.pull.merged_at, + datetime(2012, 5, 27, 10, 29, 7, tzinfo=timezone.utc), + ) self.assertEqual(self.pull.merged_by.login, "jacquev6") self.assertEqual(self.pull.number, 31) self.assertEqual( @@ -127,7 +134,8 @@ class PullRequest(Framework.TestCase): self.assertEqual(self.pull.state, "closed") self.assertEqual(self.pull.title, "Title edited by PyGithub") self.assertEqual( - self.pull.updated_at, datetime.datetime(2018, 6, 25, 12, 54, 43) + self.pull.updated_at, + datetime(2018, 6, 25, 12, 54, 43, tzinfo=timezone.utc), ) self.assertEqual( self.pull.url, "https://api.github.com/repos/PyGithub/PyGithub/pulls/31" @@ -214,7 +222,7 @@ class PullRequest(Framework.TestCase): self.assertEqual(comment.id, 886298) def testGetComments(self): - epoch = datetime.datetime(1970, 1, 1, 0, 0) + epoch = datetime(1970, 1, 1, 0, 0) comments = self.pull.get_comments(sort="updated", direction="desc", since=epoch) self.assertListKeyEqual(comments, lambda c: c.id, [197784357, 1580134]) @@ -239,7 +247,7 @@ class PullRequest(Framework.TestCase): ) def testGetReviewComments(self): - epoch = datetime.datetime(1970, 1, 1, 0, 0) + epoch = datetime(1970, 1, 1, 0, 0) comments = self.pull.get_review_comments( sort="updated", direction="desc", since=epoch ) diff --git a/tests/PullRequestComment.py b/tests/PullRequestComment.py index 2c9bb454..98a6dcbb 100644 --- a/tests/PullRequestComment.py +++ b/tests/PullRequestComment.py @@ -28,7 +28,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -46,7 +46,8 @@ class PullRequestComment(Framework.TestCase): self.comment.commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206" ) self.assertEqual( - self.comment.created_at, datetime.datetime(2012, 5, 27, 9, 40, 12) + self.comment.created_at, + datetime(2012, 5, 27, 9, 40, 12, tzinfo=timezone.utc), ) self.assertEqual(self.comment.id, 886298) self.assertEqual( @@ -56,7 +57,8 @@ class PullRequestComment(Framework.TestCase): self.assertEqual(self.comment.path, "src/github/Issue.py") self.assertEqual(self.comment.position, 5) self.assertEqual( - self.comment.updated_at, datetime.datetime(2012, 5, 27, 9, 40, 12) + self.comment.updated_at, + datetime(2012, 5, 27, 9, 40, 12, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, diff --git a/tests/PullRequestReview.py b/tests/PullRequestReview.py index 2594c7d8..30bbf3d6 100644 --- a/tests/PullRequestReview.py +++ b/tests/PullRequestReview.py @@ -24,7 +24,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -73,7 +73,8 @@ class PullRequestReview(Framework.TestCase): "https://api.github.com/repos/PyGithub/PyGithub/pulls/538", ) self.assertEqual( - self.pullreview.submitted_at, datetime.datetime(2017, 3, 22, 19, 6, 59) + self.pullreview.submitted_at, + datetime(2017, 3, 22, 19, 6, 59, tzinfo=timezone.utc), ) self.assertIn(self.created_pullreview.id, [r.id for r in self.pullreviews]) self.assertEqual( diff --git a/tests/RateLimiting.py b/tests/RateLimiting.py index d8bd7a3b..2fcf0594 100644 --- a/tests/RateLimiting.py +++ b/tests/RateLimiting.py @@ -26,7 +26,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -45,12 +45,15 @@ class RateLimiting(Framework.TestCase): rateLimit = self.g.get_rate_limit() self.assertEqual( repr(rateLimit), - "RateLimit(core=Rate(reset=2018-09-05 04:55:56, remaining=4929, limit=5000))", + "RateLimit(core=Rate(reset=2018-09-05 04:55:56+00:00, remaining=4929, limit=5000))", ) self.assertEqual( repr(rateLimit.core), - "Rate(reset=2018-09-05 04:55:56, remaining=4929, limit=5000)", + "Rate(reset=2018-09-05 04:55:56+00:00, remaining=4929, limit=5000)", ) self.assertEqual(rateLimit.core.limit, 5000) self.assertEqual(rateLimit.core.remaining, 4929) - self.assertEqual(rateLimit.core.reset, datetime.datetime(2018, 9, 5, 4, 55, 56)) + self.assertEqual( + rateLimit.core.reset, + datetime(2018, 9, 5, 4, 55, 56, tzinfo=timezone.utc), + ) diff --git a/tests/Reaction.py b/tests/Reaction.py index a9aa619a..70811221 100644 --- a/tests/Reaction.py +++ b/tests/Reaction.py @@ -21,7 +21,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -39,7 +39,8 @@ class Reaction(Framework.TestCase): def testAttributes(self): self.assertEqual(self.reactions[0].content, "+1") self.assertEqual( - self.reactions[0].created_at, datetime.datetime(2017, 12, 5, 1, 59, 33) + self.reactions[0].created_at, + datetime(2017, 12, 5, 1, 59, 33, tzinfo=timezone.utc), ) self.assertEqual(self.reactions[0].id, 16916340) self.assertEqual(self.reactions[0].user.login, "nicolastrres") diff --git a/tests/ReleaseAsset.py b/tests/ReleaseAsset.py index d0b8af38..413d85ec 100644 --- a/tests/ReleaseAsset.py +++ b/tests/ReleaseAsset.py @@ -22,7 +22,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -47,10 +47,12 @@ class ReleaseAsset(Framework.TestCase): self.assertEqual(self.asset.size, 3783) self.assertEqual(self.asset.download_count, 2) self.assertEqual( - self.asset.created_at, datetime.datetime(2017, 2, 1, 22, 40, 58) + self.asset.created_at, + datetime(2017, 2, 1, 22, 40, 58, tzinfo=timezone.utc), ) self.assertEqual( - self.asset.updated_at, datetime.datetime(2017, 2, 1, 22, 44, 58) + self.asset.updated_at, + datetime(2017, 2, 1, 22, 44, 58, tzinfo=timezone.utc), ) self.assertEqual( self.asset.browser_download_url, diff --git a/tests/Repository.py b/tests/Repository.py index e7a2226f..641a2025 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -46,7 +46,7 @@ # # ################################################################################ -import datetime +from datetime import date, datetime, timezone from unittest import mock import github @@ -65,7 +65,8 @@ class Repository(Framework.TestCase): self.repo.clone_url, "https://github.com/jacquev6/PyGithub.git" ) self.assertEqual( - self.repo.created_at, datetime.datetime(2012, 2, 25, 12, 53, 47) + self.repo.created_at, + datetime(2012, 2, 25, 12, 53, 47, tzinfo=timezone.utc), ) self.assertEqual( self.repo.description, "Python library implementing the full Github API v3" @@ -101,13 +102,17 @@ class Repository(Framework.TestCase): self.assertTrue(self.repo.permissions.pull) self.assertTrue(self.repo.permissions.push) self.assertFalse(self.repo.private) - self.assertEqual(self.repo.pushed_at, datetime.datetime(2012, 5, 27, 6, 0, 28)) + self.assertEqual( + self.repo.pushed_at, + datetime(2012, 5, 27, 6, 0, 28, tzinfo=timezone.utc), + ) self.assertEqual(self.repo.size, 308) self.assertEqual(self.repo.source, None) self.assertEqual(self.repo.ssh_url, "git@github.com:jacquev6/PyGithub.git") self.assertEqual(self.repo.svn_url, "https://github.com/jacquev6/PyGithub") self.assertEqual( - self.repo.updated_at, datetime.datetime(2012, 5, 27, 6, 55, 28) + self.repo.updated_at, + datetime(2012, 5, 27, 6, 55, 28, tzinfo=timezone.utc), ) self.assertEqual( self.repo.url, "https://api.github.com/repos/jacquev6/PyGithub" @@ -181,7 +186,7 @@ class Repository(Framework.TestCase): "Milestone created by PyGithub", state="open", description="Description created by PyGithub", - due_on=datetime.date(2012, 6, 15), + due_on=date(2012, 6, 15), ) self.assertEqual(milestone.number, 5) @@ -482,11 +487,11 @@ class Repository(Framework.TestCase): ) self.assertEqual( codescan_alert.created_at, - datetime.datetime(2021, 6, 29, 12, 28, 30), + datetime(2021, 6, 29, 12, 28, 30, tzinfo=timezone.utc), ) self.assertEqual( codescan_alert.dismissed_at, - datetime.datetime(2021, 6, 30, 5, 5, 5), + datetime(2021, 6, 30, 5, 5, 5, tzinfo=timezone.utc), ) self.assertEqual(codescan_alert.dismissed_reason, "Won't tell") dismissed_by = codescan_alert.dismissed_by @@ -786,8 +791,8 @@ class Repository(Framework.TestCase): def testGetCommitsWithSinceUntil(self): self.assertListKeyEqual( self.repo.get_commits( - since=datetime.datetime(2013, 3, 1), - until=datetime.datetime(2013, 3, 31), + since=datetime(2013, 3, 1), + until=datetime(2013, 3, 31), ), lambda c: c.sha, [ @@ -940,7 +945,8 @@ class Repository(Framework.TestCase): self.assertEqual(delivery.id, 12345) self.assertEqual(delivery.guid, "abcde-12345") self.assertEqual( - delivery.delivered_at, datetime.datetime(2012, 5, 27, 6, 0, 32) + delivery.delivered_at, + datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(delivery.redelivery, False) self.assertEqual(delivery.duration, 0.27) @@ -968,7 +974,8 @@ class Repository(Framework.TestCase): self.assertEqual(deliveries[0].id, 12345) self.assertEqual(deliveries[0].guid, "abcde-12345") self.assertEqual( - deliveries[0].delivered_at, datetime.datetime(2012, 5, 27, 6, 0, 32) + deliveries[0].delivered_at, + datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(deliveries[0].redelivery, False) self.assertEqual(deliveries[0].duration, 0.27) @@ -1041,7 +1048,9 @@ class Repository(Framework.TestCase): ], ) self.assertListKeyEqual( - self.repo.get_issues(since=datetime.datetime(2012, 5, 28, 23, 0, 0)), + self.repo.get_issues( + since=datetime(2012, 5, 28, 23, 0, 0, tzinfo=timezone.utc) + ), lambda i: i.id, [4793216, 4793162, 4793106, 3624556, 3619973, 3527266], ) @@ -1288,12 +1297,30 @@ class Repository(Framework.TestCase): stargazers, lambda stargazer: (stargazer.starred_at, stargazer.user.login), [ - (datetime.datetime(2014, 8, 13, 19, 22, 5), "sAlexander"), - (datetime.datetime(2014, 10, 15, 5, 2, 30), "ThomasG77"), - (datetime.datetime(2015, 4, 14, 15, 22, 40), "therusek"), - (datetime.datetime(2015, 4, 29, 0, 9, 40), "athomann"), - (datetime.datetime(2015, 4, 29, 14, 26, 46), "jcapron"), - (datetime.datetime(2015, 5, 9, 19, 14, 45), "JoePython1"), + ( + datetime(2014, 8, 13, 19, 22, 5, tzinfo=timezone.utc), + "sAlexander", + ), + ( + datetime(2014, 10, 15, 5, 2, 30, tzinfo=timezone.utc), + "ThomasG77", + ), + ( + datetime(2015, 4, 14, 15, 22, 40, tzinfo=timezone.utc), + "therusek", + ), + ( + datetime(2015, 4, 29, 0, 9, 40, tzinfo=timezone.utc), + "athomann", + ), + ( + datetime(2015, 4, 29, 14, 26, 46, tzinfo=timezone.utc), + "jcapron", + ), + ( + datetime(2015, 5, 9, 19, 14, 45, tzinfo=timezone.utc), + "JoePython1", + ), ], ) self.assertEqual(repr(stargazers[0]), 'Stargazer(user="sAlexander")') @@ -1365,13 +1392,15 @@ class Repository(Framework.TestCase): # Attributes retrieved from legacy API without lazy completion call self.assertEqual(issues[0].number, 49) self.assertEqual( - issues[0].created_at, datetime.datetime(2012, 6, 21, 12, 27, 38) + issues[0].created_at, + datetime(2012, 6, 21, 12, 27, 38, tzinfo=timezone.utc), ) self.assertEqual(issues[0].comments, 4) self.assertEqual(issues[0].body[:20], "New API ported from ") self.assertEqual(issues[0].title, "Support new Search API") self.assertEqual( - issues[0].updated_at, datetime.datetime(2012, 6, 28, 21, 13, 25) + issues[0].updated_at, + datetime(2012, 6, 28, 21, 13, 25, tzinfo=timezone.utc), ) self.assertEqual(issues[0].user.login, "kukuts") self.assertEqual(issues[0].user.url, "/users/kukuts") @@ -1382,7 +1411,7 @@ class Repository(Framework.TestCase): def testMarkNotificationsAsRead(self): repo = self.g.get_user().get_repo("PyGithub") - repo.mark_notifications_as_read(datetime.datetime(2018, 10, 18, 18, 19, 43, 0)) + repo.mark_notifications_as_read(datetime(2018, 10, 18, 18, 19, 43, 0)) def testAssignees(self): lyloa = self.g.get_user("Lyloa") @@ -1641,9 +1670,7 @@ class Repository(Framework.TestCase): ], ) self.assertListKeyEqual( - self.repo.get_issues_comments( - since=datetime.datetime(2012, 5, 28, 23, 0, 0) - )[:40], + self.repo.get_issues_comments(since=datetime(2012, 5, 28, 23, 0, 0))[:40], lambda c: c.id, [ 5981084, @@ -1699,9 +1726,7 @@ class Repository(Framework.TestCase): [1580134], ) self.assertListKeyEqual( - self.repo.get_pulls_comments( - since=datetime.datetime(2012, 5, 28, 23, 0, 0) - ), + self.repo.get_pulls_comments(since=datetime(2012, 5, 28, 23, 0, 0)), lambda c: c.id, [1580134], ) @@ -1735,18 +1760,27 @@ class Repository(Framework.TestCase): if s.author.login == "jacquev6": seenJacquev6 = True self.assertEqual(adTotal, 282147) - self.assertEqual(s.weeks[0].w, datetime.datetime(2012, 2, 12)) + self.assertEqual( + s.weeks[0].w, + datetime(2012, 2, 12, tzinfo=timezone.utc), + ) self.assertTrue(seenJacquev6) def testStatisticsCommitActivity(self): stats = self.repo.get_stats_commit_activity() - self.assertEqual(stats[0].week, datetime.datetime(2012, 11, 18, 0, 0)) + self.assertEqual( + stats[0].week, + datetime(2012, 11, 18, 0, 0, tzinfo=timezone.utc), + ) self.assertEqual(stats[0].total, 29) self.assertEqual(stats[0].days, [0, 7, 3, 9, 7, 3, 0]) def testStatisticsCodeFrequency(self): stats = self.repo.get_stats_code_frequency() - self.assertEqual(stats[0].week, datetime.datetime(2012, 2, 12, 0, 0)) + self.assertEqual( + stats[0].week, + datetime(2012, 2, 12, 0, 0, tzinfo=timezone.utc), + ) self.assertEqual(stats[0].additions, 3853) self.assertEqual(stats[0].deletions, -2098) diff --git a/tests/RepositoryAdvisory.py b/tests/RepositoryAdvisory.py index 8c002b18..faad095a 100644 --- a/tests/RepositoryAdvisory.py +++ b/tests/RepositoryAdvisory.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone import github.RepositoryAdvisory @@ -41,7 +41,8 @@ class RepositoryAdvisory(Framework.TestCase): self.assertEqual(self.advisory.author.login, "JLLeitschuh") self.assertEqual(self.advisory.closed_at, None) self.assertEqual( - self.advisory.created_at, datetime.datetime(2023, 3, 28, 21, 41, 40) + self.advisory.created_at, + datetime(2023, 3, 28, 21, 41, 40, tzinfo=timezone.utc), ) self.assertListKeyEqual( self.advisory.credits, lambda e: (e.login, e.type), [("octocat", "analyst")] @@ -75,7 +76,8 @@ class RepositoryAdvisory(Framework.TestCase): self.assertEqual(self.advisory.state, "draft") self.assertEqual(self.advisory.summary, "A test creating a GHSA via the API") self.assertEqual( - self.advisory.updated_at, datetime.datetime(2023, 3, 30, 19, 31, 33) + self.advisory.updated_at, + datetime(2023, 3, 30, 19, 31, 33, tzinfo=timezone.utc), ) self.assertEqual( self.advisory.url, diff --git a/tests/RepositoryKey.py b/tests/RepositoryKey.py index 4e290ab5..65799217 100644 --- a/tests/RepositoryKey.py +++ b/tests/RepositoryKey.py @@ -29,7 +29,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -51,7 +51,10 @@ class RepositoryKey(Framework.TestCase): self.assertEqual( self.key.url, "https://api.github.com/repos/lra/mackup/keys/21870881" ) - self.assertEqual(self.key.created_at, datetime.datetime(2017, 2, 22, 8, 16, 23)) + self.assertEqual( + self.key.created_at, + datetime(2017, 2, 22, 8, 16, 23, tzinfo=timezone.utc), + ) self.assertTrue(self.key.verified) self.assertTrue(self.key.read_only) self.assertEqual( diff --git a/tests/Team.py b/tests/Team.py index 8812a843..37e764bb 100644 --- a/tests/Team.py +++ b/tests/Team.py @@ -34,7 +34,7 @@ import warnings -from datetime import datetime +from datetime import datetime, timezone from . import Framework @@ -75,7 +75,9 @@ class Team(Framework.TestCase): self.assertEqual( d.comments_url, "https://api.github.com/teams/189850/discussions/1/comments" ) - self.assertEqual(d.created_at, datetime(2019, 10, 8, 21, 3, 36)) + self.assertEqual( + d.created_at, datetime(2019, 10, 8, 21, 3, 36, tzinfo=timezone.utc) + ) self.assertEqual( d.html_url, "https://github.com/orgs/BeaverSoftware/teams/Team/discussions/1", @@ -87,7 +89,9 @@ class Team(Framework.TestCase): self.assertEqual(d.private, False) self.assertEqual(d.team_url, "https://api.github.com/teams/189850") self.assertEqual(d.title, "TITLE") - self.assertEqual(d.updated_at, datetime(2019, 10, 8, 21, 3, 36)) + self.assertEqual( + d.updated_at, datetime(2019, 10, 8, 21, 3, 36, tzinfo=timezone.utc) + ) self.assertEqual(d.url, "https://api.github.com/teams/189850/discussions/1") self.assertEqual(repr(d), 'TeamDiscussion(title="TITLE", number=1)') diff --git a/tests/Time.py b/tests/Time.py deleted file mode 100644 index 4743eaa3..00000000 --- a/tests/Time.py +++ /dev/null @@ -1,34 +0,0 @@ -############################ Copyrights and license ############################ -# # -# Copyright 2018 itsbruce # -# # -# This file is part of PyGithub. # -# http://pygithub.readthedocs.io/ # -# # -# PyGithub is free software: you can redistribute it and/or modify it under # -# the terms of the GNU Lesser General Public License as published by the Free # -# Software Foundation, either version 3 of the License, or (at your option) # -# any later version. # -# # -# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # -# details. # -# # -# You should have received a copy of the GNU Lesser General Public License # -# along with PyGithub. If not, see . # -# # -################################################################################ - -from datetime import timedelta, tzinfo - - -class UTCtzinfo(tzinfo): - def utcoffset(self, dt): - return timedelta(0) - - def tzname(self, dt): - return "UTC" - - def dst(self, dt): - return timedelta(0) diff --git a/tests/Topic.py b/tests/Topic.py index 8bdfeaaf..ddc8d448 100644 --- a/tests/Topic.py +++ b/tests/Topic.py @@ -21,7 +21,7 @@ ################################################################################ -from datetime import datetime +from datetime import datetime, timezone from operator import attrgetter from . import Framework @@ -47,8 +47,12 @@ class Topic(Framework.TestCase): ) self.assertEqual(topic.created_by, "Guido van Rossum") self.assertEqual(topic.released, "February 20, 1991") - self.assertEqual(topic.created_at, datetime(2016, 12, 7, 0, 7, 2)) - self.assertEqual(topic.updated_at, datetime(2019, 10, 9, 20, 33, 49)) + self.assertEqual( + topic.created_at, datetime(2016, 12, 7, 0, 7, 2, tzinfo=timezone.utc) + ) + self.assertEqual( + topic.updated_at, datetime(2019, 10, 9, 20, 33, 49, tzinfo=timezone.utc) + ) self.assertEqual(topic.featured, True) self.assertEqual(topic.curated, True) self.assertEqual(topic.score, 7576.306) diff --git a/tests/Traffic.py b/tests/Traffic.py index 7dfe6dcc..6fb76322 100644 --- a/tests/Traffic.py +++ b/tests/Traffic.py @@ -24,7 +24,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -68,10 +68,14 @@ class Traffic(Framework.TestCase): self.assertEqual(len(viewsResponse["views"]), 5) view_obj = viewsResponse["views"][0] self.assertEqual(view_obj.uniques, 4) - self.assertEqual(view_obj.timestamp, datetime.datetime(2018, 11, 27, 0, 0)) + self.assertEqual( + view_obj.timestamp, + datetime(2018, 11, 27, 0, 0, tzinfo=timezone.utc), + ) self.assertEqual(view_obj.count, 56) self.assertEqual( - repr(view_obj), "View(uniques=4, timestamp=2018-11-27 00:00:00, count=56)" + repr(view_obj), + "View(uniques=4, timestamp=2018-11-27 00:00:00+00:00, count=56)", ) def testGetClones(self): @@ -81,8 +85,12 @@ class Traffic(Framework.TestCase): self.assertEqual(len(clonesResponse["clones"]), 1) clone_obj = clonesResponse["clones"][0] self.assertEqual(clone_obj.uniques, 4) - self.assertEqual(clone_obj.timestamp, datetime.datetime(2018, 11, 27, 0, 0)) + self.assertEqual( + clone_obj.timestamp, + datetime(2018, 11, 27, 0, 0, tzinfo=timezone.utc), + ) self.assertEqual(clone_obj.count, 4) self.assertEqual( - repr(clone_obj), "Clones(uniques=4, timestamp=2018-11-27 00:00:00, count=4)" + repr(clone_obj), + "Clones(uniques=4, timestamp=2018-11-27 00:00:00+00:00, count=4)", ) diff --git a/tests/Workflow.py b/tests/Workflow.py index 4f8ead19..e424bf58 100644 --- a/tests/Workflow.py +++ b/tests/Workflow.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -39,7 +39,7 @@ class Workflow(Framework.TestCase): self.assertEqual(self.workflow.name, "check") self.assertEqual(self.workflow.path, ".github/workflows/check.yml") self.assertEqual(self.workflow.state, "active") - timestamp = datetime.datetime(2020, 4, 15, 0, 48, 32) + timestamp = datetime(2020, 4, 15, 0, 48, 32, tzinfo=timezone.utc) self.assertEqual(self.workflow.created_at, timestamp) self.assertEqual(self.workflow.updated_at, timestamp) self.assertEqual( diff --git a/tests/WorkflowJob.py b/tests/WorkflowJob.py index 7722a8ba..07758940 100644 --- a/tests/WorkflowJob.py +++ b/tests/WorkflowJob.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -50,9 +50,9 @@ class WorkflowJob(Framework.TestCase): ) self.assertEqual(self.job.status, "completed") self.assertEqual(self.job.conclusion, "success") - started_at = datetime.datetime(2023, 2, 17, 16, 3, 46) + started_at = datetime(2023, 2, 17, 16, 3, 46, tzinfo=timezone.utc) self.assertEqual(self.job.started_at, started_at) - completed_at = datetime.datetime(2023, 2, 17, 16, 4, 52) + completed_at = datetime(2023, 2, 17, 16, 4, 52, tzinfo=timezone.utc) self.assertEqual(self.job.completed_at, completed_at) self.assertEqual(self.job.name, "test (Python 3.7)") self.assertEqual( diff --git a/tests/WorkflowRun.py b/tests/WorkflowRun.py index 0b6054d7..e00ecb68 100644 --- a/tests/WorkflowRun.py +++ b/tests/WorkflowRun.py @@ -20,7 +20,7 @@ # # ################################################################################ -import datetime +from datetime import datetime, timezone from . import Framework @@ -47,7 +47,8 @@ class WorkflowRun(Framework.TestCase): self.assertEqual(self.workflow_run.run_number, 930) self.assertEqual(self.workflow_run.run_attempt, 1) self.assertEqual( - self.workflow_run.run_started_at, datetime.datetime(2023, 1, 10, 8, 24, 19) + self.workflow_run.run_started_at, + datetime(2023, 1, 10, 8, 24, 19, tzinfo=timezone.utc), ) self.assertEqual(self.workflow_run.event, "pull_request") self.assertEqual(self.workflow_run.status, "completed") @@ -62,9 +63,9 @@ class WorkflowRun(Framework.TestCase): "https://github.com/PyGithub/PyGithub/actions/runs/3881497935", ) self.assertEqual(self.workflow_run.pull_requests, []) - created_at = datetime.datetime(2023, 1, 10, 8, 24, 19) + created_at = datetime(2023, 1, 10, 8, 24, 19, tzinfo=timezone.utc) self.assertEqual(self.workflow_run.created_at, created_at) - updated_at = datetime.datetime(2023, 1, 10, 8, 28, 20) + updated_at = datetime(2023, 1, 10, 8, 28, 20, tzinfo=timezone.utc) self.assertEqual(self.workflow_run.updated_at, updated_at) self.assertEqual( self.workflow_run.jobs_url,