diff --git a/.flake8 b/.flake8 index 7c8d8fa0..a9b6f3bb 100644 --- a/.flake8 +++ b/.flake8 @@ -1,2 +1,4 @@ [flake8] -ignore = E501,E266,W503 +max-line-length = 88 +select = C,E,F,W +ignore = E203, E266, E501, W503 diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..0ac773da --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,6 @@ +[settings] +multi_line_output=3 +include_trailing_comma=True +force_grid_wrap=0 +use_parentheses=True +line_length=88 \ No newline at end of file diff --git a/README.md b/README.md index de273834..23c18c53 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![Join the chat at https://gitter.im/PyGithub/PyGithub](https://badges.gitter.im/PyGithub/PyGithub.svg)](https://gitter.im/PyGithub/PyGithub?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Open Source Helpers](https://www.codetriage.com/pygithub/pygithub/badges/users.svg)](https://www.codetriage.com/pygithub/pygithub) [![codecov](https://codecov.io/gh/PyGithub/PyGithub/branch/master/graph/badge.svg)](https://codecov.io/gh/PyGithub/PyGithub) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) PyGitHub is a Python (2 and 3) library to access the [GitHub API v3] and [Github Enterprise API v3]. This library enables you to manage [GitHub] resources such as repositories, user profiles, and organizations in your Python applications. diff --git a/doc/conf.py b/doc/conf.py index 3bbc4048..d36f9bff 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -28,16 +28,17 @@ # # ################################################################################ -import sys -import os -import glob import datetime +import glob +import os +import sys + +from setup import version as setupVersion # noqa: E402 # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('..')) -from setup import version as setupVersion # noqa: E402 +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ----------------------------------------------------- @@ -46,23 +47,23 @@ from setup import version as setupVersion # noqa: E402 # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.mathjax'] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.mathjax"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'PyGithub' -copyright = u'%d, Vincent Jacques' % datetime.date.today().year +project = u"PyGithub" +copyright = u"%d, Vincent Jacques" % datetime.date.today().year # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -102,7 +103,7 @@ exclude_patterns = [] # show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] @@ -112,7 +113,7 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -141,7 +142,7 @@ html_theme = 'sphinx_rtd_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. @@ -185,7 +186,7 @@ html_static_path = ['_static'] # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'PyGithubdoc' +htmlhelp_basename = "PyGithubdoc" # -- Options for LaTeX output -------------------------------------------------- @@ -204,8 +205,7 @@ htmlhelp_basename = 'PyGithubdoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'PyGithub.tex', u'PyGithub Documentation', - u'Vincent Jacques', 'manual'), + ("index", "PyGithub.tex", u"PyGithub Documentation", u"Vincent Jacques", "manual"), ] # The name of an image file (relative to this directory) to place at the top of @@ -233,10 +233,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'pygithub', u'PyGithub Documentation', - [u'Vincent Jacques'], 1) -] +man_pages = [("index", "pygithub", u"PyGithub Documentation", [u"Vincent Jacques"], 1)] # If true, show URL addresses after external links. # man_show_urls = False @@ -248,9 +245,15 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'PyGithub', u'PyGithub Documentation', - u'Vincent Jacques', 'PyGithub', 'One line description of project.', - 'Miscellaneous'), + ( + "index", + "PyGithub", + u"PyGithub Documentation", + u"Vincent Jacques", + "PyGithub", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. @@ -269,7 +272,8 @@ autoclass_content = "both" githubClasses = [ fileName[10:-3] for fileName in sorted(glob.glob("../github/*.py")) - if fileName not in [ + if fileName + not in [ "../github/GithubException.py", "../github/GithubObject.py", "../github/InputFileContent.py", @@ -280,7 +284,8 @@ githubClasses = [ "../github/PaginatedList.py", "../github/Requester.py", "../github/Consts.py", - "../github/__init__.py"] + "../github/__init__.py", + ] ] with open("github_objects.rst", "w") as f: @@ -316,7 +321,22 @@ for githubClass in githubClasses + ["MainClass"]: if line.startswith(" def "): if not isProperty: method = line.split("(")[0][8:] - if method in ["_initAttributes", "_useAttributes", "__init__", "__create_pull_1", "__create_pull_2", "__create_pull", "_hub", "__get_FIX_REPO_GET_GIT_REF", "__set_FIX_REPO_GET_GIT_REF", "__get_per_page", "__set_per_page", "create_from_raw_data", "dump", "load"]: + if method in [ + "_initAttributes", + "_useAttributes", + "__init__", + "__create_pull_1", + "__create_pull_2", + "__create_pull", + "_hub", + "__get_FIX_REPO_GET_GIT_REF", + "__set_FIX_REPO_GET_GIT_REF", + "__get_per_page", + "__set_per_page", + "create_from_raw_data", + "dump", + "load", + ]: method = None isProperty = False if line.startswith(" :calls: `"): @@ -343,5 +363,7 @@ with open("apis.rst", "w") as apis: apis.write("\n") for verb in ["GET", "PATCH", "POST", "PUT", "DELETE"]: if verb in verbs: - apis.write(" * " + verb + ": " + " or ".join(sorted(verbs[verb])) + "\n") + apis.write( + " * " + verb + ": " + " or ".join(sorted(verbs[verb])) + "\n" + ) apis.write("\n") diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index d675c690..ebbfcc0c 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -41,26 +41,27 @@ ################################################################################ from __future__ import absolute_import + import datetime -import github.GithubObject -import github.PaginatedList -import github.Invitation -import github.Gist -import github.Repository -import github.NamedUser -import github.Plan -import github.Organization -import github.UserKey -import github.Issue -import github.Event import github.Authorization -import github.Notification -import github.Migration +import github.Event +import github.Gist +import github.GithubObject +import github.Invitation +import github.Issue import github.Membership +import github.Migration +import github.NamedUser +import github.Notification +import github.Organization +import github.PaginatedList +import github.Plan +import github.Repository +import github.UserKey +import six from . import Consts -import six class AuthenticatedUser(github.GithubObject.CompletableGithubObject): @@ -375,12 +376,12 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param email: string :rtype: None """ - assert all(isinstance(element, (str, six.text_type)) for element in emails), emails + assert all( + isinstance(element, (str, six.text_type)) for element in emails + ), emails post_parameters = emails headers, data = self._requester.requestJsonAndCheck( - "POST", - "/user/emails", - input=post_parameters + "POST", "/user/emails", input=post_parameters ) def add_to_following(self, following): @@ -391,8 +392,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(following, github.NamedUser.NamedUser), following headers, data = self._requester.requestJsonAndCheck( - "PUT", - "/user/following/" + following._identity + "PUT", "/user/following/" + following._identity ) def add_to_starred(self, starred): @@ -403,8 +403,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(starred, github.Repository.Repository), starred headers, data = self._requester.requestJsonAndCheck( - "PUT", - "/user/starred/" + starred._identity + "PUT", "/user/starred/" + starred._identity ) def add_to_subscriptions(self, subscription): @@ -415,8 +414,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(subscription, github.Repository.Repository), subscription headers, data = self._requester.requestJsonAndCheck( - "PUT", - "/user/subscriptions/" + subscription._identity + "PUT", "/user/subscriptions/" + subscription._identity ) def add_to_watched(self, watched): @@ -429,10 +427,18 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "PUT", "/repos/" + watched._identity + "/subscription", - input={"subscribed": True} + input={"subscribed": True}, ) - def create_authorization(self, scopes=github.GithubObject.NotSet, note=github.GithubObject.NotSet, note_url=github.GithubObject.NotSet, client_id=github.GithubObject.NotSet, client_secret=github.GithubObject.NotSet, onetime_password=None): + def create_authorization( + self, + scopes=github.GithubObject.NotSet, + note=github.GithubObject.NotSet, + note_url=github.GithubObject.NotSet, + client_id=github.GithubObject.NotSet, + client_secret=github.GithubObject.NotSet, + onetime_password=None, + ): """ :calls: `POST /authorizations `_ :param scopes: list of string @@ -443,12 +449,24 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param onetime_password: string :rtype: :class:`github.Authorization.Authorization` """ - assert scopes is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in scopes), scopes - assert note is github.GithubObject.NotSet or isinstance(note, (str, six.text_type)), note - assert note_url is github.GithubObject.NotSet or isinstance(note_url, (str, six.text_type)), note_url - assert client_id is github.GithubObject.NotSet or isinstance(client_id, (str, six.text_type)), client_id - assert client_secret is github.GithubObject.NotSet or isinstance(client_secret, (str, six.text_type)), client_secret - assert onetime_password is None or isinstance(onetime_password, (str, six.text_type)), onetime_password + assert scopes is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in scopes + ), scopes + assert note is github.GithubObject.NotSet or isinstance( + note, (str, six.text_type) + ), note + assert note_url is github.GithubObject.NotSet or isinstance( + note_url, (str, six.text_type) + ), note_url + assert client_id is github.GithubObject.NotSet or isinstance( + client_id, (str, six.text_type) + ), client_id + assert client_secret is github.GithubObject.NotSet or isinstance( + client_secret, (str, six.text_type) + ), client_secret + assert onetime_password is None or isinstance( + onetime_password, (str, six.text_type) + ), onetime_password post_parameters = dict() if scopes is not github.GithubObject.NotSet: post_parameters["scopes"] = scopes @@ -461,16 +479,17 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if client_secret is not github.GithubObject.NotSet: post_parameters["client_secret"] = client_secret if onetime_password is not None: - request_header = {Consts.headerOTP: onetime_password} # pragma no cover (Should be covered) + request_header = { + Consts.headerOTP: onetime_password + } # pragma no cover (Should be covered) else: request_header = None headers, data = self._requester.requestJsonAndCheck( - "POST", - "/authorizations", - input=post_parameters, - headers=request_header, + "POST", "/authorizations", input=post_parameters, headers=request_header, + ) + return github.Authorization.Authorization( + self._requester, headers, data, completed=True ) - return github.Authorization.Authorization(self._requester, headers, data, completed=True) def create_fork(self, repo): """ @@ -480,10 +499,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(repo, github.Repository.Repository), repo headers, data = self._requester.requestJsonAndCheck( - "POST", - "/repos/" + repo.owner.login + "/" + repo.name + "/forks" + "POST", "/repos/" + repo.owner.login + "/" + repo.name + "/forks" + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) def create_gist(self, public, files, description=github.GithubObject.NotSet): """ @@ -494,8 +514,13 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Gist.Gist` """ assert isinstance(public, bool), public - assert all(isinstance(element, github.InputFileContent) for element in six.itervalues(files)), files - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description + assert all( + isinstance(element, github.InputFileContent) + for element in six.itervalues(files) + ), files + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description post_parameters = { "public": public, "files": {key: value._identity for key, value in six.iteritems(files)}, @@ -503,9 +528,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if description is not github.GithubObject.NotSet: post_parameters["description"] = description headers, data = self._requester.requestJsonAndCheck( - "POST", - "/gists", - input=post_parameters + "POST", "/gists", input=post_parameters ) return github.Gist.Gist(self._requester, headers, data, completed=True) @@ -523,18 +546,27 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): "key": key, } headers, data = self._requester.requestJsonAndCheck( - "POST", - "/user/keys", - input=post_parameters + "POST", "/user/keys", input=post_parameters ) return github.UserKey.UserKey(self._requester, headers, data, completed=True) - def create_repo(self, name, description=github.GithubObject.NotSet, homepage=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, has_issues=github.GithubObject.NotSet, - has_wiki=github.GithubObject.NotSet, has_downloads=github.GithubObject.NotSet, - has_projects=github.GithubObject.NotSet, auto_init=github.GithubObject.NotSet, license_template=github.GithubObject.NotSet, - gitignore_template=github.GithubObject.NotSet, allow_squash_merge=github.GithubObject.NotSet, - allow_merge_commit=github.GithubObject.NotSet, allow_rebase_merge=github.GithubObject.NotSet): + def create_repo( + self, + name, + description=github.GithubObject.NotSet, + homepage=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + has_issues=github.GithubObject.NotSet, + has_wiki=github.GithubObject.NotSet, + has_downloads=github.GithubObject.NotSet, + has_projects=github.GithubObject.NotSet, + auto_init=github.GithubObject.NotSet, + license_template=github.GithubObject.NotSet, + gitignore_template=github.GithubObject.NotSet, + allow_squash_merge=github.GithubObject.NotSet, + allow_merge_commit=github.GithubObject.NotSet, + allow_rebase_merge=github.GithubObject.NotSet, + ): """ :calls: `POST /user/repos `_ :param name: string @@ -554,19 +586,45 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Repository.Repository` """ assert isinstance(name, (str, six.text_type)), name - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert homepage is github.GithubObject.NotSet or isinstance(homepage, (str, six.text_type)), homepage - assert private is github.GithubObject.NotSet or isinstance(private, bool), private - assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues - assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki - assert has_downloads is github.GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads - assert has_projects is github.GithubObject.NotSet or isinstance(has_projects, bool), has_projects - assert auto_init is github.GithubObject.NotSet or isinstance(auto_init, bool), auto_init - assert license_template is github.GithubObject.NotSet or isinstance(license_template, (str, six.text_type)), license_template - assert gitignore_template is github.GithubObject.NotSet or isinstance(gitignore_template, (str, six.text_type)), gitignore_template - assert allow_squash_merge is github.GithubObject.NotSet or isinstance(allow_squash_merge, bool), allow_squash_merge - assert allow_merge_commit is github.GithubObject.NotSet or isinstance(allow_merge_commit, bool), allow_merge_commit - assert allow_rebase_merge is github.GithubObject.NotSet or isinstance(allow_rebase_merge, bool), allow_rebase_merge + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert homepage is github.GithubObject.NotSet or isinstance( + homepage, (str, six.text_type) + ), homepage + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + assert has_issues is github.GithubObject.NotSet or isinstance( + has_issues, bool + ), has_issues + assert has_wiki is github.GithubObject.NotSet or isinstance( + has_wiki, bool + ), has_wiki + assert has_downloads is github.GithubObject.NotSet or isinstance( + has_downloads, bool + ), has_downloads + assert has_projects is github.GithubObject.NotSet or isinstance( + has_projects, bool + ), has_projects + assert auto_init is github.GithubObject.NotSet or isinstance( + auto_init, bool + ), auto_init + assert license_template is github.GithubObject.NotSet or isinstance( + license_template, (str, six.text_type) + ), license_template + assert gitignore_template is github.GithubObject.NotSet or isinstance( + gitignore_template, (str, six.text_type) + ), gitignore_template + assert allow_squash_merge is github.GithubObject.NotSet or isinstance( + allow_squash_merge, bool + ), allow_squash_merge + assert allow_merge_commit is github.GithubObject.NotSet or isinstance( + allow_merge_commit, bool + ), allow_merge_commit + assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( + allow_rebase_merge, bool + ), allow_rebase_merge post_parameters = { "name": name, } @@ -597,13 +655,22 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if allow_rebase_merge is not github.GithubObject.NotSet: post_parameters["allow_rebase_merge"] = allow_rebase_merge headers, data = self._requester.requestJsonAndCheck( - "POST", - "/user/repos", - input=post_parameters + "POST", "/user/repos", input=post_parameters + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) - def edit(self, name=github.GithubObject.NotSet, email=github.GithubObject.NotSet, blog=github.GithubObject.NotSet, company=github.GithubObject.NotSet, location=github.GithubObject.NotSet, hireable=github.GithubObject.NotSet, bio=github.GithubObject.NotSet): + def edit( + self, + name=github.GithubObject.NotSet, + email=github.GithubObject.NotSet, + blog=github.GithubObject.NotSet, + company=github.GithubObject.NotSet, + location=github.GithubObject.NotSet, + hireable=github.GithubObject.NotSet, + bio=github.GithubObject.NotSet, + ): """ :calls: `PATCH /user `_ :param name: string @@ -615,13 +682,27 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param bio: string :rtype: None """ - assert name is github.GithubObject.NotSet or isinstance(name, (str, six.text_type)), name - assert email is github.GithubObject.NotSet or isinstance(email, (str, six.text_type)), email - assert blog is github.GithubObject.NotSet or isinstance(blog, (str, six.text_type)), blog - assert company is github.GithubObject.NotSet or isinstance(company, (str, six.text_type)), company - assert location is github.GithubObject.NotSet or isinstance(location, (str, six.text_type)), location - assert hireable is github.GithubObject.NotSet or isinstance(hireable, bool), hireable - assert bio is github.GithubObject.NotSet or isinstance(bio, (str, six.text_type)), bio + assert name is github.GithubObject.NotSet or isinstance( + name, (str, six.text_type) + ), name + assert email is github.GithubObject.NotSet or isinstance( + email, (str, six.text_type) + ), email + assert blog is github.GithubObject.NotSet or isinstance( + blog, (str, six.text_type) + ), blog + assert company is github.GithubObject.NotSet or isinstance( + company, (str, six.text_type) + ), company + assert location is github.GithubObject.NotSet or isinstance( + location, (str, six.text_type) + ), location + assert hireable is github.GithubObject.NotSet or isinstance( + hireable, bool + ), hireable + assert bio is github.GithubObject.NotSet or isinstance( + bio, (str, six.text_type) + ), bio post_parameters = dict() if name is not github.GithubObject.NotSet: post_parameters["name"] = name @@ -638,9 +719,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if bio is not github.GithubObject.NotSet: post_parameters["bio"] = bio headers, data = self._requester.requestJsonAndCheck( - "PATCH", - "/user", - input=post_parameters + "PATCH", "/user", input=post_parameters ) self._useAttributes(data) @@ -652,10 +731,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - "/authorizations/" + str(id) + "GET", "/authorizations/" + str(id) + ) + return github.Authorization.Authorization( + self._requester, headers, data, completed=True ) - return github.Authorization.Authorization(self._requester, headers, data, completed=True) def get_authorizations(self): """ @@ -663,10 +743,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Authorization.Authorization` """ return github.PaginatedList.PaginatedList( - github.Authorization.Authorization, - self._requester, - "/authorizations", - None + github.Authorization.Authorization, self._requester, "/authorizations", None ) def get_emails(self): @@ -674,10 +751,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :calls: `GET /user/emails `_ :rtype: list of string """ - headers, data = self._requester.requestJsonAndCheck( - "GET", - "/user/emails" - ) + headers, data = self._requester.requestJsonAndCheck("GET", "/user/emails") return data def get_events(self): @@ -686,10 +760,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - "/events", - None + github.Event.Event, self._requester, "/events", None ) def get_followers(self): @@ -698,10 +769,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - "/user/followers", - None + github.NamedUser.NamedUser, self._requester, "/user/followers", None ) def get_following(self): @@ -710,10 +778,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - "/user/following", - None + github.NamedUser.NamedUser, self._requester, "/user/following", None ) def get_gists(self, since=github.GithubObject.NotSet): @@ -722,18 +787,25 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param since: datetime.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.datetime + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Gist.Gist, - self._requester, - "/gists", - url_parameters + github.Gist.Gist, self._requester, "/gists", url_parameters ) - def get_issues(self, filter=github.GithubObject.NotSet, state=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): + def get_issues( + self, + filter=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): """ :calls: `GET /issues `_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` @@ -745,12 +817,24 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param since: datetime.datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ - assert filter is github.GithubObject.NotSet or isinstance(filter, (str, six.text_type)), filter - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert filter is github.GithubObject.NotSet or isinstance( + filter, (str, six.text_type) + ), filter + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) for element in labels + ), labels + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -765,13 +849,18 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Issue.Issue, - self._requester, - "/issues", - url_parameters + github.Issue.Issue, self._requester, "/issues", url_parameters ) - def get_user_issues(self, filter=github.GithubObject.NotSet, state=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): + def get_user_issues( + self, + filter=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): """ :calls: `GET /user/issues `_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` @@ -783,12 +872,24 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param since: datetime.datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ - assert filter is github.GithubObject.NotSet or isinstance(filter, (str, six.text_type)), filter - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert filter is github.GithubObject.NotSet or isinstance( + filter, (str, six.text_type) + ), filter + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) for element in labels + ), labels + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -803,10 +904,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Issue.Issue, - self._requester, - "/issues", - url_parameters + github.Issue.Issue, self._requester, "/issues", url_parameters ) def get_key(self, id): @@ -817,8 +915,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - "/user/keys/" + str(id) + "GET", "/user/keys/" + str(id) ) return github.UserKey.UserKey(self._requester, headers, data, completed=True) @@ -828,10 +925,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.UserKey.UserKey` """ return github.PaginatedList.PaginatedList( - github.UserKey.UserKey, - self._requester, - "/user/keys", - None + github.UserKey.UserKey, self._requester, "/user/keys", None ) def get_notification(self, id): @@ -842,12 +936,19 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): assert isinstance(id, (str, six.text_type)), id headers, data = self._requester.requestJsonAndCheck( - "GET", - "/notifications/threads/" + id + "GET", "/notifications/threads/" + id + ) + return github.Notification.Notification( + self._requester, headers, data, completed=True ) - return github.Notification.Notification(self._requester, headers, data, completed=True) - def get_notifications(self, all=github.GithubObject.NotSet, participating=github.GithubObject.NotSet, since=github.GithubObject.NotSet, before=github.GithubObject.NotSet): + def get_notifications( + self, + all=github.GithubObject.NotSet, + participating=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + before=github.GithubObject.NotSet, + ): """ :calls: `GET /notifications `_ :param all: bool @@ -858,9 +959,15 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert all is github.GithubObject.NotSet or isinstance(all, bool), all - assert participating is github.GithubObject.NotSet or isinstance(participating, bool), participating - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since - assert before is github.GithubObject.NotSet or isinstance(before, datetime.datetime), before + assert participating is github.GithubObject.NotSet or isinstance( + participating, bool + ), participating + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert before is github.GithubObject.NotSet or isinstance( + before, datetime.datetime + ), before params = dict() if all is not github.GithubObject.NotSet: @@ -873,10 +980,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Notification.Notification, - self._requester, - "/notifications", - params + github.Notification.Notification, self._requester, "/notifications", params ) def get_organization_events(self, org): @@ -890,7 +994,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): github.Event.Event, self._requester, "/users/" + self.login + "/events/orgs/" + org.login, - None + None, ) def get_orgs(self): @@ -899,10 +1003,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization` """ return github.PaginatedList.PaginatedList( - github.Organization.Organization, - self._requester, - "/user/orgs", - None + github.Organization.Organization, self._requester, "/user/orgs", None ) def get_repo(self, name): @@ -913,12 +1014,20 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name headers, data = self._requester.requestJsonAndCheck( - "GET", - "/repos/" + self.login + "/" + name + "GET", "/repos/" + self.login + "/" + name + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) - def get_repos(self, visibility=github.GithubObject.NotSet, affiliation=github.GithubObject.NotSet, type=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet): + def get_repos( + self, + visibility=github.GithubObject.NotSet, + affiliation=github.GithubObject.NotSet, + type=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + ): """ :calls: `GET /user/repos ` :param visibility: string @@ -928,11 +1037,21 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param direction: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - assert visibility is github.GithubObject.NotSet or isinstance(visibility, (str, six.text_type)), visibility - assert affiliation is github.GithubObject.NotSet or isinstance(affiliation, (str, six.text_type)), affiliation - assert type is github.GithubObject.NotSet or isinstance(type, (str, six.text_type)), type - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction + assert visibility is github.GithubObject.NotSet or isinstance( + visibility, (str, six.text_type) + ), visibility + assert affiliation is github.GithubObject.NotSet or isinstance( + affiliation, (str, six.text_type) + ), affiliation + assert type is github.GithubObject.NotSet or isinstance( + type, (str, six.text_type) + ), type + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction url_parameters = dict() if visibility is not github.GithubObject.NotSet: url_parameters["visibility"] = visibility @@ -945,10 +1064,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if direction is not github.GithubObject.NotSet: url_parameters["direction"] = direction return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - "/user/repos", - url_parameters + github.Repository.Repository, self._requester, "/user/repos", url_parameters ) def get_starred(self): @@ -957,10 +1073,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - "/user/starred", - None + github.Repository.Repository, self._requester, "/user/starred", None ) def get_starred_gists(self): @@ -969,10 +1082,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ return github.PaginatedList.PaginatedList( - github.Gist.Gist, - self._requester, - "/gists/starred", - None + github.Gist.Gist, self._requester, "/gists/starred", None ) def get_subscriptions(self): @@ -981,10 +1091,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - "/user/subscriptions", - None + github.Repository.Repository, self._requester, "/user/subscriptions", None ) def get_teams(self): @@ -993,10 +1100,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` """ return github.PaginatedList.PaginatedList( - github.Team.Team, - self._requester, - "/user/teams", - None + github.Team.Team, self._requester, "/user/teams", None ) def get_watched(self): @@ -1005,10 +1109,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - "/user/subscriptions", - None + github.Repository.Repository, self._requester, "/user/subscriptions", None ) def has_in_following(self, following): @@ -1019,8 +1120,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(following, github.NamedUser.NamedUser), following status, headers, data = self._requester.requestJson( - "GET", - "/user/following/" + following._identity + "GET", "/user/following/" + following._identity ) return status == 204 @@ -1032,8 +1132,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(starred, github.Repository.Repository), starred status, headers, data = self._requester.requestJson( - "GET", - "/user/starred/" + starred._identity + "GET", "/user/starred/" + starred._identity ) return status == 204 @@ -1045,8 +1144,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(subscription, github.Repository.Repository), subscription status, headers, data = self._requester.requestJson( - "GET", - "/user/subscriptions/" + subscription._identity + "GET", "/user/subscriptions/" + subscription._identity ) return status == 204 @@ -1058,8 +1156,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(watched, github.Repository.Repository), watched status, headers, data = self._requester.requestJson( - "GET", - "/repos/" + watched._identity + "/subscription" + "GET", "/repos/" + watched._identity + "/subscription" ) return status == 200 @@ -1069,14 +1166,10 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param last_read_at: datetime """ assert isinstance(last_read_at, datetime.datetime) - put_parameters = { - "last_read_at": last_read_at.strftime('%Y-%m-%dT%H:%M:%SZ') - } + put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} headers, data = self._requester.requestJsonAndCheck( - "PUT", - "/notifications", - input=put_parameters + "PUT", "/notifications", input=put_parameters ) def remove_from_emails(self, *emails): @@ -1085,12 +1178,12 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param email: string :rtype: None """ - assert all(isinstance(element, (str, six.text_type)) for element in emails), emails + assert all( + isinstance(element, (str, six.text_type)) for element in emails + ), emails post_parameters = emails headers, data = self._requester.requestJsonAndCheck( - "DELETE", - "/user/emails", - input=post_parameters + "DELETE", "/user/emails", input=post_parameters ) def remove_from_following(self, following): @@ -1101,8 +1194,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(following, github.NamedUser.NamedUser), following headers, data = self._requester.requestJsonAndCheck( - "DELETE", - "/user/following/" + following._identity + "DELETE", "/user/following/" + following._identity ) def remove_from_starred(self, starred): @@ -1113,8 +1205,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(starred, github.Repository.Repository), starred headers, data = self._requester.requestJsonAndCheck( - "DELETE", - "/user/starred/" + starred._identity + "DELETE", "/user/starred/" + starred._identity ) def remove_from_subscriptions(self, subscription): @@ -1125,8 +1216,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(subscription, github.Repository.Repository), subscription headers, data = self._requester.requestJsonAndCheck( - "DELETE", - "/user/subscriptions/" + subscription._identity + "DELETE", "/user/subscriptions/" + subscription._identity ) def remove_from_watched(self, watched): @@ -1137,8 +1227,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(watched, github.Repository.Repository), watched headers, data = self._requester.requestJsonAndCheck( - "DELETE", - "/repos/" + watched._identity + "/subscription" + "DELETE", "/repos/" + watched._identity + "/subscription" ) def accept_invitation(self, invitation): @@ -1147,15 +1236,15 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): :param invitation: :class:`github.Invitation.Invitation` or int :rtype: None """ - assert isinstance(invitation, github.Invitation.Invitation) or isinstance(invitation, int) + assert isinstance(invitation, github.Invitation.Invitation) or isinstance( + invitation, int + ) if isinstance(invitation, github.Invitation.Invitation): invitation = invitation.id headers, data = self._requester.requestJsonAndCheck( - "PATCH", - "/user/repository_invitations/" + str(invitation), - input={} + "PATCH", "/user/repository_invitations/" + str(invitation), input={} ) def get_invitations(self): @@ -1170,7 +1259,12 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): None, ) - def create_migration(self, repos, lock_repositories=github.GithubObject.NotSet, exclude_attachments=github.GithubObject.NotSet): + def create_migration( + self, + repos, + lock_repositories=github.GithubObject.NotSet, + exclude_attachments=github.GithubObject.NotSet, + ): """ :calls: `POST /user/migrations`_ :param repos: list or tuple of str @@ -1180,11 +1274,13 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(repos, (list, tuple)), repos assert all(isinstance(repo, (str, six.text_type)) for repo in repos), repos - assert lock_repositories is github.GithubObject.NotSet or isinstance(lock_repositories, bool), lock_repositories - assert exclude_attachments is github.GithubObject.NotSet or isinstance(exclude_attachments, bool), exclude_attachments - post_parameters = { - "repositories": repos - } + assert lock_repositories is github.GithubObject.NotSet or isinstance( + lock_repositories, bool + ), lock_repositories + assert exclude_attachments is github.GithubObject.NotSet or isinstance( + exclude_attachments, bool + ), exclude_attachments + post_parameters = {"repositories": repos} if lock_repositories is not github.GithubObject.NotSet: post_parameters["lock_repositories"] = lock_repositories if exclude_attachments is not github.GithubObject.NotSet: @@ -1193,11 +1289,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): "POST", "/user/migrations", input=post_parameters, - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, + ) + return github.Migration.Migration( + self._requester, headers, data, completed=True ) - return github.Migration.Migration(self._requester, headers, data, completed=True) def get_migrations(self): """ @@ -1209,9 +1305,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): self._requester, "/user/migrations", None, - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, ) def get_organization_membership(self, org): @@ -1221,10 +1315,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(org, int) headers, data = self._requester.requestJsonAndCheck( - "GET", - "/user/memberships/orgs/" + str(org) + "GET", "/user/memberships/orgs/" + str(org) + ) + return github.Membership.Membership( + self._requester, headers, data, completed=True ) - return github.Membership.Membership(self._requester, headers, data, completed=True) def _initAttributes(self): self._avatar_url = github.GithubObject.NotSet @@ -1311,9 +1406,13 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if "node_id" in attributes: # pragma no branch self._node_id = self._makeStringAttribute(attributes["node_id"]) if "organizations_url" in attributes: # pragma no branch - self._organizations_url = self._makeStringAttribute(attributes["organizations_url"]) + self._organizations_url = self._makeStringAttribute( + attributes["organizations_url"] + ) if "owned_private_repos" in attributes: # pragma no branch - self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"]) + self._owned_private_repos = self._makeIntAttribute( + attributes["owned_private_repos"] + ) if "plan" in attributes: # pragma no branch self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"]) if "private_gists" in attributes: # pragma no branch @@ -1323,7 +1422,9 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if "public_repos" in attributes: # pragma no branch self._public_repos = self._makeIntAttribute(attributes["public_repos"]) if "received_events_url" in attributes: # pragma no branch - self._received_events_url = self._makeStringAttribute(attributes["received_events_url"]) + self._received_events_url = self._makeStringAttribute( + attributes["received_events_url"] + ) if "repos_url" in attributes: # pragma no branch self._repos_url = self._makeStringAttribute(attributes["repos_url"]) if "site_admin" in attributes: # pragma no branch @@ -1331,9 +1432,13 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): if "starred_url" in attributes: # pragma no branch self._starred_url = self._makeStringAttribute(attributes["starred_url"]) if "subscriptions_url" in attributes: # pragma no branch - self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"]) + self._subscriptions_url = self._makeStringAttribute( + attributes["subscriptions_url"] + ) if "total_private_repos" in attributes: # pragma no branch - self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"]) + self._total_private_repos = self._makeIntAttribute( + attributes["total_private_repos"] + ) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "updated_at" in attributes: # pragma no branch diff --git a/github/Authorization.py b/github/Authorization.py index faea16ca..f5bfe280 100644 --- a/github/Authorization.py +++ b/github/Authorization.py @@ -31,9 +31,9 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.AuthorizationApplication +import github.GithubObject import six @@ -122,12 +122,16 @@ class Authorization(github.GithubObject.CompletableGithubObject): :calls: `DELETE /authorizations/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, scopes=github.GithubObject.NotSet, add_scopes=github.GithubObject.NotSet, remove_scopes=github.GithubObject.NotSet, note=github.GithubObject.NotSet, note_url=github.GithubObject.NotSet): + def edit( + self, + scopes=github.GithubObject.NotSet, + add_scopes=github.GithubObject.NotSet, + remove_scopes=github.GithubObject.NotSet, + note=github.GithubObject.NotSet, + note_url=github.GithubObject.NotSet, + ): """ :calls: `PATCH /authorizations/:id `_ :param scopes: list of string @@ -137,11 +141,21 @@ class Authorization(github.GithubObject.CompletableGithubObject): :param note_url: string :rtype: None """ - assert scopes is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in scopes), scopes - assert add_scopes is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in add_scopes), add_scopes - assert remove_scopes is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in remove_scopes), remove_scopes - assert note is github.GithubObject.NotSet or isinstance(note, (str, six.text_type)), note - assert note_url is github.GithubObject.NotSet or isinstance(note_url, (str, six.text_type)), note_url + assert scopes is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in scopes + ), scopes + assert add_scopes is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in add_scopes + ), add_scopes + assert remove_scopes is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in remove_scopes + ), remove_scopes + assert note is github.GithubObject.NotSet or isinstance( + note, (str, six.text_type) + ), note + assert note_url is github.GithubObject.NotSet or isinstance( + note_url, (str, six.text_type) + ), note_url post_parameters = dict() if scopes is not github.GithubObject.NotSet: post_parameters["scopes"] = scopes @@ -154,9 +168,7 @@ class Authorization(github.GithubObject.CompletableGithubObject): if note_url is not github.GithubObject.NotSet: post_parameters["note_url"] = note_url headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -173,7 +185,10 @@ class Authorization(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "app" in attributes: # pragma no branch - self._app = self._makeClassAttribute(github.AuthorizationApplication.AuthorizationApplication, attributes["app"]) + self._app = self._makeClassAttribute( + github.AuthorizationApplication.AuthorizationApplication, + attributes["app"], + ) if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "id" in attributes: # pragma no branch diff --git a/github/AuthorizationApplication.py b/github/AuthorizationApplication.py index ab3e93e5..92d98f3b 100644 --- a/github/AuthorizationApplication.py +++ b/github/AuthorizationApplication.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/Branch.py b/github/Branch.py index a6cdeea8..9e1a0695 100644 --- a/github/Branch.py +++ b/github/Branch.py @@ -34,15 +34,15 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.BranchProtection import github.Commit +import github.GithubObject import github.RequiredPullRequestReviews import github.RequiredStatusChecks +import six from . import Consts -import six class Branch(github.GithubObject.NonCompletableGithubObject): @@ -89,11 +89,15 @@ class Branch(github.GithubObject.NonCompletableGithubObject): def _useAttributes(self, attributes): if "commit" in attributes: # pragma no branch - self._commit = self._makeClassAttribute(github.Commit.Commit, attributes["commit"]) + self._commit = self._makeClassAttribute( + github.Commit.Commit, attributes["commit"] + ) if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "protection_url" in attributes: # pragma no branch - self._protection_url = self._makeStringAttribute(attributes["protection_url"]) + self._protection_url = self._makeStringAttribute( + attributes["protection_url"] + ) if "protected" in attributes: # pragma no branch self._protected = self._makeBoolAttribute(attributes["protected"]) @@ -104,11 +108,25 @@ class Branch(github.GithubObject.NonCompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "GET", self.protection_url, - headers={'Accept': Consts.mediaTypeRequireMultipleApprovingReviews} + headers={"Accept": Consts.mediaTypeRequireMultipleApprovingReviews}, + ) + return github.BranchProtection.BranchProtection( + self._requester, headers, data, completed=True ) - return github.BranchProtection.BranchProtection(self._requester, headers, data, completed=True) - def edit_protection(self, strict=github.GithubObject.NotSet, contexts=github.GithubObject.NotSet, enforce_admins=github.GithubObject.NotSet, dismissal_users=github.GithubObject.NotSet, dismissal_teams=github.GithubObject.NotSet, dismiss_stale_reviews=github.GithubObject.NotSet, require_code_owner_reviews=github.GithubObject.NotSet, required_approving_review_count=github.GithubObject.NotSet, user_push_restrictions=github.GithubObject.NotSet, team_push_restrictions=github.GithubObject.NotSet): + def edit_protection( + self, + strict=github.GithubObject.NotSet, + contexts=github.GithubObject.NotSet, + enforce_admins=github.GithubObject.NotSet, + dismissal_users=github.GithubObject.NotSet, + dismissal_teams=github.GithubObject.NotSet, + dismiss_stale_reviews=github.GithubObject.NotSet, + require_code_owner_reviews=github.GithubObject.NotSet, + required_approving_review_count=github.GithubObject.NotSet, + user_push_restrictions=github.GithubObject.NotSet, + team_push_restrictions=github.GithubObject.NotSet, + ): """ :calls: `PUT /repos/:owner/:repo/branches/:branch/protection `_ :strict: bool @@ -127,21 +145,48 @@ class Branch(github.GithubObject.NonCompletableGithubObject): changing. Use edit_required_status_checks() to avoid this. """ assert strict is github.GithubObject.NotSet or isinstance(strict, bool), strict - assert contexts is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in contexts), contexts - assert enforce_admins is github.GithubObject.NotSet or isinstance(enforce_admins, bool), enforce_admins - assert dismissal_users is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in dismissal_users), dismissal_users - assert dismissal_teams is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in dismissal_teams), dismissal_teams - assert dismiss_stale_reviews is github.GithubObject.NotSet or isinstance(dismiss_stale_reviews, bool), dismiss_stale_reviews - assert require_code_owner_reviews is github.GithubObject.NotSet or isinstance(require_code_owner_reviews, bool), require_code_owner_reviews - assert required_approving_review_count is github.GithubObject.NotSet or isinstance(required_approving_review_count, int), required_approving_review_count + assert contexts is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in contexts + ), contexts + assert enforce_admins is github.GithubObject.NotSet or isinstance( + enforce_admins, bool + ), enforce_admins + assert dismissal_users is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in dismissal_users + ), dismissal_users + assert dismissal_teams is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in dismissal_teams + ), dismissal_teams + assert dismiss_stale_reviews is github.GithubObject.NotSet or isinstance( + dismiss_stale_reviews, bool + ), dismiss_stale_reviews + assert require_code_owner_reviews is github.GithubObject.NotSet or isinstance( + require_code_owner_reviews, bool + ), require_code_owner_reviews + assert ( + required_approving_review_count is github.GithubObject.NotSet + or isinstance(required_approving_review_count, int) + ), required_approving_review_count post_parameters = {} - if strict is not github.GithubObject.NotSet or contexts is not github.GithubObject.NotSet: + if ( + strict is not github.GithubObject.NotSet + or contexts is not github.GithubObject.NotSet + ): if strict is github.GithubObject.NotSet: strict = False if contexts is github.GithubObject.NotSet: contexts = [] - post_parameters["required_status_checks"] = {"strict": strict, "contexts": contexts} + post_parameters["required_status_checks"] = { + "strict": strict, + "contexts": contexts, + } else: post_parameters["required_status_checks"] = None @@ -150,36 +195,63 @@ class Branch(github.GithubObject.NonCompletableGithubObject): else: post_parameters["enforce_admins"] = None - if dismissal_users is not github.GithubObject.NotSet or dismissal_teams is not github.GithubObject.NotSet or dismiss_stale_reviews is not github.GithubObject.NotSet or require_code_owner_reviews is not github.GithubObject.NotSet or required_approving_review_count is not github.GithubObject.NotSet: + if ( + dismissal_users is not github.GithubObject.NotSet + or dismissal_teams is not github.GithubObject.NotSet + or dismiss_stale_reviews is not github.GithubObject.NotSet + or require_code_owner_reviews is not github.GithubObject.NotSet + or required_approving_review_count is not github.GithubObject.NotSet + ): post_parameters["required_pull_request_reviews"] = {} if dismiss_stale_reviews is not github.GithubObject.NotSet: - post_parameters["required_pull_request_reviews"]["dismiss_stale_reviews"] = dismiss_stale_reviews + post_parameters["required_pull_request_reviews"][ + "dismiss_stale_reviews" + ] = dismiss_stale_reviews if require_code_owner_reviews is not github.GithubObject.NotSet: - post_parameters["required_pull_request_reviews"]["require_code_owner_reviews"] = require_code_owner_reviews + post_parameters["required_pull_request_reviews"][ + "require_code_owner_reviews" + ] = require_code_owner_reviews if required_approving_review_count is not github.GithubObject.NotSet: - post_parameters["required_pull_request_reviews"]["required_approving_review_count"] = required_approving_review_count + post_parameters["required_pull_request_reviews"][ + "required_approving_review_count" + ] = required_approving_review_count if dismissal_users is not github.GithubObject.NotSet: - post_parameters["required_pull_request_reviews"]["dismissal_restrictions"] = {"users": dismissal_users} + post_parameters["required_pull_request_reviews"][ + "dismissal_restrictions" + ] = {"users": dismissal_users} if dismissal_teams is not github.GithubObject.NotSet: - if "dismissal_restrictions" not in post_parameters["required_pull_request_reviews"]: - post_parameters["required_pull_request_reviews"]["dismissal_restrictions"] = {} - post_parameters["required_pull_request_reviews"]["dismissal_restrictions"]["teams"] = dismissal_teams + if ( + "dismissal_restrictions" + not in post_parameters["required_pull_request_reviews"] + ): + post_parameters["required_pull_request_reviews"][ + "dismissal_restrictions" + ] = {} + post_parameters["required_pull_request_reviews"][ + "dismissal_restrictions" + ]["teams"] = dismissal_teams else: post_parameters["required_pull_request_reviews"] = None - if user_push_restrictions is not github.GithubObject.NotSet or team_push_restrictions is not github.GithubObject.NotSet: + if ( + user_push_restrictions is not github.GithubObject.NotSet + or team_push_restrictions is not github.GithubObject.NotSet + ): if user_push_restrictions is github.GithubObject.NotSet: user_push_restrictions = [] if team_push_restrictions is github.GithubObject.NotSet: team_push_restrictions = [] - post_parameters["restrictions"] = {"users": user_push_restrictions, "teams": team_push_restrictions} + post_parameters["restrictions"] = { + "users": user_push_restrictions, + "teams": team_push_restrictions, + } else: post_parameters["restrictions"] = None headers, data = self._requester.requestJsonAndCheck( "PUT", self.protection_url, - headers={'Accept': Consts.mediaTypeRequireMultipleApprovingReviews}, - input=post_parameters + headers={"Accept": Consts.mediaTypeRequireMultipleApprovingReviews}, + input=post_parameters, ) def remove_protection(self): @@ -187,8 +259,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection `_ """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url, + "DELETE", self.protection_url, ) def get_required_status_checks(self): @@ -197,19 +268,26 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :rtype: :class:`github.RequiredStatusChecks.RequiredStatusChecks` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.protection_url + "/required_status_checks" + "GET", self.protection_url + "/required_status_checks" + ) + return github.RequiredStatusChecks.RequiredStatusChecks( + self._requester, headers, data, completed=True ) - return github.RequiredStatusChecks.RequiredStatusChecks(self._requester, headers, data, completed=True) - def edit_required_status_checks(self, strict=github.GithubObject.NotSet, contexts=github.GithubObject.NotSet): + def edit_required_status_checks( + self, strict=github.GithubObject.NotSet, contexts=github.GithubObject.NotSet + ): """ :calls: `PATCH /repos/:owner/:repo/branches/:branch/protection/required_status_checks `_ :strict: bool :contexts: list of strings """ assert strict is github.GithubObject.NotSet or isinstance(strict, bool), strict - assert contexts is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in contexts), contexts + assert contexts is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in contexts + ), contexts post_parameters = {} if strict is not github.GithubObject.NotSet: @@ -219,7 +297,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "PATCH", self.protection_url + "/required_status_checks", - input=post_parameters + input=post_parameters, ) def remove_required_status_checks(self): @@ -227,8 +305,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection/required_status_checks `_ """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url + "/required_status_checks" + "DELETE", self.protection_url + "/required_status_checks" ) def get_required_pull_request_reviews(self): @@ -239,11 +316,20 @@ class Branch(github.GithubObject.NonCompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "GET", self.protection_url + "/required_pull_request_reviews", - headers={'Accept': Consts.mediaTypeRequireMultipleApprovingReviews} + headers={"Accept": Consts.mediaTypeRequireMultipleApprovingReviews}, + ) + return github.RequiredPullRequestReviews.RequiredPullRequestReviews( + self._requester, headers, data, completed=True ) - return github.RequiredPullRequestReviews.RequiredPullRequestReviews(self._requester, headers, data, completed=True) - def edit_required_pull_request_reviews(self, dismissal_users=github.GithubObject.NotSet, dismissal_teams=github.GithubObject.NotSet, dismiss_stale_reviews=github.GithubObject.NotSet, require_code_owner_reviews=github.GithubObject.NotSet, required_approving_review_count=github.GithubObject.NotSet): + def edit_required_pull_request_reviews( + self, + dismissal_users=github.GithubObject.NotSet, + dismissal_teams=github.GithubObject.NotSet, + dismiss_stale_reviews=github.GithubObject.NotSet, + require_code_owner_reviews=github.GithubObject.NotSet, + required_approving_review_count=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo/branches/:branch/protection/required_pull_request_reviews `_ :dismissal_users: list of strings @@ -252,11 +338,26 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :require_code_owner_reviews: bool :required_approving_review_count: int """ - assert dismissal_users is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in dismissal_users), dismissal_users - assert dismissal_teams is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in dismissal_teams), dismissal_teams - assert dismiss_stale_reviews is github.GithubObject.NotSet or isinstance(dismiss_stale_reviews, bool), dismiss_stale_reviews - assert require_code_owner_reviews is github.GithubObject.NotSet or isinstance(require_code_owner_reviews, bool), require_code_owner_reviews - assert required_approving_review_count is github.GithubObject.NotSet or isinstance(required_approving_review_count, int), required_approving_review_count + assert dismissal_users is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in dismissal_users + ), dismissal_users + assert dismissal_teams is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in dismissal_teams + ), dismissal_teams + assert dismiss_stale_reviews is github.GithubObject.NotSet or isinstance( + dismiss_stale_reviews, bool + ), dismiss_stale_reviews + assert require_code_owner_reviews is github.GithubObject.NotSet or isinstance( + require_code_owner_reviews, bool + ), require_code_owner_reviews + assert ( + required_approving_review_count is github.GithubObject.NotSet + or isinstance(required_approving_review_count, int) + ), required_approving_review_count post_parameters = {} if dismissal_users is not github.GithubObject.NotSet: @@ -270,12 +371,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): if require_code_owner_reviews is not github.GithubObject.NotSet: post_parameters["require_code_owner_reviews"] = require_code_owner_reviews if required_approving_review_count is not github.GithubObject.NotSet: - post_parameters["required_approving_review_count"] = required_approving_review_count + post_parameters[ + "required_approving_review_count" + ] = required_approving_review_count headers, data = self._requester.requestJsonAndCheck( "PATCH", self.protection_url + "/required_pull_request_reviews", - headers={'Accept': Consts.mediaTypeRequireMultipleApprovingReviews}, - input=post_parameters + headers={"Accept": Consts.mediaTypeRequireMultipleApprovingReviews}, + input=post_parameters, ) def remove_required_pull_request_reviews(self): @@ -283,8 +386,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection/required_pull_request_reviews `_ """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url + "/required_pull_request_reviews" + "DELETE", self.protection_url + "/required_pull_request_reviews" ) def get_admin_enforcement(self): @@ -293,8 +395,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :rtype: bool """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.protection_url + "/enforce_admins" + "GET", self.protection_url + "/enforce_admins" ) return data["enabled"] @@ -303,8 +404,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `POST /repos/:owner/:repo/branches/:branch/protection/enforce_admins `_ """ headers, data = self._requester.requestJsonAndCheck( - "POST", - self.protection_url + "/enforce_admins" + "POST", self.protection_url + "/enforce_admins" ) def remove_admin_enforcement(self): @@ -312,8 +412,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection/enforce_admins `_ """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url + "/enforce_admins" + "DELETE", self.protection_url + "/enforce_admins" ) def get_user_push_restrictions(self): @@ -325,7 +424,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): github.NamedUser.NamedUser, self._requester, self.protection_url + "/restrictions/users", - None + None, ) def get_team_push_restrictions(self): @@ -337,7 +436,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): github.Team.Team, self._requester, self.protection_url + "/restrictions/teams", - None + None, ) def add_user_push_restrictions(self, *users): @@ -345,12 +444,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `POST /repos/:owner/:repo/branches/:branch/protection/restrictions/users `_ :users: list of strings (user names) """ - assert all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in users), users + assert all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in users + ), users headers, data = self._requester.requestJsonAndCheck( - "POST", - self.protection_url + "/restrictions/users", - input=users + "POST", self.protection_url + "/restrictions/users", input=users ) def replace_user_push_restrictions(self, *users): @@ -358,12 +459,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `PUT /repos/:owner/:repo/branches/:branch/protection/restrictions/users `_ :users: list of strings (user names) """ - assert all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in users), users + assert all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in users + ), users headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.protection_url + "/restrictions/users", - input=users + "PUT", self.protection_url + "/restrictions/users", input=users ) def remove_user_push_restrictions(self, *users): @@ -371,12 +474,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection/restrictions/users `_ :users: list of strings (user names) """ - assert all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in users), users + assert all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in users + ), users headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url + "/restrictions/users", - input=users + "DELETE", self.protection_url + "/restrictions/users", input=users ) def add_team_push_restrictions(self, *teams): @@ -384,12 +489,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `POST /repos/:owner/:repo/branches/:branch/protection/restrictions/teams `_ :teams: list of strings (team slugs) """ - assert all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in teams), teams + assert all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in teams + ), teams headers, data = self._requester.requestJsonAndCheck( - "POST", - self.protection_url + "/restrictions/teams", - input=teams + "POST", self.protection_url + "/restrictions/teams", input=teams ) def replace_team_push_restrictions(self, *teams): @@ -397,12 +504,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `PUT /repos/:owner/:repo/branches/:branch/protection/restrictions/teams `_ :teams: list of strings (team slugs) """ - assert all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in teams), teams + assert all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in teams + ), teams headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.protection_url + "/restrictions/teams", - input=teams + "PUT", self.protection_url + "/restrictions/teams", input=teams ) def remove_team_push_restrictions(self, *teams): @@ -410,12 +519,14 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection/restrictions/teams `_ :teams: list of strings (team slugs) """ - assert all(isinstance(element, (str, six.text_type)) or isinstance(element, (str, six.text_type)) for element in teams), teams + assert all( + isinstance(element, (str, six.text_type)) + or isinstance(element, (str, six.text_type)) + for element in teams + ), teams headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url + "/restrictions/teams", - input=teams + "DELETE", self.protection_url + "/restrictions/teams", input=teams ) def remove_push_restrictions(self): @@ -423,8 +534,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/branches/:branch/protection/restrictions `_ """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.protection_url + "/restrictions" + "DELETE", self.protection_url + "/restrictions" ) def get_required_signatures(self): @@ -434,7 +544,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "GET", self.protection_url + "/required_signatures", - headers={'Accept': Consts.signaturesProtectedBranchesPreview} + headers={"Accept": Consts.signaturesProtectedBranchesPreview}, ) return data["enabled"] @@ -445,7 +555,7 @@ class Branch(github.GithubObject.NonCompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "POST", self.protection_url + "/required_signatures", - headers={'Accept': Consts.signaturesProtectedBranchesPreview} + headers={"Accept": Consts.signaturesProtectedBranchesPreview}, ) def remove_required_signatures(self): @@ -455,5 +565,5 @@ class Branch(github.GithubObject.NonCompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "DELETE", self.protection_url + "/required_signatures", - headers={'Accept': Consts.signaturesProtectedBranchesPreview} + headers={"Accept": Consts.signaturesProtectedBranchesPreview}, ) diff --git a/github/BranchProtection.py b/github/BranchProtection.py index caf1bfd9..e56bef04 100644 --- a/github/BranchProtection.py +++ b/github/BranchProtection.py @@ -23,8 +23,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser import github.RequiredPullRequestReviews import github.RequiredStatusChecks @@ -81,7 +81,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject): github.NamedUser.NamedUser, self._requester, self._user_push_restrictions, - None + None, ) def get_team_push_restrictions(self): @@ -91,10 +91,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject): if self._team_push_restrictions is github.GithubObject.NotSet: return None return github.PaginatedList.PaginatedList( - github.Team.Team, - self._requester, - self._team_push_restrictions, - None + github.Team.Team, self._requester, self._team_push_restrictions, None ) def _initAttributes(self): @@ -109,11 +106,19 @@ class BranchProtection(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "required_status_checks" in attributes: # pragma no branch - self._required_status_checks = self._makeClassAttribute(github.RequiredStatusChecks.RequiredStatusChecks, attributes["required_status_checks"]) + self._required_status_checks = self._makeClassAttribute( + github.RequiredStatusChecks.RequiredStatusChecks, + attributes["required_status_checks"], + ) if "enforce_admins" in attributes: # pragma no branch - self._enforce_admins = self._makeBoolAttribute(attributes["enforce_admins"]["enabled"]) + self._enforce_admins = self._makeBoolAttribute( + attributes["enforce_admins"]["enabled"] + ) if "required_pull_request_reviews" in attributes: # pragma no branch - self._required_pull_request_reviews = self._makeClassAttribute(github.RequiredPullRequestReviews.RequiredPullRequestReviews, attributes["required_pull_request_reviews"]) + self._required_pull_request_reviews = self._makeClassAttribute( + github.RequiredPullRequestReviews.RequiredPullRequestReviews, + attributes["required_pull_request_reviews"], + ) if "restrictions" in attributes: # pragma no branch self._user_push_restrictions = attributes["restrictions"]["users_url"] self._team_push_restrictions = attributes["restrictions"]["teams_url"] diff --git a/github/Clones.py b/github/Clones.py index 1f3faac6..b24e5893 100644 --- a/github/Clones.py +++ b/github/Clones.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -37,11 +38,13 @@ class Clones(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "timestamp": self._timestamp.value, - "count": self._count.value, - "uniques": self._uniques.value - }) + return self.get__repr__( + { + "timestamp": self._timestamp.value, + "count": self._count.value, + "uniques": self._uniques.value, + } + ) @property def timestamp(self): diff --git a/github/Commit.py b/github/Commit.py index a15fdc6e..733f6183 100644 --- a/github/Commit.py +++ b/github/Commit.py @@ -33,16 +33,16 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.PaginatedList -import github.GitCommit -import github.NamedUser -import github.CommitStatus import github.CommitCombinedStatus -import github.File -import github.CommitStats import github.CommitComment +import github.CommitStats +import github.CommitStatus +import github.File +import github.GitCommit +import github.GithubObject +import github.NamedUser +import github.PaginatedList import six @@ -134,7 +134,13 @@ class Commit(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def create_comment(self, body, line=github.GithubObject.NotSet, path=github.GithubObject.NotSet, position=github.GithubObject.NotSet): + def create_comment( + self, + body, + line=github.GithubObject.NotSet, + path=github.GithubObject.NotSet, + position=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/commits/:sha/comments `_ :param body: string @@ -144,9 +150,15 @@ class Commit(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.CommitComment.CommitComment` """ assert isinstance(body, (str, six.text_type)), body - assert line is github.GithubObject.NotSet or isinstance(line, six.integer_types), line - assert path is github.GithubObject.NotSet or isinstance(path, (str, six.text_type)), path - assert position is github.GithubObject.NotSet or isinstance(position, six.integer_types), position + assert line is github.GithubObject.NotSet or isinstance( + line, six.integer_types + ), line + assert path is github.GithubObject.NotSet or isinstance( + path, (str, six.text_type) + ), path + assert position is github.GithubObject.NotSet or isinstance( + position, six.integer_types + ), position post_parameters = { "body": body, } @@ -157,13 +169,19 @@ class Commit(github.GithubObject.CompletableGithubObject): if position is not github.GithubObject.NotSet: post_parameters["position"] = position headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/comments", - input=post_parameters + "POST", self.url + "/comments", input=post_parameters + ) + return github.CommitComment.CommitComment( + self._requester, headers, data, completed=True ) - return github.CommitComment.CommitComment(self._requester, headers, data, completed=True) - def create_status(self, state, target_url=github.GithubObject.NotSet, description=github.GithubObject.NotSet, context=github.GithubObject.NotSet): + def create_status( + self, + state, + target_url=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + context=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/statuses/:sha `_ :param state: string @@ -173,9 +191,15 @@ class Commit(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.CommitStatus.CommitStatus` """ assert isinstance(state, (str, six.text_type)), state - assert target_url is github.GithubObject.NotSet or isinstance(target_url, (str, six.text_type)), target_url - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert context is github.GithubObject.NotSet or isinstance(context, (str, six.text_type)), context + assert target_url is github.GithubObject.NotSet or isinstance( + target_url, (str, six.text_type) + ), target_url + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert context is github.GithubObject.NotSet or isinstance( + context, (str, six.text_type) + ), context post_parameters = { "state": state, } @@ -188,9 +212,11 @@ class Commit(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "POST", self._parentUrl(self._parentUrl(self.url)) + "/statuses/" + self.sha, - input=post_parameters + input=post_parameters, + ) + return github.CommitStatus.CommitStatus( + self._requester, headers, data, completed=True ) - return github.CommitStatus.CommitStatus(self._requester, headers, data, completed=True) def get_comments(self): """ @@ -201,7 +227,7 @@ class Commit(github.GithubObject.CompletableGithubObject): github.CommitComment.CommitComment, self._requester, self.url + "/comments", - None + None, ) def get_statuses(self): @@ -213,7 +239,7 @@ class Commit(github.GithubObject.CompletableGithubObject): github.CommitStatus.CommitStatus, self._requester, self._parentUrl(self._parentUrl(self.url)) + "/statuses/" + self.sha, - None + None, ) def get_combined_status(self): @@ -221,11 +247,10 @@ class Commit(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/:owner/:repo/commits/:ref/status/ `_ :rtype: :class:`github.CommitCombinedStatus.CommitCombinedStatus` """ - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/status" + headers, data = self._requester.requestJsonAndCheck("GET", self.url + "/status") + return github.CommitCombinedStatus.CommitCombinedStatus( + self._requester, headers, data, completed=True ) - return github.CommitCombinedStatus.CommitCombinedStatus(self._requester, headers, data, completed=True) @property def _identity(self): @@ -245,22 +270,34 @@ class Commit(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "author" in attributes: # pragma no branch - self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) + self._author = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["author"] + ) if "comments_url" in attributes: # pragma no branch self._comments_url = self._makeStringAttribute(attributes["comments_url"]) if "commit" in attributes: # pragma no branch - self._commit = self._makeClassAttribute(github.GitCommit.GitCommit, attributes["commit"]) + self._commit = self._makeClassAttribute( + github.GitCommit.GitCommit, attributes["commit"] + ) if "committer" in attributes: # pragma no branch - self._committer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["committer"]) + self._committer = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["committer"] + ) if "files" in attributes: # pragma no branch - self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"]) + self._files = self._makeListOfClassesAttribute( + github.File.File, attributes["files"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "parents" in attributes: # pragma no branch - self._parents = self._makeListOfClassesAttribute(Commit, attributes["parents"]) + self._parents = self._makeListOfClassesAttribute( + Commit, attributes["parents"] + ) if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "stats" in attributes: # pragma no branch - self._stats = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["stats"]) + self._stats = self._makeClassAttribute( + github.CommitStats.CommitStats, attributes["stats"] + ) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) diff --git a/github/CommitCombinedStatus.py b/github/CommitCombinedStatus.py index 3516ea39..f23e65ca 100644 --- a/github/CommitCombinedStatus.py +++ b/github/CommitCombinedStatus.py @@ -27,9 +27,9 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.CommitStatus +import github.GithubObject import github.Repository @@ -111,6 +111,10 @@ class CommitCombinedStatus(github.GithubObject.NonCompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "repository" in attributes: # pragma no branch - self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) + self._repository = self._makeClassAttribute( + github.Repository.Repository, attributes["repository"] + ) if "statuses" in attributes: # pragma no branch - self._statuses = self._makeListOfClassesAttribute(github.CommitStatus.CommitStatus, attributes["statuses"]) + self._statuses = self._makeListOfClassesAttribute( + github.CommitStatus.CommitStatus, attributes["statuses"] + ) diff --git a/github/CommitComment.py b/github/CommitComment.py index 6a085168..ff3059f1 100644 --- a/github/CommitComment.py +++ b/github/CommitComment.py @@ -33,11 +33,12 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.NamedUser +import six from . import Consts -import six class CommitComment(github.GithubObject.CompletableGithubObject): @@ -141,10 +142,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/comments/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def edit(self, body): """ @@ -157,9 +155,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -174,7 +170,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/reactions", None, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) def create_reaction(self, reaction_type): @@ -184,9 +180,17 @@ class CommitComment(github.GithubObject.CompletableGithubObject): :param reaction_type: string :rtype: :class:`github.Reaction.Reaction` """ - assert isinstance(reaction_type, (str, six.text_type)), "reaction type should be a string" - assert reaction_type in ["+1", "-1", "laugh", "confused", "heart", "hooray"], \ - "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" + assert isinstance( + reaction_type, (str, six.text_type) + ), "reaction type should be a string" + assert reaction_type in [ + "+1", + "-1", + "laugh", + "confused", + "heart", + "hooray", + ], "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" post_parameters = { "content": reaction_type, @@ -195,7 +199,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): "POST", self.url + "/reactions", input=post_parameters, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) @@ -234,4 +238,6 @@ class CommitComment(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/CommitStats.py b/github/CommitStats.py index e1b78b76..6b345e1a 100644 --- a/github/CommitStats.py +++ b/github/CommitStats.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/CommitStatus.py b/github/CommitStatus.py index 91b05d70..8de27dd4 100644 --- a/github/CommitStatus.py +++ b/github/CommitStatus.py @@ -33,8 +33,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser @@ -44,11 +44,13 @@ class CommitStatus(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "id": self._id.value, - "state": self._state.value, - "context": self._context.value - }) + return self.get__repr__( + { + "id": self._id.value, + "state": self._state.value, + "context": self._context.value, + } + ) @property def created_at(self): @@ -128,7 +130,9 @@ class CommitStatus(github.GithubObject.NonCompletableGithubObject): if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "creator" in attributes: # pragma no branch - self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"]) + self._creator = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["creator"] + ) if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "id" in attributes: # pragma no branch diff --git a/github/Comparison.py b/github/Comparison.py index cfcbc9a0..4b4efdf8 100644 --- a/github/Comparison.py +++ b/github/Comparison.py @@ -30,10 +30,10 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.Commit import github.File +import github.GithubObject class Comparison(github.GithubObject.CompletableGithubObject): @@ -164,19 +164,27 @@ class Comparison(github.GithubObject.CompletableGithubObject): if "ahead_by" in attributes: # pragma no branch self._ahead_by = self._makeIntAttribute(attributes["ahead_by"]) if "base_commit" in attributes: # pragma no branch - self._base_commit = self._makeClassAttribute(github.Commit.Commit, attributes["base_commit"]) + self._base_commit = self._makeClassAttribute( + github.Commit.Commit, attributes["base_commit"] + ) if "behind_by" in attributes: # pragma no branch self._behind_by = self._makeIntAttribute(attributes["behind_by"]) if "commits" in attributes: # pragma no branch - self._commits = self._makeListOfClassesAttribute(github.Commit.Commit, attributes["commits"]) + self._commits = self._makeListOfClassesAttribute( + github.Commit.Commit, attributes["commits"] + ) if "diff_url" in attributes: # pragma no branch self._diff_url = self._makeStringAttribute(attributes["diff_url"]) if "files" in attributes: # pragma no branch - self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"]) + self._files = self._makeListOfClassesAttribute( + github.File.File, attributes["files"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "merge_base_commit" in attributes: # pragma no branch - self._merge_base_commit = self._makeClassAttribute(github.Commit.Commit, attributes["merge_base_commit"]) + self._merge_base_commit = self._makeClassAttribute( + github.Commit.Commit, attributes["merge_base_commit"] + ) if "patch_url" in attributes: # pragma no branch self._patch_url = self._makeStringAttribute(attributes["patch_url"]) if "permalink_url" in attributes: # pragma no branch diff --git a/github/Consts.py b/github/Consts.py index 4d2a6220..a3368522 100644 --- a/github/Consts.py +++ b/github/Consts.py @@ -92,7 +92,9 @@ mediaTypeOrganizationInvitationPreview = "application/vnd.github.dazzler-preview mediaTypeTeamDiscussionsPreview = "application/vnd.github.echo-preview+json" # https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews/ -mediaTypeRequireMultipleApprovingReviews = "application/vnd.github.luke-cage-preview+json" +mediaTypeRequireMultipleApprovingReviews = ( + "application/vnd.github.luke-cage-preview+json" +) # https://developer.github.com/changes/2018-05-24-user-migration-api/ mediaTypeMigrationPreview = "application/vnd.github.wyandotte-preview+json" diff --git a/github/ContentFile.py b/github/ContentFile.py index c53c74f1..7304f127 100644 --- a/github/ContentFile.py +++ b/github/ContentFile.py @@ -32,6 +32,7 @@ ################################################################################ from __future__ import absolute_import + import base64 import github.GithubObject @@ -122,8 +123,14 @@ class ContentFile(github.GithubObject.CompletableGithubObject): """ if self._repository is github.GithubObject.NotSet: # The repository was not set automatically, so it must be looked up by url. - repo_url = "/".join(self.url.split("/")[:6]) # pragma no cover (Should be covered) - self._repository = github.GithubObject._ValuedAttribute(github.Repository.Repository(self._requester, self._headers, {'url': repo_url}, completed=False)) # pragma no cover (Should be covered) + repo_url = "/".join( + self.url.split("/")[:6] + ) # pragma no cover (Should be covered) + self._repository = github.GithubObject._ValuedAttribute( + github.Repository.Repository( + self._requester, self._headers, {"url": repo_url}, completed=False + ) + ) # pragma no cover (Should be covered) return self._repository.value @property @@ -193,13 +200,17 @@ class ContentFile(github.GithubObject.CompletableGithubObject): if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "license" in attributes: # pragma no branch - self._license = self._makeClassAttribute(github.License.License, attributes["license"]) + self._license = self._makeClassAttribute( + github.License.License, attributes["license"] + ) if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "path" in attributes: # pragma no branch self._path = self._makeStringAttribute(attributes["path"]) if "repository" in attributes: # pragma no branch - self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) + self._repository = self._makeClassAttribute( + github.Repository.Repository, attributes["repository"] + ) if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "size" in attributes: # pragma no branch @@ -209,4 +220,6 @@ class ContentFile(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "text_matches" in attributes: # pragma no branch - self._text_matches = self._makeListOfDictsAttribute(attributes["text_matches"]) + self._text_matches = self._makeListOfDictsAttribute( + attributes["text_matches"] + ) diff --git a/github/Download.py b/github/Download.py index 2b7fb92e..7370930d 100644 --- a/github/Download.py +++ b/github/Download.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -207,10 +208,7 @@ class Download(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/downloads/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def _initAttributes(self): self._accesskeyid = github.GithubObject.NotSet @@ -236,11 +234,17 @@ class Download(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "accesskeyid" in attributes: # pragma no branch - self._accesskeyid = self._makeStringAttribute(attributes["accesskeyid"]) # pragma no cover (was covered only by create_download, which has been removed) + self._accesskeyid = self._makeStringAttribute( + attributes["accesskeyid"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "acl" in attributes: # pragma no branch - self._acl = self._makeStringAttribute(attributes["acl"]) # pragma no cover (was covered only by create_download, which has been removed) + self._acl = self._makeStringAttribute( + attributes["acl"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "bucket" in attributes: # pragma no branch - self._bucket = self._makeStringAttribute(attributes["bucket"]) # pragma no cover (was covered only by create_download, which has been removed) + self._bucket = self._makeStringAttribute( + attributes["bucket"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "content_type" in attributes: # pragma no branch self._content_type = self._makeStringAttribute(attributes["content_type"]) if "created_at" in attributes: # pragma no branch @@ -250,27 +254,43 @@ class Download(github.GithubObject.CompletableGithubObject): if "download_count" in attributes: # pragma no branch self._download_count = self._makeIntAttribute(attributes["download_count"]) if "expirationdate" in attributes: # pragma no branch - self._expirationdate = self._makeDatetimeAttribute(attributes["expirationdate"]) # pragma no cover (was covered only by create_download, which has been removed) + self._expirationdate = self._makeDatetimeAttribute( + attributes["expirationdate"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "mime_type" in attributes: # pragma no branch - self._mime_type = self._makeStringAttribute(attributes["mime_type"]) # pragma no cover (was covered only by create_download, which has been removed) + self._mime_type = self._makeStringAttribute( + attributes["mime_type"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "path" in attributes: # pragma no branch - self._path = self._makeStringAttribute(attributes["path"]) # pragma no cover (was covered only by create_download, which has been removed) + self._path = self._makeStringAttribute( + attributes["path"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "policy" in attributes: # pragma no branch - self._policy = self._makeStringAttribute(attributes["policy"]) # pragma no cover (was covered only by create_download, which has been removed) + self._policy = self._makeStringAttribute( + attributes["policy"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "prefix" in attributes: # pragma no branch - self._prefix = self._makeStringAttribute(attributes["prefix"]) # pragma no cover (was covered only by create_download, which has been removed) + self._prefix = self._makeStringAttribute( + attributes["prefix"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "redirect" in attributes: # pragma no branch - self._redirect = self._makeBoolAttribute(attributes["redirect"]) # pragma no cover (was covered only by create_download, which has been removed) + self._redirect = self._makeBoolAttribute( + attributes["redirect"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "s3_url" in attributes: # pragma no branch - self._s3_url = self._makeStringAttribute(attributes["s3_url"]) # pragma no cover (was covered only by create_download, which has been removed) + self._s3_url = self._makeStringAttribute( + attributes["s3_url"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "signature" in attributes: # pragma no branch - self._signature = self._makeStringAttribute(attributes["signature"]) # pragma no cover (was covered only by create_download, which has been removed) + self._signature = self._makeStringAttribute( + attributes["signature"] + ) # pragma no cover (was covered only by create_download, which has been removed) if "size" in attributes: # pragma no branch self._size = self._makeIntAttribute(attributes["size"]) if "url" in attributes: # pragma no branch diff --git a/github/Event.py b/github/Event.py index 6a92a010..fa100d74 100644 --- a/github/Event.py +++ b/github/Event.py @@ -31,11 +31,11 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject +import github.NamedUser import github.Organization import github.Repository -import github.NamedUser class Event(github.GithubObject.NonCompletableGithubObject): @@ -114,18 +114,24 @@ class Event(github.GithubObject.NonCompletableGithubObject): def _useAttributes(self, attributes): if "actor" in attributes: # pragma no branch - self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"]) + self._actor = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["actor"] + ) if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "id" in attributes: # pragma no branch self._id = self._makeStringAttribute(attributes["id"]) if "org" in attributes: # pragma no branch - self._org = self._makeClassAttribute(github.Organization.Organization, attributes["org"]) + self._org = self._makeClassAttribute( + github.Organization.Organization, attributes["org"] + ) if "payload" in attributes: # pragma no branch self._payload = self._makeDictAttribute(attributes["payload"]) if "public" in attributes: # pragma no branch self._public = self._makeBoolAttribute(attributes["public"]) if "repo" in attributes: # pragma no branch - self._repo = self._makeClassAttribute(github.Repository.Repository, attributes["repo"]) + self._repo = self._makeClassAttribute( + github.Repository.Repository, attributes["repo"] + ) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) diff --git a/github/File.py b/github/File.py index 7fc09776..1db06dc7 100644 --- a/github/File.py +++ b/github/File.py @@ -33,6 +33,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -42,7 +43,9 @@ class File(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"sha": self._sha.value, "filename": self._filename.value}) + return self.get__repr__( + {"sha": self._sha.value, "filename": self._filename.value} + ) @property def additions(self): @@ -150,7 +153,9 @@ class File(github.GithubObject.NonCompletableGithubObject): if "patch" in attributes: # pragma no branch self._patch = self._makeStringAttribute(attributes["patch"]) if "previous_filename" in attributes: # pragma no branch - self._previous_filename = self._makeStringAttribute(attributes["previous_filename"]) + self._previous_filename = self._makeStringAttribute( + attributes["previous_filename"] + ) if "raw_url" in attributes: # pragma no branch self._raw_url = self._makeStringAttribute(attributes["raw_url"]) if "sha" in attributes: # pragma no branch diff --git a/github/Gist.py b/github/Gist.py index 6115f852..d899eaae 100644 --- a/github/Gist.py +++ b/github/Gist.py @@ -34,13 +34,13 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.PaginatedList import github.GistComment -import github.NamedUser import github.GistFile import github.GistHistoryState +import github.GithubObject +import github.NamedUser +import github.PaginatedList import six @@ -215,21 +215,18 @@ class Gist(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/comments", - input=post_parameters + "POST", self.url + "/comments", input=post_parameters + ) + return github.GistComment.GistComment( + self._requester, headers, data, completed=True ) - return github.GistComment.GistComment(self._requester, headers, data, completed=True) def create_fork(self): """ :calls: `POST /gists/:id/forks `_ :rtype: :class:`github.Gist.Gist` """ - headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/forks" - ) + headers, data = self._requester.requestJsonAndCheck("POST", self.url + "/forks") return Gist(self._requester, headers, data, completed=True) def delete(self): @@ -237,29 +234,34 @@ class Gist(github.GithubObject.CompletableGithubObject): :calls: `DELETE /gists/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, description=github.GithubObject.NotSet, files=github.GithubObject.NotSet): + def edit( + self, description=github.GithubObject.NotSet, files=github.GithubObject.NotSet + ): """ :calls: `PATCH /gists/:id `_ :param description: string :param files: dict of string to :class:`github.InputFileContent.InputFileContent` :rtype: None """ - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert files is github.GithubObject.NotSet or all(element is None or isinstance(element, github.InputFileContent) for element in six.itervalues(files)), files + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert files is github.GithubObject.NotSet or all( + element is None or isinstance(element, github.InputFileContent) + for element in six.itervalues(files) + ), files post_parameters = dict() if description is not github.GithubObject.NotSet: post_parameters["description"] = description if files is not github.GithubObject.NotSet: - post_parameters["files"] = {key: None if value is None else value._identity for key, value in six.iteritems(files)} + post_parameters["files"] = { + key: None if value is None else value._identity + for key, value in six.iteritems(files) + } headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -271,10 +273,11 @@ class Gist(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/comments/" + str(id) + "GET", self.url + "/comments/" + str(id) + ) + return github.GistComment.GistComment( + self._requester, headers, data, completed=True ) - return github.GistComment.GistComment(self._requester, headers, data, completed=True) def get_comments(self): """ @@ -285,7 +288,7 @@ class Gist(github.GithubObject.CompletableGithubObject): github.GistComment.GistComment, self._requester, self.url + "/comments", - None + None, ) def is_starred(self): @@ -293,10 +296,7 @@ class Gist(github.GithubObject.CompletableGithubObject): :calls: `GET /gists/:id/star `_ :rtype: bool """ - status, headers, data = self._requester.requestJson( - "GET", - self.url + "/star" - ) + status, headers, data = self._requester.requestJson("GET", self.url + "/star") return status == 204 def reset_starred(self): @@ -305,8 +305,7 @@ class Gist(github.GithubObject.CompletableGithubObject): :rtype: None """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/star" + "DELETE", self.url + "/star" ) def set_starred(self): @@ -314,10 +313,7 @@ class Gist(github.GithubObject.CompletableGithubObject): :calls: `PUT /gists/:id/star `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/star" - ) + headers, data = self._requester.requestJsonAndCheck("PUT", self.url + "/star") def _initAttributes(self): self._comments = github.GithubObject.NotSet @@ -352,7 +348,9 @@ class Gist(github.GithubObject.CompletableGithubObject): if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "files" in attributes: # pragma no branch - self._files = self._makeDictOfStringsToClassesAttribute(github.GistFile.GistFile, attributes["files"]) + self._files = self._makeDictOfStringsToClassesAttribute( + github.GistFile.GistFile, attributes["files"] + ) if "fork_of" in attributes: # pragma no branch self._fork_of = self._makeClassAttribute(Gist, attributes["fork_of"]) if "forks" in attributes: # pragma no branch @@ -364,13 +362,17 @@ class Gist(github.GithubObject.CompletableGithubObject): if "git_push_url" in attributes: # pragma no branch self._git_push_url = self._makeStringAttribute(attributes["git_push_url"]) if "history" in attributes: # pragma no branch - self._history = self._makeListOfClassesAttribute(github.GistHistoryState.GistHistoryState, attributes["history"]) + self._history = self._makeListOfClassesAttribute( + github.GistHistoryState.GistHistoryState, attributes["history"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch self._id = self._makeStringAttribute(attributes["id"]) if "owner" in attributes: # pragma no branch - self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"]) + self._owner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["owner"] + ) if "public" in attributes: # pragma no branch self._public = self._makeBoolAttribute(attributes["public"]) if "updated_at" in attributes: # pragma no branch @@ -378,4 +380,6 @@ class Gist(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/GistComment.py b/github/GistComment.py index 2de766f7..a584421c 100644 --- a/github/GistComment.py +++ b/github/GistComment.py @@ -31,8 +31,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser import six @@ -98,10 +98,7 @@ class GistComment(github.GithubObject.CompletableGithubObject): :calls: `DELETE /gists/:gist_id/comments/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def edit(self, body): """ @@ -114,9 +111,7 @@ class GistComment(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -140,4 +135,6 @@ class GistComment(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/GistFile.py b/github/GistFile.py index a16829a1..7d4b656e 100644 --- a/github/GistFile.py +++ b/github/GistFile.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/GistHistoryState.py b/github/GistHistoryState.py index bd01a79b..83647f5f 100644 --- a/github/GistHistoryState.py +++ b/github/GistHistoryState.py @@ -30,11 +30,11 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.NamedUser import github.CommitStats import github.Gist +import github.GithubObject +import github.NamedUser class GistHistoryState(github.GithubObject.CompletableGithubObject): @@ -235,7 +235,9 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "change_status" in attributes: # pragma no branch - self._change_status = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["change_status"]) + self._change_status = self._makeClassAttribute( + github.CommitStats.CommitStats, attributes["change_status"] + ) if "comments" in attributes: # pragma no branch self._comments = self._makeIntAttribute(attributes["comments"]) if "comments_url" in attributes: # pragma no branch @@ -249,9 +251,13 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject): if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "files" in attributes: # pragma no branch - self._files = self._makeDictOfStringsToClassesAttribute(github.GistFile.GistFile, attributes["files"]) + self._files = self._makeDictOfStringsToClassesAttribute( + github.GistFile.GistFile, attributes["files"] + ) if "forks" in attributes: # pragma no branch - self._forks = self._makeListOfClassesAttribute(github.Gist.Gist, attributes["forks"]) + self._forks = self._makeListOfClassesAttribute( + github.Gist.Gist, attributes["forks"] + ) if "forks_url" in attributes: # pragma no branch self._forks_url = self._makeStringAttribute(attributes["forks_url"]) if "git_pull_url" in attributes: # pragma no branch @@ -259,13 +265,17 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject): if "git_push_url" in attributes: # pragma no branch self._git_push_url = self._makeStringAttribute(attributes["git_push_url"]) if "history" in attributes: # pragma no branch - self._history = self._makeListOfClassesAttribute(GistHistoryState, attributes["history"]) + self._history = self._makeListOfClassesAttribute( + GistHistoryState, attributes["history"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch self._id = self._makeStringAttribute(attributes["id"]) if "owner" in attributes: # pragma no branch - self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"]) + self._owner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["owner"] + ) if "public" in attributes: # pragma no branch self._public = self._makeBoolAttribute(attributes["public"]) if "updated_at" in attributes: # pragma no branch @@ -273,6 +283,8 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) if "version" in attributes: # pragma no branch self._version = self._makeStringAttribute(attributes["version"]) diff --git a/github/GitAuthor.py b/github/GitAuthor.py index 6532f96e..1d7220b1 100644 --- a/github/GitAuthor.py +++ b/github/GitAuthor.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/GitBlob.py b/github/GitBlob.py index 367db983..3b4dc5fe 100644 --- a/github/GitBlob.py +++ b/github/GitBlob.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/GitCommit.py b/github/GitCommit.py index 9198240e..6f14a642 100644 --- a/github/GitCommit.py +++ b/github/GitCommit.py @@ -31,9 +31,9 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.GitAuthor +import github.GithubObject import github.GitTree @@ -125,18 +125,26 @@ class GitCommit(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "author" in attributes: # pragma no branch - self._author = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["author"]) + self._author = self._makeClassAttribute( + github.GitAuthor.GitAuthor, attributes["author"] + ) if "committer" in attributes: # pragma no branch - self._committer = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["committer"]) + self._committer = self._makeClassAttribute( + github.GitAuthor.GitAuthor, attributes["committer"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "message" in attributes: # pragma no branch self._message = self._makeStringAttribute(attributes["message"]) if "parents" in attributes: # pragma no branch - self._parents = self._makeListOfClassesAttribute(GitCommit, attributes["parents"]) + self._parents = self._makeListOfClassesAttribute( + GitCommit, attributes["parents"] + ) if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "tree" in attributes: # pragma no branch - self._tree = self._makeClassAttribute(github.GitTree.GitTree, attributes["tree"]) + self._tree = self._makeClassAttribute( + github.GitTree.GitTree, attributes["tree"] + ) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) diff --git a/github/GitObject.py b/github/GitObject.py index b03c7fdb..edc992fc 100644 --- a/github/GitObject.py +++ b/github/GitObject.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/GitRef.py b/github/GitRef.py index 9c929d60..797e2384 100644 --- a/github/GitRef.py +++ b/github/GitRef.py @@ -31,8 +31,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.GitObject import six @@ -74,10 +74,7 @@ class GitRef(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/git/refs/:ref `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def edit(self, sha, force=github.GithubObject.NotSet): """ @@ -94,9 +91,7 @@ class GitRef(github.GithubObject.CompletableGithubObject): if force is not github.GithubObject.NotSet: post_parameters["force"] = force headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -123,7 +118,9 @@ class GitRef(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "object" in attributes: # pragma no branch - self._object = self._makeClassAttribute(github.GitObject.GitObject, attributes["object"]) + self._object = self._makeClassAttribute( + github.GitObject.GitObject, attributes["object"] + ) if "ref" in attributes: # pragma no branch self._ref = self._makeStringAttribute(attributes["ref"]) if "url" in attributes: # pragma no branch diff --git a/github/GitRelease.py b/github/GitRelease.py index 8ab79fdb..73be5c68 100644 --- a/github/GitRelease.py +++ b/github/GitRelease.py @@ -36,10 +36,12 @@ ################################################################################ from __future__ import absolute_import + from os.path import basename + import github.GithubObject -import github.NamedUser import github.GitReleaseAsset +import github.NamedUser import six @@ -176,24 +178,27 @@ class GitRelease(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/releases/:release_id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def update_release(self, name, message, draft=False, prerelease=False, - tag_name=github.GithubObject.NotSet, - target_commitish=github.GithubObject.NotSet): + def update_release( + self, + name, + message, + draft=False, + prerelease=False, + tag_name=github.GithubObject.NotSet, + target_commitish=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo/releases/:release_id `_ :rtype: :class:`github.GitRelease.GitRelease` """ - assert tag_name is github.GithubObject.NotSet \ - or isinstance(tag_name, (str, six.text_type)), \ - 'tag_name must be a str/unicode object' - assert target_commitish is github.GithubObject.NotSet \ - or isinstance(target_commitish, (str, six.text_type)), \ - 'target_commitish must be a str/unicode object' + assert tag_name is github.GithubObject.NotSet or isinstance( + tag_name, (str, six.text_type) + ), "tag_name must be a str/unicode object" + assert target_commitish is github.GithubObject.NotSet or isinstance( + target_commitish, (str, six.text_type) + ), "target_commitish must be a str/unicode object" assert isinstance(name, (str, six.text_type)), name assert isinstance(message, (str, six.text_type)), message assert isinstance(draft, bool), draft @@ -210,26 +215,32 @@ class GitRelease(github.GithubObject.CompletableGithubObject): # Do not set target_commitish to self.target_commitish when ommited, just don't send it # alltogether in that case, in order to match the Github API behaviour. Only send it when set. if target_commitish is not github.GithubObject.NotSet: - post_parameters['target_commitish'] = target_commitish + post_parameters["target_commitish"] = target_commitish headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True ) - return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) - def upload_asset(self, path, label="", content_type=github.GithubObject.NotSet, name=github.GithubObject.NotSet): + def upload_asset( + self, + path, + label="", + content_type=github.GithubObject.NotSet, + name=github.GithubObject.NotSet, + ): """ :calls: `POST https:///repos/:owner/:repo/releases/:release_id/assets `_ :rtype: :class:`github.GitReleaseAsset.GitReleaseAsset` """ assert isinstance(path, (str, six.text_type)), path assert isinstance(label, (str, six.text_type)), label - assert name is github.GithubObject.NotSet or isinstance(name, (str, six.text_type)), name + assert name is github.GithubObject.NotSet or isinstance( + name, (str, six.text_type) + ), name - post_parameters = { - "label": label - } + post_parameters = {"label": label} if name is github.GithubObject.NotSet: post_parameters["name"] = basename(path) else: @@ -242,9 +253,11 @@ class GitRelease(github.GithubObject.CompletableGithubObject): self.upload_url.split("{?")[0], parameters=post_parameters, headers=headers, - input=path + input=path, + ) + return github.GitReleaseAsset.GitReleaseAsset( + self._requester, resp_headers, data, completed=True ) - return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True) def get_assets(self): """ @@ -255,7 +268,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject): github.GitReleaseAsset.GitReleaseAsset, self._requester, self.url + "/assets", - None + None, ) def _initAttributes(self): @@ -285,13 +298,17 @@ class GitRelease(github.GithubObject.CompletableGithubObject): if "tag_name" in attributes: self._tag_name = self._makeStringAttribute(attributes["tag_name"]) if "target_commitish" in attributes: - self._target_commitish = self._makeStringAttribute(attributes["target_commitish"]) + self._target_commitish = self._makeStringAttribute( + attributes["target_commitish"] + ) if "draft" in attributes: self._draft = self._makeBoolAttribute(attributes["draft"]) if "prerelease" in attributes: self._prerelease = self._makeBoolAttribute(attributes["prerelease"]) if "author" in attributes: - self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) + self._author = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["author"] + ) if "url" in attributes: self._url = self._makeStringAttribute(attributes["url"]) if "upload_url" in attributes: diff --git a/github/GitReleaseAsset.py b/github/GitReleaseAsset.py index a92848a4..f831bac4 100644 --- a/github/GitReleaseAsset.py +++ b/github/GitReleaseAsset.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import six @@ -155,10 +156,7 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): Delete asset from the release. :rtype: bool """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) return True def update_asset(self, name, label=""): @@ -168,14 +166,9 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name assert isinstance(label, (str, six.text_type)), label - post_parameters = { - "name": name, - "label": label - } + post_parameters = {"name": name, "label": label} headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) return GitReleaseAsset(self._requester, headers, data, completed=True) @@ -203,7 +196,9 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): if "label" in attributes: # pragma no branch self._label = self._makeStringAttribute(attributes["label"]) if "uploader" in attributes: # pragma no branch - self._uploader = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["uploader"]) + self._uploader = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["uploader"] + ) if "content_type" in attributes: # pragma no branch self._content_type = self._makeStringAttribute(attributes["content_type"]) if "state" in attributes: # pragma no branch @@ -217,4 +212,6 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): if "updated_at" in attributes: # pragma no branch self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) if "browser_download_url" in attributes: # pragma no branch - self._browser_download_url = self._makeStringAttribute(attributes["browser_download_url"]) + self._browser_download_url = self._makeStringAttribute( + attributes["browser_download_url"] + ) diff --git a/github/GitTag.py b/github/GitTag.py index 5b9a41dd..fe108cb3 100644 --- a/github/GitTag.py +++ b/github/GitTag.py @@ -31,9 +31,9 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.GitAuthor +import github.GithubObject import github.GitObject @@ -105,12 +105,16 @@ class GitTag(github.GithubObject.CompletableGithubObject): if "message" in attributes: # pragma no branch self._message = self._makeStringAttribute(attributes["message"]) if "object" in attributes: # pragma no branch - self._object = self._makeClassAttribute(github.GitObject.GitObject, attributes["object"]) + self._object = self._makeClassAttribute( + github.GitObject.GitObject, attributes["object"] + ) if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "tag" in attributes: # pragma no branch self._tag = self._makeStringAttribute(attributes["tag"]) if "tagger" in attributes: # pragma no branch - self._tagger = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["tagger"]) + self._tagger = self._makeClassAttribute( + github.GitAuthor.GitAuthor, attributes["tagger"] + ) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) diff --git a/github/GitTree.py b/github/GitTree.py index a5c0fd79..866d7866 100644 --- a/github/GitTree.py +++ b/github/GitTree.py @@ -31,8 +31,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.GitTreeElement @@ -81,6 +81,8 @@ class GitTree(github.GithubObject.CompletableGithubObject): if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "tree" in attributes: # pragma no branch - self._tree = self._makeListOfClassesAttribute(github.GitTreeElement.GitTreeElement, attributes["tree"]) + self._tree = self._makeListOfClassesAttribute( + github.GitTreeElement.GitTreeElement, attributes["tree"] + ) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) diff --git a/github/GitTreeElement.py b/github/GitTreeElement.py index eadf7d1e..937e63ca 100644 --- a/github/GitTreeElement.py +++ b/github/GitTreeElement.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/GithubException.py b/github/GithubException.py index c72fad89..1dd5bd88 100644 --- a/github/GithubException.py +++ b/github/GithubException.py @@ -92,6 +92,7 @@ class BadAttributeException(Exception): """ Exception raised when Github returns an attribute with the wrong type. """ + def __init__(self, actualValue, expectedType, transformationException): self.__actualValue = actualValue self.__expectedType = expectedType diff --git a/github/GithubObject.py b/github/GithubObject.py index d9b0545c..0c7b3b54 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -33,13 +33,14 @@ ################################################################################ from __future__ import absolute_import + import datetime from operator import itemgetter -from . import GithubException -from . import Consts import six +from . import Consts, GithubException + class _NotSetType: def __repr__(self): @@ -64,7 +65,9 @@ class _BadAttribute: @property def value(self): - raise GithubException.BadAttributeException(self.__value, self.__expectedType, self.__exception) + raise GithubException.BadAttributeException( + self.__value, self.__expectedType, self.__exception + ) class GithubObject(object): @@ -72,9 +75,9 @@ class GithubObject(object): Base class for all classes representing objects returned by the API. """ - ''' + """ A global debug flag to enable header validation by requester for all objects - ''' + """ CHECK_AFTER_INIT_FLAG = False @classmethod @@ -116,7 +119,7 @@ class GithubObject(object): @staticmethod def _parentUrl(url): - return "/".join(url.split("/")[: -1]) + return "/".join(url.split("/")[:-1]) @staticmethod def __makeSimpleAttribute(value, type): @@ -127,7 +130,9 @@ class GithubObject(object): @staticmethod def __makeSimpleListAttribute(value, type): - if isinstance(value, list) and all(isinstance(element, type) for element in value): + if isinstance(value, list) and all( + isinstance(element, type) for element in value + ): return _ValuedAttribute(value) else: return _BadAttribute(value, [type]) @@ -166,24 +171,38 @@ class GithubObject(object): @staticmethod def _makeTimestampAttribute(value): - return GithubObject.__makeTransformedAttribute(value, six.integer_types, datetime.datetime.utcfromtimestamp) + return GithubObject.__makeTransformedAttribute( + value, six.integer_types, datetime.datetime.utcfromtimestamp + ) @staticmethod def _makeDatetimeAttribute(value): def parseDatetime(s): - if len(s) == 24: # pragma no branch (This branch was used only when creating a download) + 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) + 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])) + 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, six.text_type), parseDatetime) + return GithubObject.__makeTransformedAttribute( + value, (str, six.text_type), parseDatetime + ) def _makeClassAttribute(self, klass, value): - return GithubObject.__makeTransformedAttribute(value, dict, lambda value: klass(self._requester, self._headers, value, completed=False)) + return GithubObject.__makeTransformedAttribute( + value, + dict, + lambda value: klass(self._requester, self._headers, value, completed=False), + ) @staticmethod def _makeListOfStringsAttribute(value): @@ -202,46 +221,66 @@ class GithubObject(object): return GithubObject.__makeSimpleListAttribute(value, list) def _makeListOfClassesAttribute(self, klass, value): - if isinstance(value, list) and all(isinstance(element, dict) for element in value): - return _ValuedAttribute([klass(self._requester, self._headers, element, completed=False) for element in value]) + if isinstance(value, list) and all( + isinstance(element, dict) for element in value + ): + return _ValuedAttribute( + [ + klass(self._requester, self._headers, element, completed=False) + for element in value + ] + ) else: return _BadAttribute(value, [dict]) def _makeDictOfStringsToClassesAttribute(self, klass, value): - if isinstance(value, dict) and all(isinstance(key, (str, six.text_type)) and isinstance(element, dict) for key, element in six.iteritems(value)): - return _ValuedAttribute(dict((key, klass(self._requester, self._headers, element, completed=False)) for key, element in six.iteritems(value))) + if isinstance(value, dict) and all( + isinstance(key, (str, six.text_type)) and isinstance(element, dict) + for key, element in six.iteritems(value) + ): + return _ValuedAttribute( + dict( + ( + key, + klass(self._requester, self._headers, element, completed=False), + ) + for key, element in six.iteritems(value) + ) + ) else: return _BadAttribute(value, {(str, six.text_type): dict}) @property def etag(self): - ''' + """ :type: str - ''' + """ return self._headers.get(Consts.RES_ETAG) @property def last_modified(self): - ''' + """ :type: str - ''' + """ return self._headers.get(Consts.RES_LAST_MODIFIED) def get__repr__(self, params): """ Converts the object to a nicely printable string. """ + def format_params(params): items = list(params.items()) for k, v in sorted(items, key=itemgetter(0), reverse=True): if isinstance(v, bytes): - v = v.decode('utf-8') + v = v.decode("utf-8") if isinstance(v, six.text_type): v = u'"{v}"'.format(v=v) - yield u'{k}={v}'.format(k=k, v=v) - return u'{class_name}({params})'.format( + yield u"{k}={v}".format(k=k, v=v) + + return u"{class_name}({params})".format( class_name=self.__class__.__name__, - params=u", ".join(list(format_params(params))) + params=u", ".join(list(format_params(params))), ) @@ -271,19 +310,18 @@ class CompletableGithubObject(GithubObject): def __complete(self): if self._url.value is None: - raise GithubException.IncompletableObject(400, "Returned object contains no URL") - headers, data = self._requester.requestJsonAndCheck( - "GET", - self._url.value - ) + raise GithubException.IncompletableObject( + 400, "Returned object contains no URL" + ) + headers, data = self._requester.requestJsonAndCheck("GET", self._url.value) self._storeAndUseAttributes(headers, data) self.__completed = True def update(self, additional_headers=None): - ''' + """ Check and update the object with conditional request :rtype: Boolean value indicating whether the object is changed - ''' + """ conditionalRequestHeader = dict() if self.etag is not None: conditionalRequestHeader[Consts.REQ_IF_NONE_MATCH] = self.etag @@ -293,14 +331,14 @@ class CompletableGithubObject(GithubObject): conditionalRequestHeader.update(additional_headers) status, responseHeaders, output = self._requester.requestJson( - "GET", - self._url.value, - headers=conditionalRequestHeader + "GET", self._url.value, headers=conditionalRequestHeader ) if status == 304: return False else: - headers, data = self._requester._Requester__check(status, responseHeaders, output) + headers, data = self._requester._Requester__check( + status, responseHeaders, output + ) self._storeAndUseAttributes(headers, data) self.__completed = True return True diff --git a/github/GitignoreTemplate.py b/github/GitignoreTemplate.py index 650885dd..b3eaefe5 100644 --- a/github/GitignoreTemplate.py +++ b/github/GitignoreTemplate.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/Hook.py b/github/Hook.py index 30b2ab9f..53ae578a 100644 --- a/github/Hook.py +++ b/github/Hook.py @@ -32,8 +32,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.HookResponse import six @@ -139,12 +139,17 @@ class Hook(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/hooks/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, name, config, events=github.GithubObject.NotSet, add_events=github.GithubObject.NotSet, remove_events=github.GithubObject.NotSet, active=github.GithubObject.NotSet): + def edit( + self, + name, + config, + events=github.GithubObject.NotSet, + add_events=github.GithubObject.NotSet, + remove_events=github.GithubObject.NotSet, + active=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo/hooks/:id `_ :param name: string @@ -157,9 +162,15 @@ class Hook(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name assert isinstance(config, dict), config - assert events is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in events), events - assert add_events is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in add_events), add_events - assert remove_events is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in remove_events), remove_events + assert events is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in events + ), events + assert add_events is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in add_events + ), add_events + assert remove_events is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in remove_events + ), remove_events assert active is github.GithubObject.NotSet or isinstance(active, bool), active post_parameters = { "name": name, @@ -174,9 +185,7 @@ class Hook(github.GithubObject.CompletableGithubObject): if active is not github.GithubObject.NotSet: post_parameters["active"] = active headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -185,20 +194,14 @@ class Hook(github.GithubObject.CompletableGithubObject): :calls: `POST /repos/:owner/:repo/hooks/:id/tests `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/tests" - ) + headers, data = self._requester.requestJsonAndCheck("POST", self.url + "/tests") def ping(self): """ :calls: `POST /repos/:owner/:repo/hooks/:id/pings `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/pings" - ) + headers, data = self._requester.requestJsonAndCheck("POST", self.url + "/pings") def _initAttributes(self): self._active = github.GithubObject.NotSet @@ -225,7 +228,9 @@ class Hook(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "last_response" in attributes: # pragma no branch - self._last_response = self._makeClassAttribute(github.HookResponse.HookResponse, attributes["last_response"]) + self._last_response = self._makeClassAttribute( + github.HookResponse.HookResponse, attributes["last_response"] + ) if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "test_url" in attributes: # pragma no branch diff --git a/github/HookDescription.py b/github/HookDescription.py index 0a971dc7..6c23613f 100644 --- a/github/HookDescription.py +++ b/github/HookDescription.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -84,4 +85,6 @@ class HookDescription(github.GithubObject.NonCompletableGithubObject): if "schema" in attributes: # pragma no branch self._schema = self._makeListOfListOfStringsAttribute(attributes["schema"]) if "supported_events" in attributes: # pragma no branch - self._supported_events = self._makeListOfStringsAttribute(attributes["supported_events"]) + self._supported_events = self._makeListOfStringsAttribute( + attributes["supported_events"] + ) diff --git a/github/HookResponse.py b/github/HookResponse.py index 1a8172ba..692700c1 100644 --- a/github/HookResponse.py +++ b/github/HookResponse.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/InputFileContent.py b/github/InputFileContent.py index 33b6481e..734f4fe3 100644 --- a/github/InputFileContent.py +++ b/github/InputFileContent.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import six @@ -45,7 +46,9 @@ class InputFileContent(object): """ assert isinstance(content, (str, six.text_type)), content - assert new_name is github.GithubObject.NotSet or isinstance(new_name, (str, six.text_type)), new_name + assert new_name is github.GithubObject.NotSet or isinstance( + new_name, (str, six.text_type) + ), new_name self.__newName = new_name self.__content = content diff --git a/github/InputGitAuthor.py b/github/InputGitAuthor.py index 667fd54c..f78997eb 100644 --- a/github/InputGitAuthor.py +++ b/github/InputGitAuthor.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import six @@ -49,7 +50,9 @@ class InputGitAuthor(object): assert isinstance(name, (str, six.text_type)), name assert isinstance(email, (str, six.text_type)), email - assert date is github.GithubObject.NotSet or isinstance(date, (str, six.text_type)), date # @todo Datetime? + assert date is github.GithubObject.NotSet or isinstance( + date, (str, six.text_type) + ), date # @todo Datetime? self.__name = name self.__email = email diff --git a/github/InputGitTreeElement.py b/github/InputGitTreeElement.py index 78c354cc..22732e89 100644 --- a/github/InputGitTreeElement.py +++ b/github/InputGitTreeElement.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import six @@ -38,7 +39,14 @@ class InputGitTreeElement(object): This class represents InputGitTreeElements """ - def __init__(self, path, mode, type, content=github.GithubObject.NotSet, sha=github.GithubObject.NotSet): + def __init__( + self, + path, + mode, + type, + content=github.GithubObject.NotSet, + sha=github.GithubObject.NotSet, + ): """ :param path: string :param mode: string @@ -50,8 +58,12 @@ class InputGitTreeElement(object): assert isinstance(path, (str, six.text_type)), path assert isinstance(mode, (str, six.text_type)), mode assert isinstance(type, (str, six.text_type)), type - assert content is github.GithubObject.NotSet or isinstance(content, (str, six.text_type)), content - assert sha is github.GithubObject.NotSet or isinstance(sha, (str, six.text_type)), sha + assert content is github.GithubObject.NotSet or isinstance( + content, (str, six.text_type) + ), content + assert sha is github.GithubObject.NotSet or isinstance( + sha, (str, six.text_type) + ), sha self.__path = path self.__mode = mode self.__type = type diff --git a/github/Installation.py b/github/Installation.py index c235c249..fd9e2839 100644 --- a/github/Installation.py +++ b/github/Installation.py @@ -26,18 +26,18 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.PaginatedList -import github.Gist -import github.Repository -import github.Plan -import github.Organization -import github.UserKey -import github.Issue -import github.Event import github.Authorization +import github.Event +import github.Gist +import github.GithubObject +import github.Issue import github.Notification +import github.Organization +import github.PaginatedList +import github.Plan +import github.Repository +import github.UserKey from . import Consts @@ -69,7 +69,7 @@ class Installation(github.GithubObject.NonCompletableGithubObject): firstUrl="/installation/repositories", firstParams=url_parameters, headers=INTEGRATION_PREVIEW_HEADERS, - list_item='repositories' + list_item="repositories", ) def _initAttributes(self): diff --git a/github/InstallationAuthorization.py b/github/InstallationAuthorization.py index d95fe0db..b552dbbc 100644 --- a/github/InstallationAuthorization.py +++ b/github/InstallationAuthorization.py @@ -26,9 +26,10 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject -import github.PaginatedList import github.NamedUser +import github.PaginatedList class InstallationAuthorization(github.GithubObject.NonCompletableGithubObject): @@ -71,4 +72,6 @@ class InstallationAuthorization(github.GithubObject.NonCompletableGithubObject): if "expires_at" in attributes: # pragma no branch self._expires_at = self._makeDatetimeAttribute(attributes["expires_at"]) if "on_behalf_of" in attributes: # pragma no branch - self._on_behalf_of = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["on_behalf_of"]) + self._on_behalf_of = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["on_behalf_of"] + ) diff --git a/github/Invitation.py b/github/Invitation.py index cee0b5a4..0f5269de 100644 --- a/github/Invitation.py +++ b/github/Invitation.py @@ -25,6 +25,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -112,13 +113,19 @@ class Invitation(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "repository" in attributes: # pragma no branch - self._assignee = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) + self._assignee = self._makeClassAttribute( + github.Repository.Repository, attributes["repository"] + ) if "created_at" in attributes: # pragma no branch self._closed_at = self._makeDatetimeAttribute(attributes["created_at"]) if "invitee" in attributes: # pragma no branch - self._invitee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["invitee"]) + self._invitee = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["invitee"] + ) if "inviter" in attributes: # pragma no branch - self._inviter = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["inviter"]) + self._inviter = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["inviter"] + ) if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) diff --git a/github/Issue.py b/github/Issue.py index 9fe6aab6..e2d6be80 100644 --- a/github/Issue.py +++ b/github/Issue.py @@ -43,22 +43,23 @@ ################################################################################ from __future__ import absolute_import -import six.moves.urllib.parse -import datetime -import github.GithubObject -import github.PaginatedList -import github.Repository -import github.IssueEvent -import github.Label -import github.NamedUser -import github.Milestone +import datetime + +import github.GithubObject import github.IssueComment +import github.IssueEvent import github.IssuePullRequest +import github.Label +import github.Milestone +import github.NamedUser +import github.PaginatedList import github.Reaction +import github.Repository +import six +import six.moves.urllib.parse from . import Consts -import six class Issue(github.GithubObject.CompletableGithubObject): @@ -67,7 +68,9 @@ class Issue(github.GithubObject.CompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"number": self._number.value, "title": self._title.value}) + return self.get__repr__( + {"number": self._number.value, "title": self._title.value} + ) @property def assignee(self): @@ -206,7 +209,11 @@ class Issue(github.GithubObject.CompletableGithubObject): if self._repository is github.GithubObject.NotSet: # The repository was not set automatically, so it must be looked up by url. repo_url = "/".join(self.url.split("/")[:-2]) - self._repository = github.GithubObject._ValuedAttribute(github.Repository.Repository(self._requester, self._headers, {'url': repo_url}, completed=False)) + self._repository = github.GithubObject._ValuedAttribute( + github.Repository.Repository( + self._requester, self._headers, {"url": repo_url}, completed=False + ) + ) return self._repository.value @property @@ -271,10 +278,11 @@ class Issue(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PullRequest.PullRequest` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - "/pulls/".join(self.url.rsplit("/issues/", 1)) + "GET", "/pulls/".join(self.url.rsplit("/issues/", 1)) + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True ) - return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) def add_to_assignees(self, *assignees): """ @@ -282,12 +290,20 @@ class Issue(github.GithubObject.CompletableGithubObject): :param assignee: :class:`github.NamedUser.NamedUser` or string :rtype: None """ - assert all(isinstance(element, (github.NamedUser.NamedUser, str, six.text_type)) for element in assignees), assignees - post_parameters = {"assignees": [assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee for assignee in assignees]} + assert all( + isinstance(element, (github.NamedUser.NamedUser, str, six.text_type)) + for element in assignees + ), assignees + post_parameters = { + "assignees": [ + assignee.login + if isinstance(assignee, github.NamedUser.NamedUser) + else assignee + for assignee in assignees + ] + } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/assignees", - input=post_parameters + "POST", self.url + "/assignees", input=post_parameters ) self._useAttributes(data) @@ -297,12 +313,16 @@ class Issue(github.GithubObject.CompletableGithubObject): :param label: :class:`github.Label.Label` or string :rtype: None """ - assert all(isinstance(element, (github.Label.Label, str, six.text_type)) for element in labels), labels - post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels] + assert all( + isinstance(element, (github.Label.Label, str, six.text_type)) + for element in labels + ), labels + post_parameters = [ + label.name if isinstance(label, github.Label.Label) else label + for label in labels + ] headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/labels", - input=post_parameters + "POST", self.url + "/labels", input=post_parameters ) def create_comment(self, body): @@ -316,11 +336,11 @@ class Issue(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/comments", - input=post_parameters + "POST", self.url + "/comments", input=post_parameters + ) + return github.IssueComment.IssueComment( + self._requester, headers, data, completed=True ) - return github.IssueComment.IssueComment(self._requester, headers, data, completed=True) def delete_labels(self): """ @@ -328,11 +348,19 @@ class Issue(github.GithubObject.CompletableGithubObject): :rtype: None """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/labels" + "DELETE", self.url + "/labels" ) - def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet, assignee=github.GithubObject.NotSet, state=github.GithubObject.NotSet, milestone=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, assignees=github.GithubObject.NotSet): + def edit( + self, + title=github.GithubObject.NotSet, + body=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + milestone=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + assignees=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo/issues/:number `_ :param title: string @@ -344,13 +372,34 @@ class Issue(github.GithubObject.CompletableGithubObject): :param labels: list of string :rtype: None """ - assert title is github.GithubObject.NotSet or isinstance(title, (str, six.text_type)), title - assert body is github.GithubObject.NotSet or isinstance(body, (str, six.text_type)), body - assert assignee is github.GithubObject.NotSet or assignee is None or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, six.text_type)), assignee - assert assignees is github.GithubObject.NotSet or all(isinstance(element, github.NamedUser.NamedUser) or isinstance(element, (str, six.text_type)) for element in assignees), assignees - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert milestone is github.GithubObject.NotSet or milestone is None or isinstance(milestone, github.Milestone.Milestone), milestone - assert labels is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in labels), labels + assert title is github.GithubObject.NotSet or isinstance( + title, (str, six.text_type) + ), title + assert body is github.GithubObject.NotSet or isinstance( + body, (str, six.text_type) + ), body + assert ( + assignee is github.GithubObject.NotSet + or assignee is None + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, (str, six.text_type)) + ), assignee + assert assignees is github.GithubObject.NotSet or all( + isinstance(element, github.NamedUser.NamedUser) + or isinstance(element, (str, six.text_type)) + for element in assignees + ), assignees + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert ( + milestone is github.GithubObject.NotSet + or milestone is None + or isinstance(milestone, github.Milestone.Milestone) + ), milestone + assert labels is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in labels + ), labels post_parameters = dict() if title is not github.GithubObject.NotSet: post_parameters["title"] = title @@ -360,19 +409,22 @@ class Issue(github.GithubObject.CompletableGithubObject): if isinstance(assignee, (str, six.text_type)): post_parameters["assignee"] = assignee else: - post_parameters["assignee"] = assignee._identity if assignee else '' + post_parameters["assignee"] = assignee._identity if assignee else "" if assignees is not github.GithubObject.NotSet: - post_parameters["assignees"] = [element._identity if isinstance(element, github.NamedUser.NamedUser) else element for element in assignees] + post_parameters["assignees"] = [ + element._identity + if isinstance(element, github.NamedUser.NamedUser) + else element + for element in assignees + ] if state is not github.GithubObject.NotSet: post_parameters["state"] = state if milestone is not github.GithubObject.NotSet: - post_parameters["milestone"] = milestone._identity if milestone else '' + post_parameters["milestone"] = milestone._identity if milestone else "" if labels is not github.GithubObject.NotSet: post_parameters["labels"] = labels headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -389,7 +441,7 @@ class Issue(github.GithubObject.CompletableGithubObject): "PUT", self.url + "/lock", input=put_parameters, - headers={'Accept': Consts.mediaTypeLockReasonPreview} + headers={"Accept": Consts.mediaTypeLockReasonPreview}, ) def unlock(self): @@ -398,8 +450,7 @@ class Issue(github.GithubObject.CompletableGithubObject): :rtype: None """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/lock" + "DELETE", self.url + "/lock" ) def get_comment(self, id): @@ -410,10 +461,11 @@ class Issue(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self._parentUrl(self.url) + "/comments/" + str(id) + "GET", self._parentUrl(self.url) + "/comments/" + str(id) + ) + return github.IssueComment.IssueComment( + self._requester, headers, data, completed=True ) - return github.IssueComment.IssueComment(self._requester, headers, data, completed=True) def get_comments(self, since=github.GithubObject.NotSet): """ @@ -421,7 +473,9 @@ class Issue(github.GithubObject.CompletableGithubObject): :param since: datetime.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.datetime + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -429,7 +483,7 @@ class Issue(github.GithubObject.CompletableGithubObject): github.IssueComment.IssueComment, self._requester, self.url + "/comments", - url_parameters + url_parameters, ) def get_events(self): @@ -442,7 +496,7 @@ class Issue(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/events", None, - headers={'Accept': Consts.mediaTypeLockReasonPreview} + headers={"Accept": Consts.mediaTypeLockReasonPreview}, ) def get_labels(self): @@ -451,10 +505,7 @@ class Issue(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` """ return github.PaginatedList.PaginatedList( - github.Label.Label, - self._requester, - self.url + "/labels", - None + github.Label.Label, self._requester, self.url + "/labels", None ) def remove_from_assignees(self, *assignees): @@ -463,12 +514,20 @@ class Issue(github.GithubObject.CompletableGithubObject): :param assignee: :class:`github.NamedUser.NamedUser` or string :rtype: None """ - assert all(isinstance(element, (github.NamedUser.NamedUser, str, six.text_type)) for element in assignees), assignees - post_parameters = {"assignees": [assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee for assignee in assignees]} + assert all( + isinstance(element, (github.NamedUser.NamedUser, str, six.text_type)) + for element in assignees + ), assignees + post_parameters = { + "assignees": [ + assignee.login + if isinstance(assignee, github.NamedUser.NamedUser) + else assignee + for assignee in assignees + ] + } headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/assignees", - input=post_parameters + "DELETE", self.url + "/assignees", input=post_parameters ) self._useAttributes(data) @@ -484,8 +543,7 @@ class Issue(github.GithubObject.CompletableGithubObject): else: label = six.moves.urllib.parse.quote(label) headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/labels/" + label + "DELETE", self.url + "/labels/" + label ) def set_labels(self, *labels): @@ -494,12 +552,16 @@ class Issue(github.GithubObject.CompletableGithubObject): :param labels: list of :class:`github.Label.Label` or strings :rtype: None """ - assert all(isinstance(element, (github.Label.Label, str, six.text_type)) for element in labels), labels - post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels] + assert all( + isinstance(element, (github.Label.Label, str, six.text_type)) + for element in labels + ), labels + post_parameters = [ + label.name if isinstance(label, github.Label.Label) else label + for label in labels + ] headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/labels", - input=post_parameters + "PUT", self.url + "/labels", input=post_parameters ) def get_reactions(self): @@ -512,7 +574,7 @@ class Issue(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/reactions", None, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) def create_reaction(self, reaction_type): @@ -521,9 +583,17 @@ class Issue(github.GithubObject.CompletableGithubObject): :param reaction_type: string :rtype: :class:`github.Reaction.Reaction` """ - assert isinstance(reaction_type, (str, six.text_type)), "reaction type should be a string" - assert reaction_type in ["+1", "-1", "laugh", "confused", "heart", "hooray"], \ - "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" + assert isinstance( + reaction_type, (str, six.text_type) + ), "reaction type should be a string" + assert reaction_type in [ + "+1", + "-1", + "laugh", + "confused", + "heart", + "hooray", + ], "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" post_parameters = { "content": reaction_type, @@ -532,7 +602,7 @@ class Issue(github.GithubObject.CompletableGithubObject): "POST", self.url + "/reactions", input=post_parameters, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) @@ -566,22 +636,34 @@ class Issue(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "active_lock_reason" in attributes: # pragma no branch - self._active_lock_reason = self._makeStringAttribute(attributes["active_lock_reason"]) + self._active_lock_reason = self._makeStringAttribute( + attributes["active_lock_reason"] + ) if "assignee" in attributes: # pragma no branch - self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"]) + self._assignee = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["assignee"] + ) if "assignees" in attributes: # pragma no branch - self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, attributes["assignees"]) + self._assignees = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, attributes["assignees"] + ) elif "assignee" in attributes: if attributes["assignee"] is not None: - self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, [attributes["assignee"]]) + self._assignees = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, [attributes["assignee"]] + ) else: - self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, []) + self._assignees = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, [] + ) if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "closed_at" in attributes: # pragma no branch self._closed_at = self._makeDatetimeAttribute(attributes["closed_at"]) if "closed_by" in attributes: # pragma no branch - self._closed_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["closed_by"]) + self._closed_by = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["closed_by"] + ) if "comments" in attributes: # pragma no branch self._comments = self._makeIntAttribute(attributes["comments"]) if "comments_url" in attributes: # pragma no branch @@ -595,19 +677,27 @@ class Issue(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "labels" in attributes: # pragma no branch - self._labels = self._makeListOfClassesAttribute(github.Label.Label, attributes["labels"]) + self._labels = self._makeListOfClassesAttribute( + github.Label.Label, attributes["labels"] + ) if "labels_url" in attributes: # pragma no branch self._labels_url = self._makeStringAttribute(attributes["labels_url"]) if "locked" in attributes: # pragma no branch self._locked = self._makeBoolAttribute(attributes["locked"]) if "milestone" in attributes: # pragma no branch - self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"]) + self._milestone = self._makeClassAttribute( + github.Milestone.Milestone, attributes["milestone"] + ) if "number" in attributes: # pragma no branch self._number = self._makeIntAttribute(attributes["number"]) if "pull_request" in attributes: # pragma no branch - self._pull_request = self._makeClassAttribute(github.IssuePullRequest.IssuePullRequest, attributes["pull_request"]) + self._pull_request = self._makeClassAttribute( + github.IssuePullRequest.IssuePullRequest, attributes["pull_request"] + ) if "repository" in attributes: # pragma no branch - self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) + self._repository = self._makeClassAttribute( + github.Repository.Repository, attributes["repository"] + ) if "state" in attributes: # pragma no branch self._state = self._makeStringAttribute(attributes["state"]) if "title" in attributes: # pragma no branch @@ -617,4 +707,6 @@ class Issue(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/IssueComment.py b/github/IssueComment.py index 2e2c659f..57aa5d30 100644 --- a/github/IssueComment.py +++ b/github/IssueComment.py @@ -34,11 +34,12 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.NamedUser +import six from . import Consts -import six class IssueComment(github.GithubObject.CompletableGithubObject): @@ -118,10 +119,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/issues/comments/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def edit(self, body): """ @@ -134,9 +132,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -151,7 +147,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/reactions", None, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) def create_reaction(self, reaction_type): @@ -161,9 +157,17 @@ class IssueComment(github.GithubObject.CompletableGithubObject): :param reaction_type: string :rtype: :class:`github.Reaction.Reaction` """ - assert isinstance(reaction_type, (str, six.text_type)), "reaction type should be a string" - assert reaction_type in ["+1", "-1", "laugh", "confused", "heart", "hooray"], \ - "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" + assert isinstance( + reaction_type, (str, six.text_type) + ), "reaction type should be a string" + assert reaction_type in [ + "+1", + "-1", + "laugh", + "confused", + "heart", + "hooray", + ], "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" post_parameters = { "content": reaction_type, @@ -172,7 +176,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): "POST", self.url + "/reactions", input=post_parameters, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) @@ -202,4 +206,6 @@ class IssueComment(github.GithubObject.CompletableGithubObject): if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/IssueEvent.py b/github/IssueEvent.py index e813d7f6..f7da5b69 100644 --- a/github/IssueEvent.py +++ b/github/IssueEvent.py @@ -32,8 +32,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.Issue import github.NamedUser @@ -212,7 +212,9 @@ class IssueEvent(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "actor" in attributes: # pragma no branch - self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"]) + self._actor = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["actor"] + ) if "commit_id" in attributes: # pragma no branch self._commit_id = self._makeStringAttribute(attributes["commit_id"]) if "created_at" in attributes: # pragma no branch @@ -222,7 +224,9 @@ class IssueEvent(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "issue" in attributes: # pragma no branch - self._issue = self._makeClassAttribute(github.Issue.Issue, attributes["issue"]) + self._issue = self._makeClassAttribute( + github.Issue.Issue, attributes["issue"] + ) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "node_id" in attributes: # pragma no branch @@ -230,20 +234,34 @@ class IssueEvent(github.GithubObject.CompletableGithubObject): if "commit_url" in attributes: # pragma no branch self._commit_url = self._makeStringAttribute(attributes["commit_url"]) if "label" in attributes: # pragma no branch - self._label = self._makeClassAttribute(github.Label.Label, attributes["label"]) + self._label = self._makeClassAttribute( + github.Label.Label, attributes["label"] + ) if "assignee" in attributes: # pragma no branch - self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"]) + self._assignee = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["assignee"] + ) if "assigner" in attributes: # pragma no branch - self._assigner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assigner"]) + self._assigner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["assigner"] + ) if "review_requester" in attributes: # pragma no branch - self._review_requester = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["review_requester"]) + self._review_requester = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["review_requester"] + ) if "requested_reviewer" in attributes: # pragma no branch - self._requested_reviewer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["requested_reviewer"]) + self._requested_reviewer = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["requested_reviewer"] + ) if "milestone" in attributes: # pragma no branch - self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"]) + self._milestone = self._makeClassAttribute( + github.Milestone.Milestone, attributes["milestone"] + ) if "rename" in attributes: # pragma no branch self._rename = self._makeDictAttribute(attributes["rename"]) if "dismissed_review" in attributes: # pragma no branch - self._dismissed_review = self._makeDictAttribute(attributes["dismissed_review"]) + self._dismissed_review = self._makeDictAttribute( + attributes["dismissed_review"] + ) if "lock_reason" in attributes: # pragma no branch self._lock_reason = self._makeStringAttribute(attributes["lock_reason"]) diff --git a/github/IssuePullRequest.py b/github/IssuePullRequest.py index e3f637e0..9ee61f9d 100644 --- a/github/IssuePullRequest.py +++ b/github/IssuePullRequest.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/Label.py b/github/Label.py index b819d4e8..b28f02b0 100644 --- a/github/Label.py +++ b/github/Label.py @@ -32,12 +32,12 @@ ################################################################################ from __future__ import absolute_import -import six.moves.urllib.parse import github.GithubObject +import six +import six.moves.urllib.parse from . import Consts -import six class Label(github.GithubObject.CompletableGithubObject): @@ -85,10 +85,7 @@ class Label(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/labels/:name `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def edit(self, name, color, description=github.GithubObject.NotSet): """ @@ -100,7 +97,9 @@ class Label(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name assert isinstance(color, (str, six.text_type)), color - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description post_parameters = { "name": name, "color": color, @@ -111,7 +110,7 @@ class Label(github.GithubObject.CompletableGithubObject): "PATCH", self.url, input=post_parameters, - headers={'Accept': Consts.mediaTypeLabelDescriptionSearchPreview} + headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, ) self._useAttributes(data) diff --git a/github/License.py b/github/License.py index e4fca8f6..dd5414db 100644 --- a/github/License.py +++ b/github/License.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -149,12 +150,20 @@ class License(github.GithubObject.CompletableGithubObject): if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "implementation" in attributes: # pragma no branch - self._implementation = self._makeStringAttribute(attributes["implementation"]) + self._implementation = self._makeStringAttribute( + attributes["implementation"] + ) if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "permissions" in attributes: # pragma no branch - self._permissions = self._makeListOfStringsAttribute(attributes["permissions"]) + self._permissions = self._makeListOfStringsAttribute( + attributes["permissions"] + ) if "conditions" in attributes: # pragma no branch - self._conditions = self._makeListOfStringsAttribute(attributes["conditions"]) + self._conditions = self._makeListOfStringsAttribute( + attributes["conditions"] + ) if "limitations" in attributes: # pragma no branch - self._limitations = self._makeListOfStringsAttribute(attributes["limitations"]) + self._limitations = self._makeListOfStringsAttribute( + attributes["limitations"] + ) diff --git a/github/MainClass.py b/github/MainClass.py index b0e524fe..8e6ca1d1 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -49,32 +49,34 @@ ################################################################################ from __future__ import absolute_import -import datetime +import datetime import pickle import time -import requests + +import github.Gist +import github.GithubObject +import github.License +import github.NamedUser +import github.PaginatedList +import github.Topic import jwt +import requests +import six import urllib3 +from . import ( + AuthenticatedUser, + Consts, + GithubException, + GitignoreTemplate, + HookDescription, + Installation, + InstallationAuthorization, + RateLimit, + Repository, +) from .Requester import Requester -from . import AuthenticatedUser -import github.NamedUser -import github.Gist -import github.PaginatedList -from . import Repository -from . import Installation -import github.License -import github.Topic -import github.GithubObject -from . import HookDescription -from . import GitignoreTemplate -from . import RateLimit -from . import InstallationAuthorization -from . import GithubException - -from . import Consts -import six DEFAULT_BASE_URL = "https://api.github.com" DEFAULT_STATUS_URL = "https://status.github.com" @@ -90,7 +92,21 @@ class Github(object): This is the main class you instantiate to access the Github API v3. Optional parameters allow different authentication methods. """ - def __init__(self, login_or_token=None, password=None, jwt=None, base_url=DEFAULT_BASE_URL, timeout=DEFAULT_TIMEOUT, client_id=None, client_secret=None, user_agent='PyGithub/Python', per_page=DEFAULT_PER_PAGE, api_preview=False, verify=True, retry=None): + def __init__( + self, + login_or_token=None, + password=None, + jwt=None, + base_url=DEFAULT_BASE_URL, + timeout=DEFAULT_TIMEOUT, + client_id=None, + client_secret=None, + user_agent="PyGithub/Python", + per_page=DEFAULT_PER_PAGE, + api_preview=False, + verify=True, + retry=None, + ): """ :param login_or_token: string :param password: string @@ -104,17 +120,42 @@ class Github(object): :param retry: int or urllib3.util.retry.Retry object """ - assert login_or_token is None or isinstance(login_or_token, (str, six.text_type)), login_or_token + assert login_or_token is None or isinstance( + login_or_token, (str, six.text_type) + ), login_or_token assert password is None or isinstance(password, (str, six.text_type)), password assert jwt is None or isinstance(jwt, (str, six.text_type)), jwt assert isinstance(base_url, (str, six.text_type)), base_url assert isinstance(timeout, six.integer_types), timeout - assert client_id is None or isinstance(client_id, (str, six.text_type)), client_id - assert client_secret is None or isinstance(client_secret, (str, six.text_type)), client_secret - assert user_agent is None or isinstance(user_agent, (str, six.text_type)), user_agent + assert client_id is None or isinstance( + client_id, (str, six.text_type) + ), client_id + assert client_secret is None or isinstance( + client_secret, (str, six.text_type) + ), client_secret + assert user_agent is None or isinstance( + user_agent, (str, six.text_type) + ), user_agent assert isinstance(api_preview, (bool)) - assert retry is None or isinstance(retry, (int)) or isinstance(retry, (urllib3.util.Retry)) - self.__requester = Requester(login_or_token, password, jwt, base_url, timeout, client_id, client_secret, user_agent, per_page, api_preview, verify, retry) + assert ( + retry is None + or isinstance(retry, (int)) + or isinstance(retry, (urllib3.util.Retry)) + ) + self.__requester = Requester( + login_or_token, + password, + jwt, + base_url, + timeout, + client_id, + client_secret, + user_agent, + per_page, + api_preview, + verify, + retry, + ) def __get_FIX_REPO_GET_GIT_REF(self): """ @@ -125,7 +166,9 @@ class Github(object): def __set_FIX_REPO_GET_GIT_REF(self, value): self.__requester.FIX_REPO_GET_GIT_REF = value - FIX_REPO_GET_GIT_REF = property(__get_FIX_REPO_GET_GIT_REF, __set_FIX_REPO_GET_GIT_REF) + FIX_REPO_GET_GIT_REF = property( + __get_FIX_REPO_GET_GIT_REF, __set_FIX_REPO_GET_GIT_REF + ) def __get_per_page(self): """ @@ -172,10 +215,7 @@ class Github(object): :calls: `GET /rate_limit `_ :rtype: :class:`github.RateLimit.RateLimit` """ - headers, data = self.__requester.requestJsonAndCheck( - 'GET', - '/rate_limit' - ) + headers, data = self.__requester.requestJsonAndCheck("GET", "/rate_limit") return RateLimit.RateLimit(self.__requester, headers, data["resources"], True) @property @@ -193,10 +233,7 @@ class Github(object): """ assert isinstance(key, (str, six.text_type)), key - headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/licenses/" + key - ) + headers, data = self.__requester.requestJsonAndCheck("GET", "/licenses/" + key) return github.License.License(self.__requester, headers, data, completed=True) def get_licenses(self): @@ -208,10 +245,7 @@ class Github(object): url_parameters = dict() return github.PaginatedList.PaginatedList( - github.License.License, - self.__requester, - "/licenses", - url_parameters + github.License.License, self.__requester, "/licenses", url_parameters ) def get_user(self, login=github.GithubObject.NotSet): @@ -220,15 +254,20 @@ class Github(object): :param login: string :rtype: :class:`github.NamedUser.NamedUser` """ - assert login is github.GithubObject.NotSet or isinstance(login, (str, six.text_type)), login + assert login is github.GithubObject.NotSet or isinstance( + login, (str, six.text_type) + ), login if login is github.GithubObject.NotSet: - return AuthenticatedUser.AuthenticatedUser(self.__requester, {}, {"url": "/user"}, completed=False) + return AuthenticatedUser.AuthenticatedUser( + self.__requester, {}, {"url": "/user"}, completed=False + ) else: headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/users/" + login + "GET", "/users/" + login + ) + return github.NamedUser.NamedUser( + self.__requester, headers, data, completed=True ) - return github.NamedUser.NamedUser(self.__requester, headers, data, completed=True) def get_users(self, since=github.GithubObject.NotSet): """ @@ -236,15 +275,14 @@ class Github(object): :param since: integer :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ - assert since is github.GithubObject.NotSet or isinstance(since, six.integer_types), since + assert since is github.GithubObject.NotSet or isinstance( + since, six.integer_types + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self.__requester, - "/users", - url_parameters + github.NamedUser.NamedUser, self.__requester, "/users", url_parameters ) def get_organization(self, login): @@ -254,11 +292,10 @@ class Github(object): :rtype: :class:`github.Organization.Organization` """ assert isinstance(login, (str, six.text_type)), login - headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/orgs/" + login + headers, data = self.__requester.requestJsonAndCheck("GET", "/orgs/" + login) + return github.Organization.Organization( + self.__requester, headers, data, completed=True ) - return github.Organization.Organization(self.__requester, headers, data, completed=True) def get_organizations(self, since=github.GithubObject.NotSet): """ @@ -266,7 +303,9 @@ class Github(object): :param since: integer :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization` """ - assert since is github.GithubObject.NotSet or isinstance(since, six.integer_types), since + assert since is github.GithubObject.NotSet or isinstance( + since, six.integer_types + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since @@ -274,7 +313,7 @@ class Github(object): github.Organization.Organization, self.__requester, "/organizations", - url_parameters + url_parameters, ) def get_repo(self, full_name_or_id, lazy=False): @@ -286,32 +325,37 @@ class Github(object): url_base = "/repositories/" if isinstance(full_name_or_id, int) else "/repos/" url = "%s%s" % (url_base, full_name_or_id) if lazy: - return Repository.Repository(self.__requester, {}, {"url": url}, completed=False) + return Repository.Repository( + self.__requester, {}, {"url": url}, completed=False + ) headers, data = self.__requester.requestJsonAndCheck( - "GET", - "%s%s" % (url_base, full_name_or_id) + "GET", "%s%s" % (url_base, full_name_or_id) ) return Repository.Repository(self.__requester, headers, data, completed=True) - def get_repos(self, since=github.GithubObject.NotSet, visibility=github.GithubObject.NotSet): + def get_repos( + self, since=github.GithubObject.NotSet, visibility=github.GithubObject.NotSet + ): """ :calls: `GET /repositories `_ :param since: integer :param visibility: string ('all','public') :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - assert since is github.GithubObject.NotSet or isinstance(since, six.integer_types), since + assert since is github.GithubObject.NotSet or isinstance( + since, six.integer_types + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since if visibility is not github.GithubObject.NotSet: - assert visibility in ('public', 'all'), visibility + assert visibility in ("public", "all"), visibility url_parameters["visibility"] = visibility return github.PaginatedList.PaginatedList( github.Repository.Repository, self.__requester, "/repositories", - url_parameters + url_parameters, ) def get_project(self, id): @@ -323,7 +367,7 @@ class Github(object): headers, data = self.__requester.requestJsonAndCheck( "GET", "/projects/%d" % (id), - headers={"Accept": Consts.mediaTypeProjectsPreview} + headers={"Accept": Consts.mediaTypeProjectsPreview}, ) return github.Project.Project(self.__requester, headers, data, completed=True) @@ -334,10 +378,7 @@ class Github(object): :rtype: :class:`github.Gist.Gist` """ assert isinstance(id, (str, six.text_type)), id - headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/gists/" + id - ) + headers, data = self.__requester.requestJsonAndCheck("GET", "/gists/" + id) return github.Gist.Gist(self.__requester, headers, data, completed=True) def get_gists(self, since=github.GithubObject.NotSet): @@ -346,18 +387,23 @@ class Github(object): :param since: datetime.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.datetime + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Gist.Gist, - self.__requester, - "/gists/public", - url_parameters + github.Gist.Gist, self.__requester, "/gists/public", url_parameters ) - def search_repositories(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers): + def search_repositories( + self, + query, + sort=github.GithubObject.NotSet, + order=github.GithubObject.NotSet, + **qualifiers + ): """ :calls: `GET /search/repositories `_ :param query: string @@ -368,11 +414,15 @@ class Github(object): """ assert isinstance(query, (str, six.text_type)), query url_parameters = dict() - if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered) - assert sort in ('stars', 'forks', 'updated'), sort + if ( + sort is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) + assert sort in ("stars", "forks", "updated"), sort url_parameters["sort"] = sort - if order is not github.GithubObject.NotSet: # pragma no branch (Should be covered) - assert order in ('asc', 'desc'), order + if ( + order is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) + assert order in ("asc", "desc"), order url_parameters["order"] = order query_chunks = [] @@ -382,17 +432,23 @@ class Github(object): for qualifier, value in qualifiers.items(): query_chunks.append("%s:%s" % (qualifier, value)) - url_parameters["q"] = ' '.join(query_chunks) + url_parameters["q"] = " ".join(query_chunks) assert url_parameters["q"], "need at least one qualifier" return github.PaginatedList.PaginatedList( github.Repository.Repository, self.__requester, "/search/repositories", - url_parameters + url_parameters, ) - def search_users(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers): + def search_users( + self, + query, + sort=github.GithubObject.NotSet, + order=github.GithubObject.NotSet, + **qualifiers + ): """ :calls: `GET /search/users `_ :param query: string @@ -404,10 +460,10 @@ class Github(object): assert isinstance(query, (str, six.text_type)), query url_parameters = dict() if sort is not github.GithubObject.NotSet: - assert sort in ('followers', 'repositories', 'joined'), sort + assert sort in ("followers", "repositories", "joined"), sort url_parameters["sort"] = sort if order is not github.GithubObject.NotSet: - assert order in ('asc', 'desc'), order + assert order in ("asc", "desc"), order url_parameters["order"] = order query_chunks = [] @@ -417,17 +473,23 @@ class Github(object): for qualifier, value in qualifiers.items(): query_chunks.append("%s:%s" % (qualifier, value)) - url_parameters["q"] = ' '.join(query_chunks) + url_parameters["q"] = " ".join(query_chunks) assert url_parameters["q"], "need at least one qualifier" return github.PaginatedList.PaginatedList( github.NamedUser.NamedUser, self.__requester, "/search/users", - url_parameters + url_parameters, ) - def search_issues(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers): + def search_issues( + self, + query, + sort=github.GithubObject.NotSet, + order=github.GithubObject.NotSet, + **qualifiers + ): """ :calls: `GET /search/issues `_ :param query: string @@ -439,10 +501,10 @@ class Github(object): assert isinstance(query, (str, six.text_type)), query url_parameters = dict() if sort is not github.GithubObject.NotSet: - assert sort in ('comments', 'created', 'updated'), sort + assert sort in ("comments", "created", "updated"), sort url_parameters["sort"] = sort if order is not github.GithubObject.NotSet: - assert order in ('asc', 'desc'), order + assert order in ("asc", "desc"), order url_parameters["order"] = order query_chunks = [] @@ -452,17 +514,21 @@ class Github(object): for qualifier, value in qualifiers.items(): query_chunks.append("%s:%s" % (qualifier, value)) - url_parameters["q"] = ' '.join(query_chunks) + url_parameters["q"] = " ".join(query_chunks) assert url_parameters["q"], "need at least one qualifier" return github.PaginatedList.PaginatedList( - github.Issue.Issue, - self.__requester, - "/search/issues", - url_parameters + github.Issue.Issue, self.__requester, "/search/issues", url_parameters ) - def search_code(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, highlight=False, **qualifiers): + def search_code( + self, + query, + sort=github.GithubObject.NotSet, + order=github.GithubObject.NotSet, + highlight=False, + **qualifiers + ): """ :calls: `GET /search/code `_ :param query: string @@ -474,11 +540,15 @@ class Github(object): """ assert isinstance(query, (str, six.text_type)), query url_parameters = dict() - if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered) - assert sort in ('indexed',), sort + if ( + sort is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) + assert sort in ("indexed",), sort url_parameters["sort"] = sort - if order is not github.GithubObject.NotSet: # pragma no branch (Should be covered) - assert order in ('asc', 'desc'), order + if ( + order is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) + assert order in ("asc", "desc"), order url_parameters["order"] = order query_chunks = [] @@ -488,7 +558,7 @@ class Github(object): for qualifier, value in qualifiers.items(): query_chunks.append("%s:%s" % (qualifier, value)) - url_parameters["q"] = ' '.join(query_chunks) + url_parameters["q"] = " ".join(query_chunks) assert url_parameters["q"], "need at least one qualifier" headers = {"Accept": Consts.highLightSearchPreview} if highlight else None @@ -498,10 +568,16 @@ class Github(object): self.__requester, "/search/code", url_parameters, - headers=headers + headers=headers, ) - def search_commits(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers): + def search_commits( + self, + query, + sort=github.GithubObject.NotSet, + order=github.GithubObject.NotSet, + **qualifiers + ): """ :calls: `GET /search/commits `_ :param query: string @@ -512,11 +588,15 @@ class Github(object): """ assert isinstance(query, (str, six.text_type)), query url_parameters = dict() - if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered) - assert sort in ('author-date', 'committer-date'), sort + if ( + sort is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) + assert sort in ("author-date", "committer-date"), sort url_parameters["sort"] = sort - if order is not github.GithubObject.NotSet: # pragma no branch (Should be covered) - assert order in ('asc', 'desc'), order + if ( + order is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) + assert order in ("asc", "desc"), order url_parameters["order"] = order query_chunks = [] @@ -526,7 +606,7 @@ class Github(object): for qualifier, value in qualifiers.items(): query_chunks.append("%s:%s" % (qualifier, value)) - url_parameters["q"] = ' '.join(query_chunks) + url_parameters["q"] = " ".join(query_chunks) assert url_parameters["q"], "need at least one qualifier" return github.PaginatedList.PaginatedList( @@ -534,9 +614,7 @@ class Github(object): self.__requester, "/search/commits", url_parameters, - headers={ - "Accept": Consts.mediaTypeCommitSearchPreview - } + headers={"Accept": Consts.mediaTypeCommitSearchPreview}, ) def search_topics(self, query, **qualifiers): @@ -556,7 +634,7 @@ class Github(object): for qualifier, value in qualifiers.items(): query_chunks.append("%s:%s" % (qualifier, value)) - url_parameters["q"] = ' '.join(query_chunks) + url_parameters["q"] = " ".join(query_chunks) assert url_parameters["q"], "need at least one qualifier" return github.PaginatedList.PaginatedList( @@ -564,9 +642,7 @@ class Github(object): self.__requester, "/search/topics", url_parameters, - headers={ - "Accept": Consts.mediaTypeTopicsPreview - } + headers={"Accept": Consts.mediaTypeTopicsPreview}, ) def render_markdown(self, text, context=github.GithubObject.NotSet): @@ -577,17 +653,15 @@ class Github(object): :rtype: string """ assert isinstance(text, (str, six.text_type)), text - assert context is github.GithubObject.NotSet or isinstance(context, github.Repository.Repository), context - post_parameters = { - "text": text - } + assert context is github.GithubObject.NotSet or isinstance( + context, github.Repository.Repository + ), context + post_parameters = {"text": text} if context is not github.GithubObject.NotSet: post_parameters["mode"] = "gfm" post_parameters["context"] = context._identity status, headers, data = self.__requester.requestJson( - "POST", - "/markdown", - input=post_parameters + "POST", "/markdown", input=post_parameters ) return data @@ -599,21 +673,24 @@ class Github(object): """ assert isinstance(name, (str, six.text_type)), name headers, attributes = self.__requester.requestJsonAndCheck( - "GET", - "/hooks/" + name + "GET", "/hooks/" + name + ) + return HookDescription.HookDescription( + self.__requester, headers, attributes, completed=True ) - return HookDescription.HookDescription(self.__requester, headers, attributes, completed=True) def get_hooks(self): """ :calls: `GET /hooks `_ :rtype: list of :class:`github.HookDescription.HookDescription` """ - headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/hooks" - ) - return [HookDescription.HookDescription(self.__requester, headers, attributes, completed=True) for attributes in data] + headers, data = self.__requester.requestJsonAndCheck("GET", "/hooks") + return [ + HookDescription.HookDescription( + self.__requester, headers, attributes, completed=True + ) + for attributes in data + ] def get_gitignore_templates(self): """ @@ -621,8 +698,7 @@ class Github(object): :rtype: list of string """ headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/gitignore/templates" + "GET", "/gitignore/templates" ) return data @@ -633,20 +709,18 @@ class Github(object): """ assert isinstance(name, (str, six.text_type)), name headers, attributes = self.__requester.requestJsonAndCheck( - "GET", - "/gitignore/templates/" + name + "GET", "/gitignore/templates/" + name + ) + return GitignoreTemplate.GitignoreTemplate( + self.__requester, headers, attributes, completed=True ) - return GitignoreTemplate.GitignoreTemplate(self.__requester, headers, attributes, completed=True) def get_emojis(self): """ :calls: `GET /emojis `_ :rtype: dictionary of type => url for emoji` """ - headers, attributes = self.__requester.requestJsonAndCheck( - "GET", - "/emojis" - ) + headers, attributes = self.__requester.requestJsonAndCheck("GET", "/emojis") return attributes def create_from_raw_data(self, klass, raw_data, headers={}): @@ -688,7 +762,9 @@ class Github(object): :param id: :return: """ - return Installation.Installation(self.__requester, headers={}, attributes={"id": id}, completed=True) + return Installation.Installation( + self.__requester, headers={}, attributes={"id": id}, completed=True + ) class GithubIntegration(object): @@ -716,19 +792,11 @@ class GithubIntegration(object): :return: """ now = int(time.time()) - payload = { - "iat": now, - "exp": now + expiration, - "iss": self.integration_id - } - encrypted = jwt.encode( - payload, - key=self.private_key, - algorithm="RS256" - ) + payload = {"iat": now, "exp": now + expiration, "iss": self.integration_id} + encrypted = jwt.encode(payload, key=self.private_key, algorithm="RS256") if isinstance(encrypted, bytes): - encrypted = encrypted.decode('utf-8') + encrypted = encrypted.decode("utf-8") return encrypted @@ -744,13 +812,15 @@ class GithubIntegration(object): if user_id: body = {"user_id": user_id} response = requests.post( - "{}/app/installations/{}/access_tokens".format(self.base_url, installation_id), + "{}/app/installations/{}/access_tokens".format( + self.base_url, installation_id + ), headers={ "Authorization": "Bearer {}".format(self.create_jwt()), "Accept": Consts.mediaTypeIntegrationPreview, - "User-Agent": "PyGithub/Python" + "User-Agent": "PyGithub/Python", }, - json=body + json=body, ) if response.status_code == 201: @@ -758,21 +828,18 @@ class GithubIntegration(object): requester=None, # not required, this is a NonCompletableGithubObject headers={}, # not required, this is a NonCompletableGithubObject attributes=response.json(), - completed=True + completed=True, ) elif response.status_code == 403: raise GithubException.BadCredentialsException( - status=response.status_code, - data=response.text + status=response.status_code, data=response.text ) elif response.status_code == 404: raise GithubException.UnknownObjectException( - status=response.status_code, - data=response.text + status=response.status_code, data=response.text ) raise GithubException.GithubException( - status=response.status_code, - data=response.text + status=response.status_code, data=response.text ) def get_installation(self, owner, repo): @@ -790,7 +857,7 @@ class GithubIntegration(object): response = requests.get( "{}/repos/{}/{}/installation".format(self.base_url, owner, repo), - headers=headers + headers=headers, ) response_dict = response.json() return Installation.Installation(None, headers, response_dict, True) diff --git a/github/Membership.py b/github/Membership.py index f2a6f60d..2c45de68 100644 --- a/github/Membership.py +++ b/github/Membership.py @@ -115,8 +115,14 @@ class Membership(github.GithubObject.CompletableGithubObject): if "role" in attributes: # pragma no branch self._role = self._makeStringAttribute(attributes["role"]) if "organization_url" in attributes: # pragma no branch - self._organization_url = self._makeStringAttribute(attributes["organization_url"]) + self._organization_url = self._makeStringAttribute( + attributes["organization_url"] + ) if "organization" in attributes: # pragma no branch - self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"]) + self._organization = self._makeClassAttribute( + github.Organization.Organization, attributes["organization"] + ) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/Migration.py b/github/Migration.py index 38f796c8..99be3672 100644 --- a/github/Migration.py +++ b/github/Migration.py @@ -33,13 +33,13 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.PaginatedList +import github.GithubObject import github.NamedUser +import github.PaginatedList +import six from . import Consts -import six class Migration(github.GithubObject.CompletableGithubObject): @@ -137,11 +137,7 @@ class Migration(github.GithubObject.CompletableGithubObject): :rtype: str """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url, - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + "GET", self.url, headers={"Accept": Consts.mediaTypeMigrationPreview} ) self._useAttributes(data) return self.state @@ -154,9 +150,7 @@ class Migration(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "GET", self.url + "/archive", - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, ) return data["data"] @@ -167,9 +161,7 @@ class Migration(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "DELETE", self.url + "/archive", - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, ) def unlock_repo(self, repo_name): @@ -182,9 +174,7 @@ class Migration(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "DELETE", self.url + "/repos/" + repo_name + "/lock", - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, ) def _initAttributes(self): @@ -203,17 +193,25 @@ class Migration(github.GithubObject.CompletableGithubObject): if "id" in attributes: self._id = self._makeIntAttribute(attributes["id"]) if "owner" in attributes: - self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"]) + self._owner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["owner"] + ) if "guid" in attributes: self._guid = self._makeStringAttribute(attributes["guid"]) if "state" in attributes: self._state = self._makeStringAttribute(attributes["state"]) if "lock_repositories" in attributes: - self._lock_repositories = self._makeBoolAttribute(attributes["lock_repositories"]) + self._lock_repositories = self._makeBoolAttribute( + attributes["lock_repositories"] + ) if "exclude_attachments" in attributes: - self._exclude_attachments = self._makeBoolAttribute(attributes["exclude_attachments"]) + self._exclude_attachments = self._makeBoolAttribute( + attributes["exclude_attachments"] + ) if "repositories" in attributes: - self._repositories = self._makeListOfClassesAttribute(github.Repository.Repository, attributes["repositories"]) + self._repositories = self._makeListOfClassesAttribute( + github.Repository.Repository, attributes["repositories"] + ) if "url" in attributes: self._url = self._makeStringAttribute(attributes["url"]) if "created_at" in attributes: diff --git a/github/Milestone.py b/github/Milestone.py index bd0343aa..1fd70593 100644 --- a/github/Milestone.py +++ b/github/Milestone.py @@ -31,13 +31,13 @@ ################################################################################ from __future__ import absolute_import + import datetime import github.GithubObject -import github.PaginatedList - -import github.NamedUser import github.Label +import github.NamedUser +import github.PaginatedList import six @@ -47,7 +47,9 @@ class Milestone(github.GithubObject.CompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"number": self._number.value, "title": self._title.value}) + return self.get__repr__( + {"number": self._number.value, "title": self._title.value} + ) @property def closed_issues(self): @@ -158,12 +160,15 @@ class Milestone(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/milestones/:number `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, title, state=github.GithubObject.NotSet, description=github.GithubObject.NotSet, due_on=github.GithubObject.NotSet): + def edit( + self, + title, + state=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + due_on=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo/milestones/:number `_ :param title: string @@ -173,9 +178,15 @@ class Milestone(github.GithubObject.CompletableGithubObject): :rtype: None """ assert isinstance(title, (str, six.text_type)), title - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert due_on is github.GithubObject.NotSet or isinstance(due_on, datetime.date), due_on + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert due_on is github.GithubObject.NotSet or isinstance( + due_on, datetime.date + ), due_on post_parameters = { "title": title, } @@ -186,9 +197,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): if due_on is not github.GithubObject.NotSet: post_parameters["due_on"] = due_on.strftime("%Y-%m-%d") headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -198,10 +207,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` """ return github.PaginatedList.PaginatedList( - github.Label.Label, - self._requester, - self.url + "/labels", - None + github.Label.Label, self._requester, self.url + "/labels", None ) @property @@ -229,7 +235,9 @@ class Milestone(github.GithubObject.CompletableGithubObject): if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "creator" in attributes: # pragma no branch - self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"]) + self._creator = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["creator"] + ) if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "due_on" in attributes: # pragma no branch diff --git a/github/NamedUser.py b/github/NamedUser.py index 6c096ec4..a881397a 100644 --- a/github/NamedUser.py +++ b/github/NamedUser.py @@ -38,18 +38,18 @@ ################################################################################ from __future__ import absolute_import + import datetime -import github.GithubObject -import github.PaginatedList - +import github.Event import github.Gist -import github.Repository +import github.GithubObject import github.NamedUser +import github.Organization +import github.PaginatedList import github.Permissions import github.Plan -import github.Organization -import github.Event +import github.Repository import six @@ -73,7 +73,11 @@ class NamedUser(github.GithubObject.CompletableGithubObject): return hash((self.id, self.login)) def __eq__(self, other): - return isinstance(other, type(self)) and self.login == other.login and self.id == other.id + return ( + isinstance(other, type(self)) + and self.login == other.login + and self.id == other.id + ) @property def avatar_url(self): @@ -425,10 +429,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - self.url + "/events", - None + github.Event.Event, self._requester, self.url + "/events", None ) def get_followers(self): @@ -437,10 +438,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - NamedUser, - self._requester, - self.url + "/followers", - None + NamedUser, self._requester, self.url + "/followers", None ) def get_following(self): @@ -449,10 +447,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - NamedUser, - self._requester, - self.url + "/following", - None + NamedUser, self._requester, self.url + "/following", None ) def get_gists(self, since=github.GithubObject.NotSet): @@ -461,15 +456,14 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :param since: datetime.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.datetime + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Gist.Gist, - self._requester, - self.url + "/gists", - url_parameters + github.Gist.Gist, self._requester, self.url + "/gists", url_parameters ) def get_keys(self): @@ -478,10 +472,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.UserKey.UserKey` """ return github.PaginatedList.PaginatedList( - github.UserKey.UserKey, - self._requester, - self.url + "/keys", - None + github.UserKey.UserKey, self._requester, self.url + "/keys", None ) def get_orgs(self): @@ -490,10 +481,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization` """ return github.PaginatedList.PaginatedList( - github.Organization.Organization, - self._requester, - self.url + "/orgs", - None + github.Organization.Organization, self._requester, self.url + "/orgs", None ) def get_public_events(self): @@ -502,10 +490,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - self.url + "/events/public", - None + github.Event.Event, self._requester, self.url + "/events/public", None ) def get_public_received_events(self): @@ -517,7 +502,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): github.Event.Event, self._requester, self.url + "/received_events/public", - None + None, ) def get_received_events(self): @@ -526,10 +511,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - self.url + "/received_events", - None + github.Event.Event, self._requester, self.url + "/received_events", None ) def get_repo(self, name): @@ -540,13 +522,18 @@ class NamedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name headers, data = self._requester.requestJsonAndCheck( - "GET", - "/repos/" + self.login + "/" + name + "GET", "/repos/" + self.login + "/" + name + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) - def get_repos(self, type=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet): + def get_repos( + self, + type=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + ): """ :calls: `GET /users/:user/repos `_ :param type: string @@ -554,9 +541,15 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :param direction: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - assert type is github.GithubObject.NotSet or isinstance(type, (str, six.text_type)), type - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction + assert type is github.GithubObject.NotSet or isinstance( + type, (str, six.text_type) + ), type + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction url_parameters = dict() if type is not github.GithubObject.NotSet: url_parameters["type"] = type @@ -568,7 +561,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): github.Repository.Repository, self._requester, self.url + "/repos", - url_parameters + url_parameters, ) def get_starred(self): @@ -577,10 +570,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - self.url + "/starred", - None + github.Repository.Repository, self._requester, self.url + "/starred", None ) def get_subscriptions(self): @@ -592,7 +582,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): github.Repository.Repository, self._requester, self.url + "/subscriptions", - None + None, ) def get_watched(self): @@ -601,10 +591,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - self.url + "/watched", - None + github.Repository.Repository, self._requester, self.url + "/watched", None ) def has_in_following(self, following): @@ -615,8 +602,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): """ assert isinstance(following, github.NamedUser.NamedUser), following status, headers, data = self._requester.requestJson( - "GET", - self.url + "/following/" + following._identity + "GET", self.url + "/following/" + following._identity ) return status == 204 @@ -630,14 +616,17 @@ class NamedUser(github.GithubObject.CompletableGithubObject): :param org: string or :class:`github.Organization.Organization` :rtype: :class:`github.Membership.Membership` """ - assert isinstance(org, (str, six.text_type)) or isinstance(org, github.Organization.Organization), org + assert isinstance(org, (str, six.text_type)) or isinstance( + org, github.Organization.Organization + ), org if isinstance(org, github.Organization.Organization): org = org.login headers, data = self._requester.requestJsonAndCheck( - "GET", - "/orgs/" + org + "/memberships/" + self.login + "GET", "/orgs/" + org + "/memberships/" + self.login + ) + return github.Membership.Membership( + self._requester, headers, data, completed=True ) - return github.Membership.Membership(self._requester, headers, data, completed=True) def _initAttributes(self): self._avatar_url = github.GithubObject.NotSet @@ -725,9 +714,13 @@ class NamedUser(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "invitation_teams_url" in attributes: # pragma no branch - self._invitation_teams_url = self._makeStringAttribute(attributes["invitation_teams_url"]) + self._invitation_teams_url = self._makeStringAttribute( + attributes["invitation_teams_url"] + ) if "inviter" in attributes: # pragma no branch - self._inviter = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["inviter"]) + self._inviter = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["inviter"] + ) if "location" in attributes: # pragma no branch self._location = self._makeStringAttribute(attributes["location"]) if "login" in attributes: # pragma no branch @@ -737,11 +730,17 @@ class NamedUser(github.GithubObject.CompletableGithubObject): if "node_id" in attributes: # pragma no branch self._node_id = self._makeStringAttribute(attributes["node_id"]) if "organizations_url" in attributes: # pragma no branch - self._organizations_url = self._makeStringAttribute(attributes["organizations_url"]) + self._organizations_url = self._makeStringAttribute( + attributes["organizations_url"] + ) if "owned_private_repos" in attributes: # pragma no branch - self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"]) + self._owned_private_repos = self._makeIntAttribute( + attributes["owned_private_repos"] + ) if "permissions" in attributes: # pragma no branch - self._permissions = self._makeClassAttribute(github.Permissions.Permissions, attributes["permissions"]) + self._permissions = self._makeClassAttribute( + github.Permissions.Permissions, attributes["permissions"] + ) if "plan" in attributes: # pragma no branch self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"]) if "private_gists" in attributes: # pragma no branch @@ -751,7 +750,9 @@ class NamedUser(github.GithubObject.CompletableGithubObject): if "public_repos" in attributes: # pragma no branch self._public_repos = self._makeIntAttribute(attributes["public_repos"]) if "received_events_url" in attributes: # pragma no branch - self._received_events_url = self._makeStringAttribute(attributes["received_events_url"]) + self._received_events_url = self._makeStringAttribute( + attributes["received_events_url"] + ) if "repos_url" in attributes: # pragma no branch self._repos_url = self._makeStringAttribute(attributes["repos_url"]) if "role" in attributes: # pragma no branch @@ -761,13 +762,17 @@ class NamedUser(github.GithubObject.CompletableGithubObject): if "starred_url" in attributes: # pragma no branch self._starred_url = self._makeStringAttribute(attributes["starred_url"]) if "subscriptions_url" in attributes: # pragma no branch - self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"]) + self._subscriptions_url = self._makeStringAttribute( + attributes["subscriptions_url"] + ) if "suspended_at" in attributes: # pragma no branch self._suspended_at = self._makeDatetimeAttribute(attributes["suspended_at"]) if "team_count" in attributes: self._team_count = self._makeIntAttribute(attributes["team_count"]) if "total_private_repos" in attributes: # pragma no branch - self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"]) + self._total_private_repos = self._makeIntAttribute( + attributes["total_private_repos"] + ) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "updated_at" in attributes: # pragma no branch diff --git a/github/Notification.py b/github/Notification.py index 7b301d5f..74efbf2f 100644 --- a/github/Notification.py +++ b/github/Notification.py @@ -30,10 +30,10 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.Repository +import github.GithubObject import github.NotificationSubject +import github.Repository class Notification(github.GithubObject.CompletableGithubObject): @@ -120,23 +120,16 @@ class Notification(github.GithubObject.CompletableGithubObject): """ :calls: `PATCH /notifications/threads/:id `_ """ - headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - ) + headers, data = self._requester.requestJsonAndCheck("PATCH", self.url,) def get_pull_request(self): - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.subject.url + headers, data = self._requester.requestJsonAndCheck("GET", self.subject.url) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True ) - return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) def get_issue(self): - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.subject.url - ) + headers, data = self._requester.requestJsonAndCheck("GET", self.subject.url) return github.Issue.Issue(self._requester, headers, data, completed=True) def _initAttributes(self): @@ -155,13 +148,19 @@ class Notification(github.GithubObject.CompletableGithubObject): if "last_read_at" in attributes: # pragma no branch self._last_read_at = self._makeDatetimeAttribute(attributes["last_read_at"]) if "repository" in attributes: # pragma no branch - self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) + self._repository = self._makeClassAttribute( + github.Repository.Repository, attributes["repository"] + ) if "subject" in attributes: # pragma no branch - self._subject = self._makeClassAttribute(github.NotificationSubject.NotificationSubject, attributes["subject"]) + self._subject = self._makeClassAttribute( + github.NotificationSubject.NotificationSubject, attributes["subject"] + ) if "reason" in attributes: # pragma no branch self._reason = self._makeStringAttribute(attributes["reason"]) if "subscription_url" in attributes: # pragma no branch - self._subscription_url = self._makeStringAttribute(attributes["subscription_url"]) + self._subscription_url = self._makeStringAttribute( + attributes["subscription_url"] + ) if "unread" in attributes: # pragma no branch self._unread = self._makeBoolAttribute(attributes["unread"]) if "updated_at" in attributes: # pragma no branch diff --git a/github/NotificationSubject.py b/github/NotificationSubject.py index 46b70ff1..d97c256e 100644 --- a/github/NotificationSubject.py +++ b/github/NotificationSubject.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -80,6 +81,8 @@ class NotificationSubject(github.GithubObject.NonCompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "latest_comment_url" in attributes: # pragma no branch - self._latest_comment_url = self._makeStringAttribute(attributes["latest_comment_url"]) + self._latest_comment_url = self._makeStringAttribute( + attributes["latest_comment_url"] + ) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) diff --git a/github/Organization.py b/github/Organization.py index dd5777cb..9ea12024 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -42,20 +42,20 @@ ################################################################################ from __future__ import absolute_import + import datetime -import github.GithubObject -import github.PaginatedList - -import github.Plan -import github.Team import github.Event -import github.Repository -import github.Project +import github.GithubObject import github.NamedUser +import github.PaginatedList +import github.Plan +import github.Project +import github.Repository +import github.Team +import six from . import Consts -import six class Organization(github.GithubObject.CompletableGithubObject): @@ -321,14 +321,15 @@ class Organization(github.GithubObject.CompletableGithubObject): :param role: string :rtype: None """ - assert role is github.GithubObject.NotSet or isinstance(role, (str, six.text_type)), role + assert role is github.GithubObject.NotSet or isinstance( + role, (str, six.text_type) + ), role assert isinstance(member, github.NamedUser.NamedUser), member put_parameters = {} if role is not github.GithubObject.NotSet: put_parameters["role"] = role headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/memberships/" + member._identity, input=put_parameters + "PUT", self.url + "/memberships/" + member._identity, input=put_parameters ) def add_to_public_members(self, public_member): @@ -339,8 +340,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(public_member, github.NamedUser.NamedUser), public_member headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/public_members/" + public_member._identity + "PUT", self.url + "/public_members/" + public_member._identity ) def create_fork(self, repo): @@ -356,11 +356,19 @@ class Organization(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "POST", "/repos/" + repo.owner.login + "/" + repo.name + "/forks", - parameters=url_parameters + parameters=url_parameters, + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) - def create_hook(self, name, config, events=github.GithubObject.NotSet, active=github.GithubObject.NotSet): + def create_hook( + self, + name, + config, + events=github.GithubObject.NotSet, + active=github.GithubObject.NotSet, + ): """ :calls: `POST /orgs/:owner/hooks `_ :param name: string @@ -371,7 +379,9 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name assert isinstance(config, dict), config - assert events is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in events), events + assert events is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in events + ), events assert active is github.GithubObject.NotSet or isinstance(active, bool), active post_parameters = { "name": name, @@ -382,19 +392,28 @@ class Organization(github.GithubObject.CompletableGithubObject): if active is not github.GithubObject.NotSet: post_parameters["active"] = active headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/hooks", - input=post_parameters + "POST", self.url + "/hooks", input=post_parameters ) return github.Hook.Hook(self._requester, headers, data, completed=True) - def create_repo(self, name, description=github.GithubObject.NotSet, homepage=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, has_issues=github.GithubObject.NotSet, - has_wiki=github.GithubObject.NotSet, has_downloads=github.GithubObject.NotSet, - has_projects=github.GithubObject.NotSet, team_id=github.GithubObject.NotSet, - auto_init=github.GithubObject.NotSet, license_template=github.GithubObject.NotSet, - gitignore_template=github.GithubObject.NotSet, allow_squash_merge=github.GithubObject.NotSet, - allow_merge_commit=github.GithubObject.NotSet, allow_rebase_merge=github.GithubObject.NotSet): + def create_repo( + self, + name, + description=github.GithubObject.NotSet, + homepage=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + has_issues=github.GithubObject.NotSet, + has_wiki=github.GithubObject.NotSet, + has_downloads=github.GithubObject.NotSet, + has_projects=github.GithubObject.NotSet, + team_id=github.GithubObject.NotSet, + auto_init=github.GithubObject.NotSet, + license_template=github.GithubObject.NotSet, + gitignore_template=github.GithubObject.NotSet, + allow_squash_merge=github.GithubObject.NotSet, + allow_merge_commit=github.GithubObject.NotSet, + allow_rebase_merge=github.GithubObject.NotSet, + ): """ :calls: `POST /orgs/:org/repos `_ :param name: string @@ -415,20 +434,48 @@ class Organization(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Repository.Repository` """ assert isinstance(name, (str, six.text_type)), name - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert homepage is github.GithubObject.NotSet or isinstance(homepage, (str, six.text_type)), homepage - assert private is github.GithubObject.NotSet or isinstance(private, bool), private - assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues - assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki - assert has_downloads is github.GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads - assert has_projects is github.GithubObject.NotSet or isinstance(has_projects, bool), has_projects - assert team_id is github.GithubObject.NotSet or isinstance(team_id, six.integer_types), team_id - assert auto_init is github.GithubObject.NotSet or isinstance(auto_init, bool), auto_init - assert license_template is github.GithubObject.NotSet or isinstance(license_template, (str, six.text_type)), license_template - assert gitignore_template is github.GithubObject.NotSet or isinstance(gitignore_template, (str, six.text_type)), gitignore_template - assert allow_squash_merge is github.GithubObject.NotSet or isinstance(allow_squash_merge, bool), allow_squash_merge - assert allow_merge_commit is github.GithubObject.NotSet or isinstance(allow_merge_commit, bool), allow_merge_commit - assert allow_rebase_merge is github.GithubObject.NotSet or isinstance(allow_rebase_merge, bool), allow_rebase_merge + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert homepage is github.GithubObject.NotSet or isinstance( + homepage, (str, six.text_type) + ), homepage + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + assert has_issues is github.GithubObject.NotSet or isinstance( + has_issues, bool + ), has_issues + assert has_wiki is github.GithubObject.NotSet or isinstance( + has_wiki, bool + ), has_wiki + assert has_downloads is github.GithubObject.NotSet or isinstance( + has_downloads, bool + ), has_downloads + assert has_projects is github.GithubObject.NotSet or isinstance( + has_projects, bool + ), has_projects + assert team_id is github.GithubObject.NotSet or isinstance( + team_id, six.integer_types + ), team_id + assert auto_init is github.GithubObject.NotSet or isinstance( + auto_init, bool + ), auto_init + assert license_template is github.GithubObject.NotSet or isinstance( + license_template, (str, six.text_type) + ), license_template + assert gitignore_template is github.GithubObject.NotSet or isinstance( + gitignore_template, (str, six.text_type) + ), gitignore_template + assert allow_squash_merge is github.GithubObject.NotSet or isinstance( + allow_squash_merge, bool + ), allow_squash_merge + assert allow_merge_commit is github.GithubObject.NotSet or isinstance( + allow_merge_commit, bool + ), allow_merge_commit + assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( + allow_rebase_merge, bool + ), allow_rebase_merge post_parameters = { "name": name, } @@ -461,13 +508,20 @@ class Organization(github.GithubObject.CompletableGithubObject): if allow_rebase_merge is not github.GithubObject.NotSet: post_parameters["allow_rebase_merge"] = allow_rebase_merge headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/repos", - input=post_parameters + "POST", self.url + "/repos", input=post_parameters + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) - def create_team(self, name, repo_names=github.GithubObject.NotSet, permission=github.GithubObject.NotSet, privacy=github.GithubObject.NotSet, description=github.GithubObject.NotSet): + def create_team( + self, + name, + repo_names=github.GithubObject.NotSet, + permission=github.GithubObject.NotSet, + privacy=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + ): """ :calls: `POST /orgs/:org/teams `_ :param name: string @@ -478,25 +532,33 @@ class Organization(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Team.Team` """ assert isinstance(name, (str, six.text_type)), name - assert repo_names is github.GithubObject.NotSet or all(isinstance(element, github.Repository.Repository) for element in repo_names), repo_names - assert permission is github.GithubObject.NotSet or isinstance(permission, (str, six.text_type)), permission - assert privacy is github.GithubObject.NotSet or isinstance(privacy, (str, six.text_type)), privacy - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description + assert repo_names is github.GithubObject.NotSet or all( + isinstance(element, github.Repository.Repository) for element in repo_names + ), repo_names + assert permission is github.GithubObject.NotSet or isinstance( + permission, (str, six.text_type) + ), permission + assert privacy is github.GithubObject.NotSet or isinstance( + privacy, (str, six.text_type) + ), privacy + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description post_parameters = { "name": name, } if repo_names is not github.GithubObject.NotSet: - post_parameters["repo_names"] = [element._identity for element in repo_names] + post_parameters["repo_names"] = [ + element._identity for element in repo_names + ] if permission is not github.GithubObject.NotSet: post_parameters["permission"] = permission if privacy is not github.GithubObject.NotSet: - post_parameters['privacy'] = privacy + post_parameters["privacy"] = privacy if description is not github.GithubObject.NotSet: post_parameters["description"] = description headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/teams", - input=post_parameters + "POST", self.url + "/teams", input=post_parameters ) return github.Team.Team(self._requester, headers, data, completed=True) @@ -508,11 +570,19 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/hooks/" + str(id) + "DELETE", self.url + "/hooks/" + str(id) ) - def edit(self, billing_email=github.GithubObject.NotSet, blog=github.GithubObject.NotSet, company=github.GithubObject.NotSet, description=github.GithubObject.NotSet, email=github.GithubObject.NotSet, location=github.GithubObject.NotSet, name=github.GithubObject.NotSet): + def edit( + self, + billing_email=github.GithubObject.NotSet, + blog=github.GithubObject.NotSet, + company=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + email=github.GithubObject.NotSet, + location=github.GithubObject.NotSet, + name=github.GithubObject.NotSet, + ): """ :calls: `PATCH /orgs/:org `_ :param billing_email: string @@ -524,13 +594,27 @@ class Organization(github.GithubObject.CompletableGithubObject): :param name: string :rtype: None """ - assert billing_email is github.GithubObject.NotSet or isinstance(billing_email, (str, six.text_type)), billing_email - assert blog is github.GithubObject.NotSet or isinstance(blog, (str, six.text_type)), blog - assert company is github.GithubObject.NotSet or isinstance(company, (str, six.text_type)), company - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert email is github.GithubObject.NotSet or isinstance(email, (str, six.text_type)), email - assert location is github.GithubObject.NotSet or isinstance(location, (str, six.text_type)), location - assert name is github.GithubObject.NotSet or isinstance(name, (str, six.text_type)), name + assert billing_email is github.GithubObject.NotSet or isinstance( + billing_email, (str, six.text_type) + ), billing_email + assert blog is github.GithubObject.NotSet or isinstance( + blog, (str, six.text_type) + ), blog + assert company is github.GithubObject.NotSet or isinstance( + company, (str, six.text_type) + ), company + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert email is github.GithubObject.NotSet or isinstance( + email, (str, six.text_type) + ), email + assert location is github.GithubObject.NotSet or isinstance( + location, (str, six.text_type) + ), location + assert name is github.GithubObject.NotSet or isinstance( + name, (str, six.text_type) + ), name post_parameters = dict() if billing_email is not github.GithubObject.NotSet: post_parameters["billing_email"] = billing_email @@ -547,13 +631,18 @@ class Organization(github.GithubObject.CompletableGithubObject): if name is not github.GithubObject.NotSet: post_parameters["name"] = name headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) - def edit_hook(self, id, name, config, events=github.GithubObject.NotSet, active=github.GithubObject.NotSet): + def edit_hook( + self, + id, + name, + config, + events=github.GithubObject.NotSet, + active=github.GithubObject.NotSet, + ): """ :calls: `PATCH /orgs/:owner/hooks/:id `_ :param id: integer @@ -566,7 +655,9 @@ class Organization(github.GithubObject.CompletableGithubObject): assert isinstance(id, six.integer_types), id assert isinstance(name, (str, six.text_type)), name assert isinstance(config, dict), config - assert events is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in events), events + assert events is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in events + ), events assert active is github.GithubObject.NotSet or isinstance(active, bool), active post_parameters = { "name": name, @@ -577,9 +668,7 @@ class Organization(github.GithubObject.CompletableGithubObject): if active is not github.GithubObject.NotSet: post_parameters["active"] = active headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url + "/hooks/" + str(id), - input=post_parameters + "PATCH", self.url + "/hooks/" + str(id), input=post_parameters ) return github.Hook.Hook(self._requester, headers, data, completed=True) @@ -589,10 +678,7 @@ class Organization(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - self.url + "/events", - None + github.Event.Event, self._requester, self.url + "/events", None ) def get_hook(self, id): @@ -603,8 +689,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/hooks/" + str(id) + "GET", self.url + "/hooks/" + str(id) ) return github.Hook.Hook(self._requester, headers, data, completed=True) @@ -614,13 +699,18 @@ class Organization(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` """ return github.PaginatedList.PaginatedList( - github.Hook.Hook, - self._requester, - self.url + "/hooks", - None + github.Hook.Hook, self._requester, self.url + "/hooks", None ) - def get_issues(self, filter=github.GithubObject.NotSet, state=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): + def get_issues( + self, + filter=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): """ :calls: `GET /orgs/:org/issues `_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` @@ -632,12 +722,24 @@ class Organization(github.GithubObject.CompletableGithubObject): :param since: datetime.datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ - assert filter is github.GithubObject.NotSet or isinstance(filter, (str, six.text_type)), filter - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert filter is github.GithubObject.NotSet or isinstance( + filter, (str, six.text_type) + ), filter + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) for element in labels + ), labels + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -652,24 +754,24 @@ class Organization(github.GithubObject.CompletableGithubObject): if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( - github.Issue.Issue, - self._requester, - self.url + "/issues", - url_parameters + github.Issue.Issue, self._requester, self.url + "/issues", url_parameters ) - def get_members(self, filter_=github.GithubObject.NotSet, - role=github.GithubObject.NotSet): + def get_members( + self, filter_=github.GithubObject.NotSet, role=github.GithubObject.NotSet + ): """ :calls: `GET /orgs/:org/members `_ :param filter_: string :param role: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ - assert (filter_ is github.GithubObject.NotSet - or isinstance(filter_, (str, six.text_type))), filter_ - assert (role is github.GithubObject.NotSet - or isinstance(role, (str, six.text_type))), role + assert filter_ is github.GithubObject.NotSet or isinstance( + filter_, (str, six.text_type) + ), filter_ + assert role is github.GithubObject.NotSet or isinstance( + role, (str, six.text_type) + ), role url_parameters = {} if filter_ is not github.GithubObject.NotSet: @@ -680,7 +782,7 @@ class Organization(github.GithubObject.CompletableGithubObject): github.NamedUser.NamedUser, self._requester, self.url + "/members", - url_parameters + url_parameters, ) def get_projects(self, state=github.GithubObject.NotSet): @@ -699,7 +801,7 @@ class Organization(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/projects", url_parameters, - {"Accept": Consts.mediaTypeProjectsPreview} + {"Accept": Consts.mediaTypeProjectsPreview}, ) def get_public_members(self): @@ -711,7 +813,7 @@ class Organization(github.GithubObject.CompletableGithubObject): github.NamedUser.NamedUser, self._requester, self.url + "/public_members", - None + None, ) def get_outside_collaborators(self, filter_=github.GithubObject.NotSet): @@ -720,8 +822,9 @@ class Organization(github.GithubObject.CompletableGithubObject): :param filter_: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ - assert (filter_ is github.GithubObject.NotSet - or isinstance(filter_, (str, six.text_type))), filter_ + assert filter_ is github.GithubObject.NotSet or isinstance( + filter_, (str, six.text_type) + ), filter_ url_parameters = {} if filter_ is not github.GithubObject.NotSet: @@ -730,7 +833,7 @@ class Organization(github.GithubObject.CompletableGithubObject): github.NamedUser.NamedUser, self._requester, self.url + "/outside_collaborators", - url_parameters + url_parameters, ) def remove_outside_collaborator(self, collaborator): @@ -741,8 +844,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(collaborator, github.NamedUser.NamedUser), collaborator headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/outside_collaborators/" + collaborator._identity + "DELETE", self.url + "/outside_collaborators/" + collaborator._identity ) def convert_to_outside_collaborator(self, member): @@ -753,8 +855,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/outside_collaborators/" + member._identity + "PUT", self.url + "/outside_collaborators/" + member._identity ) def get_repo(self, name): @@ -765,12 +866,18 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name headers, data = self._requester.requestJsonAndCheck( - "GET", - "/repos/" + self.login + "/" + name + "GET", "/repos/" + self.login + "/" + name + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) - def get_repos(self, type=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet): + def get_repos( + self, + type=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + ): """ :calls: `GET /orgs/:org/repos `_ :param type: string ('all', 'public', 'private', 'forks', 'sources', 'member') @@ -778,9 +885,15 @@ class Organization(github.GithubObject.CompletableGithubObject): :param direction: string ('asc', desc') :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - assert type is github.GithubObject.NotSet or isinstance(type, (str, six.text_type)), type - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction + assert type is github.GithubObject.NotSet or isinstance( + type, (str, six.text_type) + ), type + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction url_parameters = dict() if type is not github.GithubObject.NotSet: @@ -793,7 +906,7 @@ class Organization(github.GithubObject.CompletableGithubObject): github.Repository.Repository, self._requester, self.url + "/repos", - url_parameters + url_parameters, ) def get_team(self, id): @@ -803,10 +916,7 @@ class Organization(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Team.Team` """ assert isinstance(id, six.integer_types), id - headers, data = self._requester.requestJsonAndCheck( - "GET", - "/teams/" + str(id) - ) + headers, data = self._requester.requestJsonAndCheck("GET", "/teams/" + str(id)) return github.Team.Team(self._requester, headers, data, completed=True) def get_team_by_slug(self, slug): @@ -817,8 +927,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(slug, (str, six.text_type)), slug headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/teams/" + slug + "GET", self.url + "/teams/" + slug ) return github.Team.Team(self._requester, headers, data, completed=True) @@ -828,10 +937,7 @@ class Organization(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` """ return github.PaginatedList.PaginatedList( - github.Team.Team, - self._requester, - self.url + "/teams", - None + github.Team.Team, self._requester, self.url + "/teams", None ) def invitations(self): @@ -844,12 +950,16 @@ class Organization(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/invitations", None, - headers={ - "Accept": Consts.mediaTypeOrganizationInvitationPreview - } + headers={"Accept": Consts.mediaTypeOrganizationInvitationPreview}, ) - def invite_user(self, user=github.GithubObject.NotSet, email=github.GithubObject.NotSet, role=github.GithubObject.NotSet, teams=github.GithubObject.NotSet): + def invite_user( + self, + user=github.GithubObject.NotSet, + email=github.GithubObject.NotSet, + role=github.GithubObject.NotSet, + teams=github.GithubObject.NotSet, + ): """ :calls: `POST /orgs/:org/invitations `_ :param user: :class:`github.NamedUser.NamedUser` @@ -858,9 +968,15 @@ class Organization(github.GithubObject.CompletableGithubObject): :param teams: array of :class:`github.Team.Team` :rtype: None """ - assert user is github.GithubObject.NotSet or isinstance(user, github.NamedUser.NamedUser), user - assert email is github.GithubObject.NotSet or isinstance(email, (str, six.text_type)), email - assert (email is github.GithubObject.NotSet) ^ (user is github.GithubObject.NotSet), "specify only one of email or user" + assert user is github.GithubObject.NotSet or isinstance( + user, github.NamedUser.NamedUser + ), user + assert email is github.GithubObject.NotSet or isinstance( + email, (str, six.text_type) + ), email + assert (email is github.GithubObject.NotSet) ^ ( + user is github.GithubObject.NotSet + ), "specify only one of email or user" parameters = {} if user is not github.GithubObject.NotSet: parameters["invitee_id"] = user.id @@ -868,7 +984,7 @@ class Organization(github.GithubObject.CompletableGithubObject): parameters["email"] = email if role is not github.GithubObject.NotSet: assert isinstance(role, (str, six.text_type)), role - assert role in ['admin', 'direct_member', 'billing_manager'] + assert role in ["admin", "direct_member", "billing_manager"] parameters["role"] = role if teams is not github.GithubObject.NotSet: assert all(isinstance(team, github.Team.Team) for team in teams) @@ -876,8 +992,8 @@ class Organization(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "POST", self.url + "/invitations", - headers={'Accept': Consts.mediaTypeOrganizationInvitationPreview}, - input=parameters + headers={"Accept": Consts.mediaTypeOrganizationInvitationPreview}, + input=parameters, ) def has_in_members(self, member): @@ -888,13 +1004,11 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member status, headers, data = self._requester.requestJson( - "GET", - self.url + "/members/" + member._identity + "GET", self.url + "/members/" + member._identity ) if status == 302: status, headers, data = self._requester.requestJson( - "GET", - headers['location'] + "GET", headers["location"] ) return status == 204 @@ -906,8 +1020,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(public_member, github.NamedUser.NamedUser), public_member status, headers, data = self._requester.requestJson( - "GET", - self.url + "/public_members/" + public_member._identity + "GET", self.url + "/public_members/" + public_member._identity ) return status == 204 @@ -919,8 +1032,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/memberships/" + member._identity + "DELETE", self.url + "/memberships/" + member._identity ) def remove_from_members(self, member): @@ -931,8 +1043,7 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/members/" + member._identity + "DELETE", self.url + "/members/" + member._identity ) def remove_from_public_members(self, public_member): @@ -943,11 +1054,15 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(public_member, github.NamedUser.NamedUser), public_member headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/public_members/" + public_member._identity + "DELETE", self.url + "/public_members/" + public_member._identity ) - def create_migration(self, repos, lock_repositories=github.GithubObject.NotSet, exclude_attachments=github.GithubObject.NotSet): + def create_migration( + self, + repos, + lock_repositories=github.GithubObject.NotSet, + exclude_attachments=github.GithubObject.NotSet, + ): """ :calls: `POST /orgs/:org/migrations`_ :param repos: list or tuple of str @@ -957,11 +1072,13 @@ class Organization(github.GithubObject.CompletableGithubObject): """ assert isinstance(repos, (list, tuple)), repos assert all(isinstance(repo, (str, six.text_type)) for repo in repos), repos - assert lock_repositories is github.GithubObject.NotSet or isinstance(lock_repositories, bool), lock_repositories - assert exclude_attachments is github.GithubObject.NotSet or isinstance(exclude_attachments, bool), exclude_attachments - post_parameters = { - "repositories": repos - } + assert lock_repositories is github.GithubObject.NotSet or isinstance( + lock_repositories, bool + ), lock_repositories + assert exclude_attachments is github.GithubObject.NotSet or isinstance( + exclude_attachments, bool + ), exclude_attachments + post_parameters = {"repositories": repos} if lock_repositories is not github.GithubObject.NotSet: post_parameters["lock_repositories"] = lock_repositories if exclude_attachments is not github.GithubObject.NotSet: @@ -970,11 +1087,11 @@ class Organization(github.GithubObject.CompletableGithubObject): "POST", "/orgs/" + self.login + "/migrations", input=post_parameters, - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, + ) + return github.Migration.Migration( + self._requester, headers, data, completed=True ) - return github.Migration.Migration(self._requester, headers, data, completed=True) def get_migrations(self): """ @@ -986,9 +1103,7 @@ class Organization(github.GithubObject.CompletableGithubObject): self._requester, "/orgs/" + self.login + "/migrations", None, - headers={ - "Accept": Consts.mediaTypeMigrationPreview - } + headers={"Accept": Consts.mediaTypeMigrationPreview}, ) def _initAttributes(self): @@ -1064,7 +1179,9 @@ class Organization(github.GithubObject.CompletableGithubObject): if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "owned_private_repos" in attributes: # pragma no branch - self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"]) + self._owned_private_repos = self._makeIntAttribute( + attributes["owned_private_repos"] + ) if "plan" in attributes: # pragma no branch self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"]) if "private_gists" in attributes: # pragma no branch @@ -1072,15 +1189,21 @@ class Organization(github.GithubObject.CompletableGithubObject): if "public_gists" in attributes: # pragma no branch self._public_gists = self._makeIntAttribute(attributes["public_gists"]) if "public_members_url" in attributes: # pragma no branch - self._public_members_url = self._makeStringAttribute(attributes["public_members_url"]) + self._public_members_url = self._makeStringAttribute( + attributes["public_members_url"] + ) if "public_repos" in attributes: # pragma no branch self._public_repos = self._makeIntAttribute(attributes["public_repos"]) if "repos_url" in attributes: # pragma no branch self._repos_url = self._makeStringAttribute(attributes["repos_url"]) if "total_private_repos" in attributes: # pragma no branch - self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"]) + self._total_private_repos = self._makeIntAttribute( + attributes["total_private_repos"] + ) if "two_factor_requirement_enabled" in attributes: # pragma no branch - self._two_factor_requirement_enabled = self._makeBoolAttribute(attributes["two_factor_requirement_enabled"]) + self._two_factor_requirement_enabled = self._makeBoolAttribute( + attributes["two_factor_requirement_enabled"] + ) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "updated_at" in attributes: # pragma no branch diff --git a/github/PaginatedList.py b/github/PaginatedList.py index 5b62bc4b..c6cf41a0 100644 --- a/github/PaginatedList.py +++ b/github/PaginatedList.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import -import six # -*- coding: utf-8 -*- ############################ Copyrights and license ############################ @@ -39,6 +37,9 @@ import six # # ################################################################################ +from __future__ import absolute_import + +import six from six.moves.urllib.parse import parse_qs @@ -124,7 +125,15 @@ class PaginatedList(PaginatedListBase): some_other_repos = user.get_repos().get_page(3) """ - def __init__(self, contentClass, requester, firstUrl, firstParams, headers=None, list_item="items"): + def __init__( + self, + contentClass, + requester, + firstUrl, + firstParams, + headers=None, + list_item="items", + ): PaginatedListBase.__init__(self) self.__requester = requester self.__contentClass = contentClass @@ -146,12 +155,9 @@ class PaginatedList(PaginatedListBase): # set per_page = 1 so the totalCount is just the number of pages params.update({"per_page": 1}) headers, data = self.__requester.requestJsonAndCheck( - "GET", - self.__firstUrl, - parameters=params, - headers=self.__headers + "GET", self.__firstUrl, parameters=params, headers=self.__headers ) - if 'link' not in headers: + if "link" not in headers: if data and "total_count" in data: self.__totalCount = data["total_count"] elif data: @@ -161,15 +167,12 @@ class PaginatedList(PaginatedListBase): else: links = self.__parseLinkHeader(headers) lastUrl = links.get("last") - self.__totalCount = int(parse_qs(lastUrl)['page'][0]) + self.__totalCount = int(parse_qs(lastUrl)["page"][0]) return self.__totalCount def _getLastPageUrl(self): headers, data = self.__requester.requestJsonAndCheck( - "GET", - self.__firstUrl, - parameters=self.__nextParams, - headers=self.__headers + "GET", self.__firstUrl, parameters=self.__nextParams, headers=self.__headers ) links = self.__parseLinkHeader(headers) lastUrl = links.get("last") @@ -177,7 +180,14 @@ class PaginatedList(PaginatedListBase): @property def reversed(self): - r = PaginatedList(self.__contentClass, self.__requester, self.__firstUrl, self.__firstParams, self.__headers, self.__list_item) + r = PaginatedList( + self.__contentClass, + self.__requester, + self.__firstUrl, + self.__firstParams, + self.__headers, + self.__list_item, + ) r.__reverse() return r @@ -192,10 +202,7 @@ class PaginatedList(PaginatedListBase): def _fetchNextPage(self): headers, data = self.__requester.requestJsonAndCheck( - "GET", - self.__nextUrl, - parameters=self.__nextParams, - headers=self.__headers + "GET", self.__nextUrl, parameters=self.__nextParams, headers=self.__headers ) data = data if data else [] @@ -210,12 +217,13 @@ class PaginatedList(PaginatedListBase): self.__nextParams = None if self.__list_item in data: - self.__totalCount = data.get('total_count') + self.__totalCount = data.get("total_count") data = data[self.__list_item] content = [ self.__contentClass(self.__requester, headers, element, completed=False) - for element in data if element is not None + for element in data + if element is not None ] if self._reversed: return content[::-1] @@ -239,14 +247,11 @@ class PaginatedList(PaginatedListBase): if self.__requester.per_page != 30: params["per_page"] = self.__requester.per_page headers, data = self.__requester.requestJsonAndCheck( - "GET", - self.__firstUrl, - parameters=params, - headers=self.__headers + "GET", self.__firstUrl, parameters=params, headers=self.__headers ) if self.__list_item in data: - self.__totalCount = data.get('total_count') + self.__totalCount = data.get("total_count") data = data[self.__list_item] return [ diff --git a/github/Path.py b/github/Path.py index 7843b9f7..8df76115 100644 --- a/github/Path.py +++ b/github/Path.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -37,12 +38,14 @@ class Path(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "path": self._path.value, - "title": self._title.value, - "count": self._count.value, - "uniques": self._uniques.value - }) + return self.get__repr__( + { + "path": self._path.value, + "title": self._title.value, + "count": self._count.value, + "uniques": self._uniques.value, + } + ) @property def path(self): diff --git a/github/Permissions.py b/github/Permissions.py index 4a298e90..84084796 100644 --- a/github/Permissions.py +++ b/github/Permissions.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -40,11 +41,13 @@ class Permissions(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "admin": self._admin.value, - "pull": self._pull.value, - "push": self._push.value - }) + return self.get__repr__( + { + "admin": self._admin.value, + "pull": self._pull.value, + "push": self._push.value, + } + ) @property def admin(self): diff --git a/github/Plan.py b/github/Plan.py index 22377bdb..3ab504b1 100644 --- a/github/Plan.py +++ b/github/Plan.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/Project.py b/github/Project.py index cdbe9f96..9e78bd25 100644 --- a/github/Project.py +++ b/github/Project.py @@ -23,11 +23,12 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.ProjectColumn +import six from . import Consts -import six class Project(github.GithubObject.CompletableGithubObject): @@ -153,7 +154,7 @@ class Project(github.GithubObject.CompletableGithubObject): self._requester, self.columns_url, None, - {"Accept": Consts.mediaTypeProjectsPreview} + {"Accept": Consts.mediaTypeProjectsPreview}, ) def create_column(self, name): @@ -165,12 +166,11 @@ class Project(github.GithubObject.CompletableGithubObject): post_parameters = {"name": name} import_header = {"Accept": Consts.mediaTypeProjectsPreview} headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/columns", - headers=import_header, - input=post_parameters + "POST", self.url + "/columns", headers=import_header, input=post_parameters + ) + return github.ProjectColumn.ProjectColumn( + self._requester, headers, data, completed=True ) - return github.ProjectColumn.ProjectColumn(self._requester, headers, data, completed=True) def _initAttributes(self): self._body = github.GithubObject.NotSet @@ -195,7 +195,9 @@ class Project(github.GithubObject.CompletableGithubObject): if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "creator" in attributes: # pragma no branch - self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"]) + self._creator = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["creator"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch diff --git a/github/ProjectCard.py b/github/ProjectCard.py index 52d1e5a5..2715ce9b 100644 --- a/github/ProjectCard.py +++ b/github/ProjectCard.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject # NOTE: There is currently no way to get cards "in triage" for a project. @@ -123,15 +124,13 @@ class ProjectCard(github.GithubObject.CompletableGithubObject): if content_type == "PullRequest": headers, data = self._requester.requestJsonAndCheck( - "GET", - self.content_url.replace("issues", "pulls") + "GET", self.content_url.replace("issues", "pulls") + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True ) - return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) elif content_type is github.GithubObject.NotSet or content_type == "Issue": - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.content_url - ) + headers, data = self._requester.requestJsonAndCheck("GET", self.content_url) return github.Issue.Issue(self._requester, headers, data, completed=True) else: assert False, "Unknown content type: %s" % content_type @@ -158,7 +157,9 @@ class ProjectCard(github.GithubObject.CompletableGithubObject): if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "creator" in attributes: # pragma no branch - self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"]) + self._creator = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["creator"] + ) if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "node_id" in attributes: # pragma no branch diff --git a/github/ProjectColumn.py b/github/ProjectColumn.py index 816b3fd9..372fa992 100644 --- a/github/ProjectColumn.py +++ b/github/ProjectColumn.py @@ -23,12 +23,13 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.Project import github.ProjectCard +import six from . import Consts -import six class ProjectColumn(github.GithubObject.CompletableGithubObject): @@ -101,7 +102,9 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.ProjectCard.ProjectCard` :param archived_state: string """ - assert archived_state is github.GithubObject.NotSet or isinstance(archived_state, (str, six.text_type)), archived_state + assert archived_state is github.GithubObject.NotSet or isinstance( + archived_state, (str, six.text_type) + ), archived_state url_parameters = dict() if archived_state is not github.GithubObject.NotSet: @@ -112,12 +115,15 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/cards", url_parameters, - {"Accept": Consts.mediaTypeProjectsPreview} + {"Accept": Consts.mediaTypeProjectsPreview}, ) - def create_card(self, note=github.GithubObject.NotSet, - content_id=github.GithubObject.NotSet, - content_type=github.GithubObject.NotSet): + def create_card( + self, + note=github.GithubObject.NotSet, + content_id=github.GithubObject.NotSet, + content_type=github.GithubObject.NotSet, + ): """ :calls: `POST /projects/columns/:column_id/cards `_ :param note: string @@ -133,18 +139,15 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject): assert note is github.GithubObject.NotSet, note assert isinstance(content_id, int), content_id assert isinstance(content_type, (str, six.text_type)), content_type - post_parameters = {"content_id": content_id, - "content_type": content_type} + post_parameters = {"content_id": content_id, "content_type": content_type} import_header = {"Accept": Consts.mediaTypeProjectsPreview} headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/cards", - headers=import_header, - input=post_parameters + "POST", self.url + "/cards", headers=import_header, input=post_parameters + ) + return github.ProjectCard.ProjectCard( + self._requester, headers, data, completed=True ) - return github.ProjectCard.ProjectCard(self._requester, headers, - data, completed=True) def _initAttributes(self): self._cards_url = github.GithubObject.NotSet diff --git a/github/PullRequest.py b/github/PullRequest.py index 23be8e80..0bb4a82e 100644 --- a/github/PullRequest.py +++ b/github/PullRequest.py @@ -43,22 +43,23 @@ ################################################################################ from __future__ import absolute_import -import datetime -import six.moves.urllib.parse -import github.GithubObject -import github.PaginatedList -import github.PullRequestMergeStatus -import github.NamedUser -import github.PullRequestPart -import github.PullRequestComment -import github.File -import github.IssueComment +import datetime + import github.Commit +import github.File +import github.GithubObject +import github.IssueComment +import github.NamedUser +import github.PaginatedList +import github.PullRequestComment +import github.PullRequestMergeStatus +import github.PullRequestPart import github.PullRequestReview +import six +import six.moves.urllib.parse from . import Consts -import six class PullRequest(github.GithubObject.CompletableGithubObject): @@ -67,7 +68,9 @@ class PullRequest(github.GithubObject.CompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"number": self._number.value, "title": self._title.value}) + return self.get__repr__( + {"number": self._number.value, "title": self._title.value} + ) @property def additions(self): @@ -362,10 +365,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/:owner/:repo/issues/:number `_ :rtype: :class:`github.Issue.Issue` """ - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.issue_url - ) + headers, data = self._requester.requestJsonAndCheck("GET", self.issue_url) return github.Issue.Issue(self._requester, headers, data, completed=True) def create_comment(self, body, commit_id, path, position): @@ -399,11 +399,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject): "position": position, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/comments", - input=post_parameters + "POST", self.url + "/comments", input=post_parameters + ) + return github.PullRequestComment.PullRequestComment( + self._requester, headers, data, completed=True ) - return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True) def create_issue_comment(self, body): """ @@ -416,13 +416,19 @@ class PullRequest(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.issue_url + "/comments", - input=post_parameters + "POST", self.issue_url + "/comments", input=post_parameters + ) + return github.IssueComment.IssueComment( + self._requester, headers, data, completed=True ) - return github.IssueComment.IssueComment(self._requester, headers, data, completed=True) - def create_review(self, commit=github.GithubObject.NotSet, body=github.GithubObject.NotSet, event=github.GithubObject.NotSet, comments=github.GithubObject.NotSet): + def create_review( + self, + commit=github.GithubObject.NotSet, + body=github.GithubObject.NotSet, + event=github.GithubObject.NotSet, + comments=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/pulls/:number/reviews `_ :param commit: github.Commit.Commit @@ -431,28 +437,38 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param comments: list :rtype: :class:`github.PullRequestReview.PullRequestReview` """ - assert commit is github.GithubObject.NotSet or isinstance(commit, github.Commit.Commit), commit + assert commit is github.GithubObject.NotSet or isinstance( + commit, github.Commit.Commit + ), commit assert body is github.GithubObject.NotSet or isinstance(body, str), body assert event is github.GithubObject.NotSet or isinstance(event, str), event - assert comments is github.GithubObject.NotSet or isinstance(comments, list), comments + assert comments is github.GithubObject.NotSet or isinstance( + comments, list + ), comments post_parameters = dict() if commit is not github.GithubObject.NotSet: - post_parameters['commit_id'] = commit.sha + post_parameters["commit_id"] = commit.sha if body is not github.GithubObject.NotSet: - post_parameters['body'] = body - post_parameters['event'] = 'COMMENT' if event == github.GithubObject.NotSet else event + post_parameters["body"] = body + post_parameters["event"] = ( + "COMMENT" if event == github.GithubObject.NotSet else event + ) if comments is github.GithubObject.NotSet: - post_parameters['comments'] = [] + post_parameters["comments"] = [] else: - post_parameters['comments'] = comments + post_parameters["comments"] = comments headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/reviews", - input=post_parameters + "POST", self.url + "/reviews", input=post_parameters + ) + return github.PullRequestReview.PullRequestReview( + self._requester, headers, data, completed=True ) - return github.PullRequestReview.PullRequestReview(self._requester, headers, data, completed=True) - def create_review_request(self, reviewers=github.GithubObject.NotSet, team_reviewers=github.GithubObject.NotSet): + def create_review_request( + self, + reviewers=github.GithubObject.NotSet, + team_reviewers=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/pulls/:number/requested_reviewers `_ :param reviewers: list of strings @@ -461,18 +477,24 @@ class PullRequest(github.GithubObject.CompletableGithubObject): """ post_parameters = dict() if reviewers is not github.GithubObject.NotSet: - assert all(isinstance(element, (str, six.text_type)) for element in reviewers), reviewers + assert all( + isinstance(element, (str, six.text_type)) for element in reviewers + ), reviewers post_parameters["reviewers"] = reviewers if team_reviewers is not github.GithubObject.NotSet: - assert all(isinstance(element, (str, six.text_type)) for element in team_reviewers), team_reviewers + assert all( + isinstance(element, (str, six.text_type)) for element in team_reviewers + ), team_reviewers post_parameters["team_reviewers"] = team_reviewers headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/requested_reviewers", - input=post_parameters + "POST", self.url + "/requested_reviewers", input=post_parameters ) - def delete_review_request(self, reviewers=github.GithubObject.NotSet, team_reviewers=github.GithubObject.NotSet): + def delete_review_request( + self, + reviewers=github.GithubObject.NotSet, + team_reviewers=github.GithubObject.NotSet, + ): """ :calls: `DELETE /repos/:owner/:repo/pulls/:number/requested_reviewers `_ :param reviewers: list of strings @@ -481,18 +503,26 @@ class PullRequest(github.GithubObject.CompletableGithubObject): """ post_parameters = dict() if reviewers is not github.GithubObject.NotSet: - assert all(isinstance(element, (str, six.text_type)) for element in reviewers), reviewers + assert all( + isinstance(element, (str, six.text_type)) for element in reviewers + ), reviewers post_parameters["reviewers"] = reviewers if team_reviewers is not github.GithubObject.NotSet: - assert all(isinstance(element, (str, six.text_type)) for element in team_reviewers), team_reviewers + assert all( + isinstance(element, (str, six.text_type)) for element in team_reviewers + ), team_reviewers post_parameters["team_reviewers"] = team_reviewers headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/requested_reviewers", - input=post_parameters + "DELETE", self.url + "/requested_reviewers", input=post_parameters ) - def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet, state=github.GithubObject.NotSet, base=github.GithubObject.NotSet): + def edit( + self, + title=github.GithubObject.NotSet, + body=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + base=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo/pulls/:number `_ :param title: string @@ -501,10 +531,18 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param base: string :rtype: None """ - assert title is github.GithubObject.NotSet or isinstance(title, (str, six.text_type)), title - assert body is github.GithubObject.NotSet or isinstance(body, (str, six.text_type)), body - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert base is github.GithubObject.NotSet or isinstance(base, (str, six.text_type)), base + assert title is github.GithubObject.NotSet or isinstance( + title, (str, six.text_type) + ), title + assert body is github.GithubObject.NotSet or isinstance( + body, (str, six.text_type) + ), body + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert base is github.GithubObject.NotSet or isinstance( + base, (str, six.text_type) + ), base post_parameters = dict() if title is not github.GithubObject.NotSet: post_parameters["title"] = title @@ -515,9 +553,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): if base is not github.GithubObject.NotSet: post_parameters["base"] = base headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -537,10 +573,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self._parentUrl(self.url) + "/comments/" + str(id) + "GET", self._parentUrl(self.url) + "/comments/" + str(id) + ) + return github.PullRequestComment.PullRequestComment( + self._requester, headers, data, completed=True ) - return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True) def get_comments(self): """ @@ -557,7 +594,9 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` """ - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -565,7 +604,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): github.PullRequestComment.PullRequestComment, self._requester, self.url + "/comments", - url_parameters + url_parameters, ) def get_single_review_comments(self, id): @@ -579,7 +618,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): github.PullRequestComment.PullRequestComment, self._requester, self.url + "/reviews/" + str(id) + "/comments", - None + None, ) def get_commits(self): @@ -588,10 +627,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit` """ return github.PaginatedList.PaginatedList( - github.Commit.Commit, - self._requester, - self.url + "/commits", - None + github.Commit.Commit, self._requester, self.url + "/commits", None ) def get_files(self): @@ -600,10 +636,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.File.File` """ return github.PaginatedList.PaginatedList( - github.File.File, - self._requester, - self.url + "/files", - None + github.File.File, self._requester, self.url + "/files", None ) def get_issue_comment(self, id): @@ -614,10 +647,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self._parentUrl(self.issue_url) + "/comments/" + str(id) + "GET", self._parentUrl(self.issue_url) + "/comments/" + str(id) + ) + return github.IssueComment.IssueComment( + self._requester, headers, data, completed=True ) - return github.IssueComment.IssueComment(self._requester, headers, data, completed=True) def get_issue_comments(self): """ @@ -628,7 +662,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): github.IssueComment.IssueComment, self._requester, self.issue_url + "/comments", - None + None, ) def get_issue_events(self): @@ -641,7 +675,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): self._requester, self.issue_url + "/events", None, - headers={'Accept': Consts.mediaTypeLockReasonPreview} + headers={"Accept": Consts.mediaTypeLockReasonPreview}, ) def get_review(self, id): @@ -652,10 +686,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/reviews/" + str(id), + "GET", self.url + "/reviews/" + str(id), + ) + return github.PullRequestReview.PullRequestReview( + self._requester, headers, data, completed=True ) - return github.PullRequestReview.PullRequestReview(self._requester, headers, data, completed=True) def get_reviews(self): """ @@ -680,15 +715,15 @@ class PullRequest(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/requested_reviewers", None, - list_item='users' + list_item="users", ), github.PaginatedList.PaginatedList( github.Team.Team, self._requester, self.url + "/requested_reviewers", None, - list_item='teams' - ) + list_item="teams", + ), ) def get_labels(self): @@ -697,10 +732,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` """ return github.PaginatedList.PaginatedList( - github.Label.Label, - self._requester, - self.issue_url + "/labels", - None + github.Label.Label, self._requester, self.issue_url + "/labels", None ) def add_to_labels(self, *labels): @@ -709,12 +741,16 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param label: :class:`github.Label.Label` or string :rtype: None """ - assert all(isinstance(element, (github.Label.Label, str, six.text_type)) for element in labels), labels - post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels] + assert all( + isinstance(element, (github.Label.Label, str, six.text_type)) + for element in labels + ), labels + post_parameters = [ + label.name if isinstance(label, github.Label.Label) else label + for label in labels + ] headers, data = self._requester.requestJsonAndCheck( - "POST", - self.issue_url + "/labels", - input=post_parameters + "POST", self.issue_url + "/labels", input=post_parameters ) def delete_labels(self): @@ -723,8 +759,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :rtype: None """ headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.issue_url + "/labels" + "DELETE", self.issue_url + "/labels" ) def remove_from_labels(self, label): @@ -739,8 +774,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): else: label = six.moves.urllib.parse.quote(label) headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.issue_url + "/labels/" + label + "DELETE", self.issue_url + "/labels/" + label ) def set_labels(self, *labels): @@ -749,12 +783,16 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param labels: list of :class:`github.Label.Label` or strings :rtype: None """ - assert all(isinstance(element, (github.Label.Label, str, six.text_type)) for element in labels), labels - post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels] + assert all( + isinstance(element, (github.Label.Label, str, six.text_type)) + for element in labels + ), labels + post_parameters = [ + label.name if isinstance(label, github.Label.Label) else label + for label in labels + ] headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.issue_url + "/labels", - input=post_parameters + "PUT", self.issue_url + "/labels", input=post_parameters ) def is_merged(self): @@ -762,22 +800,33 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :calls: `GET /repos/:owner/:repo/pulls/:number/merge `_ :rtype: bool """ - status, headers, data = self._requester.requestJson( - "GET", - self.url + "/merge" - ) + status, headers, data = self._requester.requestJson("GET", self.url + "/merge") return status == 204 - def merge(self, commit_message=github.GithubObject.NotSet, commit_title=github.GithubObject.NotSet, merge_method=github.GithubObject.NotSet, sha=github.GithubObject.NotSet): + def merge( + self, + commit_message=github.GithubObject.NotSet, + commit_title=github.GithubObject.NotSet, + merge_method=github.GithubObject.NotSet, + sha=github.GithubObject.NotSet, + ): """ :calls: `PUT /repos/:owner/:repo/pulls/:number/merge `_ :param commit_message: string :rtype: :class:`github.PullRequestMergeStatus.PullRequestMergeStatus` """ - assert commit_message is github.GithubObject.NotSet or isinstance(commit_message, (str, six.text_type)), commit_message - assert commit_title is github.GithubObject.NotSet or isinstance(commit_title, (str, six.text_type)), commit_title - assert merge_method is github.GithubObject.NotSet or isinstance(merge_method, (str, six.text_type)), merge_method - assert sha is github.GithubObject.NotSet or isinstance(sha, (str, six.text_type)), sha + assert commit_message is github.GithubObject.NotSet or isinstance( + commit_message, (str, six.text_type) + ), commit_message + assert commit_title is github.GithubObject.NotSet or isinstance( + commit_title, (str, six.text_type) + ), commit_title + assert merge_method is github.GithubObject.NotSet or isinstance( + merge_method, (str, six.text_type) + ), merge_method + assert sha is github.GithubObject.NotSet or isinstance( + sha, (str, six.text_type) + ), sha post_parameters = dict() if commit_message is not github.GithubObject.NotSet: post_parameters["commit_message"] = commit_message @@ -788,11 +837,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject): if sha is not github.GithubObject.NotSet: post_parameters["sha"] = sha headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/merge", - input=post_parameters + "PUT", self.url + "/merge", input=post_parameters + ) + return github.PullRequestMergeStatus.PullRequestMergeStatus( + self._requester, headers, data, completed=True ) - return github.PullRequestMergeStatus.PullRequestMergeStatus(self._requester, headers, data, completed=True) def add_to_assignees(self, *assignees): """ @@ -800,12 +849,20 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param assignees: list of :class:`github.NamedUser.NamedUser` or string :rtype: None """ - assert all(isinstance(element, (github.NamedUser.NamedUser, str)) for element in assignees), assignees - post_parameters = {"assignees": [assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee for assignee in assignees]} + assert all( + isinstance(element, (github.NamedUser.NamedUser, str)) + for element in assignees + ), assignees + post_parameters = { + "assignees": [ + assignee.login + if isinstance(assignee, github.NamedUser.NamedUser) + else assignee + for assignee in assignees + ] + } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.issue_url + "/assignees", - input=post_parameters + "POST", self.issue_url + "/assignees", input=post_parameters ) self._useAttributes(data) @@ -815,12 +872,20 @@ class PullRequest(github.GithubObject.CompletableGithubObject): :param assignees: list of :class:`github.NamedUser.NamedUser` or string :rtype: None """ - assert all(isinstance(element, (github.NamedUser.NamedUser, str)) for element in assignees), assignees - post_parameters = {"assignees": [assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee for assignee in assignees]} + assert all( + isinstance(element, (github.NamedUser.NamedUser, str)) + for element in assignees + ), assignees + post_parameters = { + "assignees": [ + assignee.login + if isinstance(assignee, github.NamedUser.NamedUser) + else assignee + for assignee in assignees + ] + } headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.issue_url + "/assignees", - input=post_parameters + "DELETE", self.issue_url + "/assignees", input=post_parameters ) self._useAttributes(data) @@ -866,16 +931,26 @@ class PullRequest(github.GithubObject.CompletableGithubObject): if "additions" in attributes: # pragma no branch self._additions = self._makeIntAttribute(attributes["additions"]) if "assignee" in attributes: # pragma no branch - self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"]) + self._assignee = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["assignee"] + ) if "assignees" in attributes: # pragma no branch - self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, attributes["assignees"]) + self._assignees = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, attributes["assignees"] + ) elif "assignee" in attributes: if attributes["assignee"] is not None: - self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, [attributes["assignee"]]) + self._assignees = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, [attributes["assignee"]] + ) else: - self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, []) + self._assignees = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, [] + ) if "base" in attributes: # pragma no branch - self._base = self._makeClassAttribute(github.PullRequestPart.PullRequestPart, attributes["base"]) + self._base = self._makeClassAttribute( + github.PullRequestPart.PullRequestPart, attributes["base"] + ) if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "changed_files" in attributes: # pragma no branch @@ -897,7 +972,9 @@ class PullRequest(github.GithubObject.CompletableGithubObject): if "diff_url" in attributes: # pragma no branch self._diff_url = self._makeStringAttribute(attributes["diff_url"]) if "head" in attributes: # pragma no branch - self._head = self._makeClassAttribute(github.PullRequestPart.PullRequestPart, attributes["head"]) + self._head = self._makeClassAttribute( + github.PullRequestPart.PullRequestPart, attributes["head"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch @@ -905,31 +982,47 @@ class PullRequest(github.GithubObject.CompletableGithubObject): if "issue_url" in attributes: # pragma no branch self._issue_url = self._makeStringAttribute(attributes["issue_url"]) if "labels" in attributes: # pragma no branch - self._labels = self._makeListOfClassesAttribute(github.Label.Label, attributes["labels"]) + self._labels = self._makeListOfClassesAttribute( + github.Label.Label, attributes["labels"] + ) if "merge_commit_sha" in attributes: # pragma no branch - self._merge_commit_sha = self._makeStringAttribute(attributes["merge_commit_sha"]) + self._merge_commit_sha = self._makeStringAttribute( + attributes["merge_commit_sha"] + ) if "mergeable" in attributes: # pragma no branch self._mergeable = self._makeBoolAttribute(attributes["mergeable"]) if "mergeable_state" in attributes: # pragma no branch - self._mergeable_state = self._makeStringAttribute(attributes["mergeable_state"]) + self._mergeable_state = self._makeStringAttribute( + attributes["mergeable_state"] + ) if "merged" in attributes: # pragma no branch self._merged = self._makeBoolAttribute(attributes["merged"]) if "merged_at" in attributes: # pragma no branch self._merged_at = self._makeDatetimeAttribute(attributes["merged_at"]) if "merged_by" in attributes: # pragma no branch - self._merged_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["merged_by"]) + self._merged_by = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["merged_by"] + ) if "milestone" in attributes: # pragma no branch - self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"]) + self._milestone = self._makeClassAttribute( + github.Milestone.Milestone, attributes["milestone"] + ) if "number" in attributes: # pragma no branch self._number = self._makeIntAttribute(attributes["number"]) if "patch_url" in attributes: # pragma no branch self._patch_url = self._makeStringAttribute(attributes["patch_url"]) if "review_comment_url" in attributes: # pragma no branch - self._review_comment_url = self._makeStringAttribute(attributes["review_comment_url"]) + self._review_comment_url = self._makeStringAttribute( + attributes["review_comment_url"] + ) if "review_comments" in attributes: # pragma no branch - self._review_comments = self._makeIntAttribute(attributes["review_comments"]) + self._review_comments = self._makeIntAttribute( + attributes["review_comments"] + ) if "review_comments_url" in attributes: # pragma no branch - self._review_comments_url = self._makeStringAttribute(attributes["review_comments_url"]) + self._review_comments_url = self._makeStringAttribute( + attributes["review_comments_url"] + ) if "state" in attributes: # pragma no branch self._state = self._makeStringAttribute(attributes["state"]) if "title" in attributes: # pragma no branch @@ -939,4 +1032,6 @@ class PullRequest(github.GithubObject.CompletableGithubObject): if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/PullRequestComment.py b/github/PullRequestComment.py index edd4a54e..43bfc17d 100644 --- a/github/PullRequestComment.py +++ b/github/PullRequestComment.py @@ -35,11 +35,12 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.NamedUser +import six from . import Consts -import six class PullRequestComment(github.GithubObject.CompletableGithubObject): @@ -175,10 +176,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/pulls/comments/:number `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def edit(self, body): """ @@ -191,9 +189,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): "body": body, } headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -208,7 +204,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/reactions", None, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) def create_reaction(self, reaction_type): @@ -218,9 +214,17 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): :param reaction_type: string :rtype: :class:`github.Reaction.Reaction` """ - assert isinstance(reaction_type, (str, six.text_type)), "reaction type should be a string" - assert reaction_type in ["+1", "-1", "laugh", "confused", "heart", "hooray"], \ - "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" + assert isinstance( + reaction_type, (str, six.text_type) + ), "reaction type should be a string" + assert reaction_type in [ + "+1", + "-1", + "laugh", + "confused", + "heart", + "hooray", + ], "Invalid reaction type (https://developer.github.com/v3/reactions/#reaction-types)" post_parameters = { "content": reaction_type, @@ -229,7 +233,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): "POST", self.url + "/reactions", input=post_parameters, - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) @@ -264,15 +268,21 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): if "in_reply_to_id" in attributes: # pragma no branch self._in_reply_to_id = self._makeIntAttribute(attributes["in_reply_to_id"]) if "original_commit_id" in attributes: # pragma no branch - self._original_commit_id = self._makeStringAttribute(attributes["original_commit_id"]) + self._original_commit_id = self._makeStringAttribute( + attributes["original_commit_id"] + ) if "original_position" in attributes: # pragma no branch - self._original_position = self._makeIntAttribute(attributes["original_position"]) + self._original_position = self._makeIntAttribute( + attributes["original_position"] + ) if "path" in attributes: # pragma no branch self._path = self._makeStringAttribute(attributes["path"]) if "position" in attributes: # pragma no branch self._position = self._makeIntAttribute(attributes["position"]) if "pull_request_url" in attributes: # pragma no branch - self._pull_request_url = self._makeStringAttribute(attributes["pull_request_url"]) + self._pull_request_url = self._makeStringAttribute( + attributes["pull_request_url"] + ) if "updated_at" in attributes: # pragma no branch self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) if "url" in attributes: # pragma no branch @@ -280,4 +290,6 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/PullRequestMergeStatus.py b/github/PullRequestMergeStatus.py index 5cf0a53f..00018111 100644 --- a/github/PullRequestMergeStatus.py +++ b/github/PullRequestMergeStatus.py @@ -32,6 +32,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/PullRequestPart.py b/github/PullRequestPart.py index 3e4a4da1..5bd6a33a 100644 --- a/github/PullRequestPart.py +++ b/github/PullRequestPart.py @@ -31,10 +31,10 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.Repository +import github.GithubObject import github.NamedUser +import github.Repository class PullRequestPart(github.GithubObject.NonCompletableGithubObject): @@ -93,8 +93,12 @@ class PullRequestPart(github.GithubObject.NonCompletableGithubObject): if "ref" in attributes: # pragma no branch self._ref = self._makeStringAttribute(attributes["ref"]) if "repo" in attributes: # pragma no branch - self._repo = self._makeClassAttribute(github.Repository.Repository, attributes["repo"]) + self._repo = self._makeClassAttribute( + github.Repository.Repository, attributes["repo"] + ) if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/PullRequestReview.py b/github/PullRequestReview.py index d48b3b1e..77057378 100644 --- a/github/PullRequestReview.py +++ b/github/PullRequestReview.py @@ -27,8 +27,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser import six @@ -119,11 +119,11 @@ class PullRequestReview(github.GithubObject.CompletableGithubObject): :rtype: None """ assert isinstance(message, (str, six.text_type)), message - post_parameters = {'message': message} + post_parameters = {"message": message} headers, data = self._requester.requestJsonAndCheck( "PUT", self.pull_request_url + "/reviews/%s/dismissals" % self.id, - input=post_parameters + input=post_parameters, ) def _initAttributes(self): @@ -141,7 +141,9 @@ class PullRequestReview(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "commit_id" in attributes: # pragma no branch @@ -153,6 +155,8 @@ class PullRequestReview(github.GithubObject.CompletableGithubObject): if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "pull_request_url" in attributes: # pragma no branch - self._pull_request_url = self._makeStringAttribute(attributes["pull_request_url"]) + self._pull_request_url = self._makeStringAttribute( + attributes["pull_request_url"] + ) if "submitted_at" in attributes: # pragma no branch self._submitted_at = self._makeDatetimeAttribute(attributes["submitted_at"]) diff --git a/github/Rate.py b/github/Rate.py index 22ed3e8d..9646290b 100644 --- a/github/Rate.py +++ b/github/Rate.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -37,7 +38,9 @@ class Rate(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"limit": self._limit.value, "remaining": self._remaining.value}) + return self.get__repr__( + {"limit": self._limit.value, "remaining": self._remaining.value} + ) @property def limit(self): diff --git a/github/RateLimit.py b/github/RateLimit.py index 68d928fb..ba32b619 100644 --- a/github/RateLimit.py +++ b/github/RateLimit.py @@ -28,9 +28,9 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.Rate - from deprecated import deprecated @@ -43,12 +43,14 @@ class RateLimit(github.GithubObject.NonCompletableGithubObject): return self.get__repr__({"core": self._core.value}) @property - @deprecated(reason=""" + @deprecated( + reason=""" The rate object is deprecated. If you're writing new API client code or updating existing code, you should use the core object instead of the rate object. The core object contains the same information that is present in the rate object. - """) + """ + ) def rate(self): """ (Deprecated) Rate limit for non-search-related API, use `core` instead @@ -93,6 +95,10 @@ class RateLimit(github.GithubObject.NonCompletableGithubObject): if "core" in attributes: # pragma no branch self._core = self._makeClassAttribute(github.Rate.Rate, attributes["core"]) if "search" in attributes: # pragma no branch - self._search = self._makeClassAttribute(github.Rate.Rate, attributes["search"]) + self._search = self._makeClassAttribute( + github.Rate.Rate, attributes["search"] + ) if "graphql" in attributes: # pragma no branch - self._graphql = self._makeClassAttribute(github.Rate.Rate, attributes["graphql"]) + self._graphql = self._makeClassAttribute( + github.Rate.Rate, attributes["graphql"] + ) diff --git a/github/Reaction.py b/github/Reaction.py index 2f916e2d..10f8d048 100644 --- a/github/Reaction.py +++ b/github/Reaction.py @@ -25,6 +25,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject import github.NamedUser @@ -79,7 +80,7 @@ class Reaction(github.GithubObject.CompletableGithubObject): self._requester.requestJsonAndCheck( "DELETE", self._parentUrl("") + "/reactions/" + str(self.id), - headers={'Accept': Consts.mediaTypeReactionsPreview} + headers={"Accept": Consts.mediaTypeReactionsPreview}, ) def _initAttributes(self): @@ -96,4 +97,6 @@ class Reaction(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "user" in attributes: # pragma no branch - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/Referrer.py b/github/Referrer.py index 9a03dd9e..1c10a495 100644 --- a/github/Referrer.py +++ b/github/Referrer.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -37,11 +38,13 @@ class Referrer(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "referrer": self._referrer.value, - "count": self._count.value, - "uniques": self._uniques.value - }) + return self.get__repr__( + { + "referrer": self._referrer.value, + "count": self._count.value, + "uniques": self._uniques.value, + } + ) @property def referrer(self): diff --git a/github/Repository.py b/github/Repository.py index aa58edb0..8893bdee 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -86,58 +86,58 @@ ################################################################################ from __future__ import absolute_import -import six.moves.urllib.parse + +import collections import datetime from base64 import b64encode -import collections -from deprecated import deprecated - -import github.GithubObject -import github.PaginatedList -import github.Invitation import github.Branch -import github.IssueEvent +import github.Clones +import github.Commit +import github.CommitComment +import github.Comparison import github.ContentFile -import github.Label +import github.Download +import github.Event import github.GitBlob -import github.Organization +import github.GitCommit +import github.GithubObject import github.GitRef import github.GitRelease import github.GitReleaseAsset -import github.Issue -import github.Repository -import github.PullRequest -import github.RepositoryKey -import github.NamedUser -import github.Milestone -import github.Project -import github.Comparison -import github.CommitComment -import github.GitCommit -import github.Team -import github.Commit +import github.GitTag import github.GitTree import github.Hook -import github.Tag -import github.GitTag -import github.Download +import github.Invitation +import github.Issue +import github.IssueEvent +import github.Label +import github.Milestone +import github.NamedUser +import github.Organization +import github.PaginatedList +import github.Path import github.Permissions -import github.Event +import github.Project +import github.PullRequest +import github.Referrer +import github.Repository +import github.RepositoryKey import github.SourceImport -import github.StatsContributor -import github.StatsCommitActivity +import github.Stargazer import github.StatsCodeFrequency +import github.StatsCommitActivity +import github.StatsContributor import github.StatsParticipation import github.StatsPunchCard -import github.Stargazer -import github.Referrer -import github.Path -import github.Clones +import github.Tag +import github.Team import github.View +import six +import six.moves.urllib.parse +from deprecated import deprecated from . import Consts -import six class Repository(github.GithubObject.CompletableGithubObject): @@ -657,7 +657,9 @@ class Repository(github.GithubObject.CompletableGithubObject): """ :type: integer """ - self._completeIfNotSet(self._stargazers_count) # pragma no cover (Should be covered) + self._completeIfNotSet( + self._stargazers_count + ) # pragma no cover (Should be covered) return self._stargazers_count.value # pragma no cover (Should be covered) @property @@ -779,26 +781,31 @@ class Repository(github.GithubObject.CompletableGithubObject): :param permission: string 'pull', 'push' or 'admin' :rtype: None """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, six.text_type)), collaborator - assert permission is github.GithubObject.NotSet or isinstance(permission, (str, six.text_type)), permission + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, (str, six.text_type) + ), collaborator + assert permission is github.GithubObject.NotSet or isinstance( + permission, (str, six.text_type) + ), permission if isinstance(collaborator, github.NamedUser.NamedUser): collaborator = collaborator._identity if permission is not github.GithubObject.NotSet: - put_parameters = {'permission': permission} + put_parameters = {"permission": permission} else: put_parameters = None headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/collaborators/" + collaborator, - input=put_parameters + "PUT", self.url + "/collaborators/" + collaborator, input=put_parameters ) # return an invitation object if there's data returned by the API. If data is empty # there's a pending invitation for the given user. - return github.Invitation.Invitation(self._requester, headers, data, completed=True) if \ - data is not None else None + return ( + github.Invitation.Invitation(self._requester, headers, data, completed=True) + if data is not None + else None + ) def get_collaborator_permission(self, collaborator): """ @@ -806,12 +813,13 @@ class Repository(github.GithubObject.CompletableGithubObject): :param collaborator: string or :class:`github.NamedUser.NamedUser` :rtype: string """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, six.text_type)), collaborator + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, (str, six.text_type) + ), collaborator if isinstance(collaborator, github.NamedUser.NamedUser): collaborator = collaborator._identity headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/collaborators/" + collaborator + "/permission", + "GET", self.url + "/collaborators/" + collaborator + "/permission", ) return data["permission"] @@ -824,7 +832,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.Invitation.Invitation, self._requester, self.url + "/invitations", - None + None, ) def remove_invitation(self, invite_id): @@ -835,8 +843,7 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(invite_id, int), invite_id headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/invitations/" + str(invite_id) + "DELETE", self.url + "/invitations/" + str(invite_id) ) def compare(self, base, head): @@ -849,10 +856,11 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(base, (str, six.text_type)), base assert isinstance(head, (str, six.text_type)), head headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/compare/" + base + "..." + head + "GET", self.url + "/compare/" + base + "..." + head + ) + return github.Comparison.Comparison( + self._requester, headers, data, completed=True ) - return github.Comparison.Comparison(self._requester, headers, data, completed=True) def create_git_blob(self, content, encoding): """ @@ -868,13 +876,18 @@ class Repository(github.GithubObject.CompletableGithubObject): "encoding": encoding, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/git/blobs", - input=post_parameters + "POST", self.url + "/git/blobs", input=post_parameters ) return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) - def create_git_commit(self, message, tree, parents, author=github.GithubObject.NotSet, committer=github.GithubObject.NotSet): + def create_git_commit( + self, + message, + tree, + parents, + author=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/git/commits `_ :param message: string @@ -886,9 +899,15 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(message, (str, six.text_type)), message assert isinstance(tree, github.GitTree.GitTree), tree - assert all(isinstance(element, github.GitCommit.GitCommit) for element in parents), parents - assert author is github.GithubObject.NotSet or isinstance(author, github.InputGitAuthor), author - assert committer is github.GithubObject.NotSet or isinstance(committer, github.InputGitAuthor), committer + assert all( + isinstance(element, github.GitCommit.GitCommit) for element in parents + ), parents + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), author + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), committer post_parameters = { "message": message, "tree": tree._identity, @@ -899,11 +918,11 @@ class Repository(github.GithubObject.CompletableGithubObject): if committer is not github.GithubObject.NotSet: post_parameters["committer"] = committer._identity headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/git/commits", - input=post_parameters + "POST", self.url + "/git/commits", input=post_parameters + ) + return github.GitCommit.GitCommit( + self._requester, headers, data, completed=True ) - return github.GitCommit.GitCommit(self._requester, headers, data, completed=True) def create_git_ref(self, ref, sha): """ @@ -919,17 +938,36 @@ class Repository(github.GithubObject.CompletableGithubObject): "sha": sha, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/git/refs", - input=post_parameters + "POST", self.url + "/git/refs", input=post_parameters ) return github.GitRef.GitRef(self._requester, headers, data, completed=True) - def create_git_tag_and_release(self, tag, tag_message, release_name, release_message, object, type, tagger=github.GithubObject.NotSet, draft=False, prerelease=False): + def create_git_tag_and_release( + self, + tag, + tag_message, + release_name, + release_message, + object, + type, + tagger=github.GithubObject.NotSet, + draft=False, + prerelease=False, + ): self.create_git_tag(tag, tag_message, object, type, tagger) - return self.create_git_release(tag, release_name, release_message, draft, prerelease) + return self.create_git_release( + tag, release_name, release_message, draft, prerelease + ) - def create_git_release(self, tag, name, message, draft=False, prerelease=False, target_commitish=github.GithubObject.NotSet): + def create_git_release( + self, + tag, + name, + message, + draft=False, + prerelease=False, + target_commitish=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/releases `_ :param tag: string @@ -945,7 +983,16 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(message, (str, six.text_type)), message assert isinstance(draft, bool), draft assert isinstance(prerelease, bool), prerelease - assert target_commitish is github.GithubObject.NotSet or isinstance(target_commitish, (str, six.text_type, github.Branch.Branch, github.Commit.Commit, github.GitCommit.GitCommit)), target_commitish + assert target_commitish is github.GithubObject.NotSet or isinstance( + target_commitish, + ( + str, + six.text_type, + github.Branch.Branch, + github.Commit.Commit, + github.GitCommit.GitCommit, + ), + ), target_commitish post_parameters = { "tag_name": tag, "name": name, @@ -957,16 +1004,20 @@ class Repository(github.GithubObject.CompletableGithubObject): post_parameters["target_commitish"] = target_commitish elif isinstance(target_commitish, github.Branch.Branch): post_parameters["target_commitish"] = target_commitish.name - elif isinstance(target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit)): + elif isinstance( + target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit) + ): post_parameters["target_commitish"] = target_commitish.sha headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/releases", - input=post_parameters + "POST", self.url + "/releases", input=post_parameters + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True ) - return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) - def create_git_tag(self, tag, message, object, type, tagger=github.GithubObject.NotSet): + def create_git_tag( + self, tag, message, object, type, tagger=github.GithubObject.NotSet + ): """ :calls: `POST /repos/:owner/:repo/git/tags `_ :param tag: string @@ -980,7 +1031,9 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(message, (str, six.text_type)), message assert isinstance(object, (str, six.text_type)), object assert isinstance(type, (str, six.text_type)), type - assert tagger is github.GithubObject.NotSet or isinstance(tagger, github.InputGitAuthor), tagger + assert tagger is github.GithubObject.NotSet or isinstance( + tagger, github.InputGitAuthor + ), tagger post_parameters = { "tag": tag, "message": message, @@ -990,9 +1043,7 @@ class Repository(github.GithubObject.CompletableGithubObject): if tagger is not github.GithubObject.NotSet: post_parameters["tagger"] = tagger._identity headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/git/tags", - input=post_parameters + "POST", self.url + "/git/tags", input=post_parameters ) return github.GitTag.GitTag(self._requester, headers, data, completed=True) @@ -1003,21 +1054,29 @@ class Repository(github.GithubObject.CompletableGithubObject): :param base_tree: :class:`github.GitTree.GitTree` :rtype: :class:`github.GitTree.GitTree` """ - assert all(isinstance(element, github.InputGitTreeElement) for element in tree), tree - assert base_tree is github.GithubObject.NotSet or isinstance(base_tree, github.GitTree.GitTree), base_tree + assert all( + isinstance(element, github.InputGitTreeElement) for element in tree + ), tree + assert base_tree is github.GithubObject.NotSet or isinstance( + base_tree, github.GitTree.GitTree + ), base_tree post_parameters = { "tree": [element._identity for element in tree], } if base_tree is not github.GithubObject.NotSet: post_parameters["base_tree"] = base_tree._identity headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/git/trees", - input=post_parameters + "POST", self.url + "/git/trees", input=post_parameters ) return github.GitTree.GitTree(self._requester, headers, data, completed=True) - def create_hook(self, name, config, events=github.GithubObject.NotSet, active=github.GithubObject.NotSet): + def create_hook( + self, + name, + config, + events=github.GithubObject.NotSet, + active=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/hooks `_ :param name: string @@ -1028,7 +1087,9 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name assert isinstance(config, dict), config - assert events is github.GithubObject.NotSet or all(isinstance(element, (str, six.text_type)) for element in events), events + assert events is github.GithubObject.NotSet or all( + isinstance(element, (str, six.text_type)) for element in events + ), events assert active is github.GithubObject.NotSet or isinstance(active, bool), active post_parameters = { "name": name, @@ -1039,13 +1100,19 @@ class Repository(github.GithubObject.CompletableGithubObject): if active is not github.GithubObject.NotSet: post_parameters["active"] = active headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/hooks", - input=post_parameters + "POST", self.url + "/hooks", input=post_parameters ) return github.Hook.Hook(self._requester, headers, data, completed=True) - def create_issue(self, title, body=github.GithubObject.NotSet, assignee=github.GithubObject.NotSet, milestone=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, assignees=github.GithubObject.NotSet): + def create_issue( + self, + title, + body=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + milestone=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + assignees=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/issues `_ :param title: string @@ -1057,11 +1124,27 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Issue.Issue` """ assert isinstance(title, (str, six.text_type)), title - assert body is github.GithubObject.NotSet or isinstance(body, (str, six.text_type)), body - assert assignee is github.GithubObject.NotSet or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, six.text_type)), assignee - assert assignees is github.GithubObject.NotSet or all(isinstance(element, github.NamedUser.NamedUser) or isinstance(element, (str, six.text_type)) for element in assignees), assignees - assert milestone is github.GithubObject.NotSet or isinstance(milestone, github.Milestone.Milestone), milestone - assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) or isinstance(element, (str, six.text_type)) for element in labels), labels + assert body is github.GithubObject.NotSet or isinstance( + body, (str, six.text_type) + ), body + assert ( + assignee is github.GithubObject.NotSet + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, (str, six.text_type)) + ), assignee + assert assignees is github.GithubObject.NotSet or all( + isinstance(element, github.NamedUser.NamedUser) + or isinstance(element, (str, six.text_type)) + for element in assignees + ), assignees + assert milestone is github.GithubObject.NotSet or isinstance( + milestone, github.Milestone.Milestone + ), milestone + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) + or isinstance(element, (str, six.text_type)) + for element in labels + ), labels post_parameters = { "title": title, @@ -1074,15 +1157,21 @@ class Repository(github.GithubObject.CompletableGithubObject): else: post_parameters["assignee"] = assignee._identity if assignees is not github.GithubObject.NotSet: - post_parameters["assignees"] = [element._identity if isinstance(element, github.NamedUser.NamedUser) else element for element in assignees] + post_parameters["assignees"] = [ + element._identity + if isinstance(element, github.NamedUser.NamedUser) + else element + for element in assignees + ] if milestone is not github.GithubObject.NotSet: post_parameters["milestone"] = milestone._identity if labels is not github.GithubObject.NotSet: - post_parameters["labels"] = [element.name if isinstance(element, github.Label.Label) else element for element in labels] + post_parameters["labels"] = [ + element.name if isinstance(element, github.Label.Label) else element + for element in labels + ] headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/issues", - input=post_parameters + "POST", self.url + "/issues", input=post_parameters ) return github.Issue.Issue(self._requester, headers, data, completed=True) @@ -1103,11 +1192,11 @@ class Repository(github.GithubObject.CompletableGithubObject): "read_only": read_only, } headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/keys", - input=post_parameters + "POST", self.url + "/keys", input=post_parameters + ) + return github.RepositoryKey.RepositoryKey( + self._requester, headers, data, completed=True ) - return github.RepositoryKey.RepositoryKey(self._requester, headers, data, completed=True) def create_label(self, name, color, description=github.GithubObject.NotSet): """ @@ -1119,7 +1208,9 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name assert isinstance(color, (str, six.text_type)), color - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description post_parameters = { "name": name, "color": color, @@ -1130,11 +1221,17 @@ class Repository(github.GithubObject.CompletableGithubObject): "POST", self.url + "/labels", input=post_parameters, - headers={'Accept': Consts.mediaTypeLabelDescriptionSearchPreview} + headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, ) return github.Label.Label(self._requester, headers, data, completed=True) - def create_milestone(self, title, state=github.GithubObject.NotSet, description=github.GithubObject.NotSet, due_on=github.GithubObject.NotSet): + def create_milestone( + self, + title, + state=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + due_on=github.GithubObject.NotSet, + ): """ :calls: `POST /repos/:owner/:repo/milestones `_ :param title: string @@ -1144,9 +1241,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.Milestone.Milestone` """ assert isinstance(title, (str, six.text_type)), title - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert due_on is github.GithubObject.NotSet or isinstance(due_on, (datetime.datetime, datetime.date)), due_on + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert due_on is github.GithubObject.NotSet or isinstance( + due_on, (datetime.datetime, datetime.date) + ), due_on post_parameters = { "title": title, } @@ -1160,11 +1263,11 @@ class Repository(github.GithubObject.CompletableGithubObject): else: post_parameters["due_on"] = due_on.isoformat() headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/milestones", - input=post_parameters + "POST", self.url + "/milestones", input=post_parameters + ) + return github.Milestone.Milestone( + self._requester, headers, data, completed=True ) - return github.Milestone.Milestone(self._requester, headers, data, completed=True) def create_project(self, name, body=github.GithubObject.NotSet): """ @@ -1173,19 +1276,18 @@ class Repository(github.GithubObject.CompletableGithubObject): :param body: string """ assert isinstance(name, (str, six.text_type)), name - assert body is github.GithubObject.NotSet or isinstance(body, (str, six.text_type)), body + assert body is github.GithubObject.NotSet or isinstance( + body, (str, six.text_type) + ), body post_parameters = { "name": name, "body": body, } import_header = {"Accept": Consts.mediaTypeProjectsPreview} if body is not github.GithubObject.NotSet: - post_parameters['body'] = body + post_parameters["body"] = body headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/projects", - headers=import_header, - input=post_parameters + "POST", self.url + "/projects", headers=import_header, input=post_parameters ) return github.Project.Project(self._requester, headers, data, completed=True) @@ -1205,14 +1307,24 @@ class Repository(github.GithubObject.CompletableGithubObject): else: return self.__create_pull_2(*args, **kwds) - def __create_pull_1(self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet): + def __create_pull_1( + self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet + ): assert isinstance(title, (str, six.text_type)), title assert isinstance(body, (str, six.text_type)), body assert isinstance(base, (str, six.text_type)), base assert isinstance(head, (str, six.text_type)), head - assert maintainer_can_modify is github.GithubObject.NotSet or isinstance(maintainer_can_modify, bool), maintainer_can_modify + assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( + maintainer_can_modify, bool + ), maintainer_can_modify if maintainer_can_modify is not github.GithubObject.NotSet: - return self.__create_pull(title=title, body=body, base=base, head=head, maintainer_can_modify=maintainer_can_modify) + return self.__create_pull( + title=title, + body=body, + base=base, + head=head, + maintainer_can_modify=maintainer_can_modify, + ) else: return self.__create_pull(title=title, body=body, base=base, head=head) @@ -1225,13 +1337,19 @@ class Repository(github.GithubObject.CompletableGithubObject): def __create_pull(self, **kwds): post_parameters = kwds headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/pulls", - input=post_parameters + "POST", self.url + "/pulls", input=post_parameters + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True ) - return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) - def create_source_import(self, vcs, vcs_url, vcs_username=github.GithubObject.NotSet, vcs_password=github.GithubObject.NotSet): + def create_source_import( + self, + vcs, + vcs_url, + vcs_username=github.GithubObject.NotSet, + vcs_password=github.GithubObject.NotSet, + ): """ :calls: `PUT /repos/:owner/:repo/import `_ :param vcs: string @@ -1242,12 +1360,13 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(vcs, (str, six.text_type)), vcs assert isinstance(vcs_url, (str, six.text_type)), vcs_url - assert vcs_username is github.GithubObject.NotSet or isinstance(vcs_username, (str, six.text_type)), vcs_username - assert vcs_password is github.GithubObject.NotSet or isinstance(vcs_password, (str, six.text_type)), vcs_password - put_parameters = { - "vcs": vcs, - "vcs_url": vcs_url - } + assert vcs_username is github.GithubObject.NotSet or isinstance( + vcs_username, (str, six.text_type) + ), vcs_username + assert vcs_password is github.GithubObject.NotSet or isinstance( + vcs_password, (str, six.text_type) + ), vcs_password + put_parameters = {"vcs": vcs, "vcs_url": vcs_url} if vcs_username is not github.GithubObject.NotSet: put_parameters["vcs_username"] = vcs_username @@ -1258,25 +1377,36 @@ class Repository(github.GithubObject.CompletableGithubObject): import_header = {"Accept": Consts.mediaTypeImportPreview} headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/import", - headers=import_header, - input=put_parameters + "PUT", self.url + "/import", headers=import_header, input=put_parameters ) - return github.SourceImport.SourceImport(self._requester, headers, data, completed=False) + return github.SourceImport.SourceImport( + self._requester, headers, data, completed=False + ) def delete(self): """ :calls: `DELETE /repos/:owner/:repo `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, name=None, description=github.GithubObject.NotSet, homepage=github.GithubObject.NotSet, private=github.GithubObject.NotSet, has_issues=github.GithubObject.NotSet, has_projects=github.GithubObject.NotSet, has_wiki=github.GithubObject.NotSet, has_downloads=github.GithubObject.NotSet, default_branch=github.GithubObject.NotSet, allow_squash_merge=github.GithubObject.NotSet, allow_merge_commit=github.GithubObject.NotSet, allow_rebase_merge=github.GithubObject.NotSet, archived=github.GithubObject.NotSet): + def edit( + self, + name=None, + description=github.GithubObject.NotSet, + homepage=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + has_issues=github.GithubObject.NotSet, + has_projects=github.GithubObject.NotSet, + has_wiki=github.GithubObject.NotSet, + has_downloads=github.GithubObject.NotSet, + default_branch=github.GithubObject.NotSet, + allow_squash_merge=github.GithubObject.NotSet, + allow_merge_commit=github.GithubObject.NotSet, + allow_rebase_merge=github.GithubObject.NotSet, + archived=github.GithubObject.NotSet, + ): """ :calls: `PATCH /repos/:owner/:repo `_ :param name: string @@ -1297,18 +1427,42 @@ class Repository(github.GithubObject.CompletableGithubObject): if name is None: name = self.name assert isinstance(name, (str, six.text_type)), name - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert homepage is github.GithubObject.NotSet or isinstance(homepage, (str, six.text_type)), homepage - assert private is github.GithubObject.NotSet or isinstance(private, bool), private - assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues - assert has_projects is github.GithubObject.NotSet or isinstance(has_projects, bool), has_projects - assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki - assert has_downloads is github.GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads - assert default_branch is github.GithubObject.NotSet or isinstance(default_branch, (str, six.text_type)), default_branch - assert allow_squash_merge is github.GithubObject.NotSet or isinstance(allow_squash_merge, bool), allow_squash_merge - assert allow_merge_commit is github.GithubObject.NotSet or isinstance(allow_merge_commit, bool), allow_merge_commit - assert allow_rebase_merge is github.GithubObject.NotSet or isinstance(allow_rebase_merge, bool), allow_rebase_merge - assert archived is github.GithubObject.NotSet or (isinstance(archived, bool) and archived is True), archived + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert homepage is github.GithubObject.NotSet or isinstance( + homepage, (str, six.text_type) + ), homepage + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + assert has_issues is github.GithubObject.NotSet or isinstance( + has_issues, bool + ), has_issues + assert has_projects is github.GithubObject.NotSet or isinstance( + has_projects, bool + ), has_projects + assert has_wiki is github.GithubObject.NotSet or isinstance( + has_wiki, bool + ), has_wiki + assert has_downloads is github.GithubObject.NotSet or isinstance( + has_downloads, bool + ), has_downloads + assert default_branch is github.GithubObject.NotSet or isinstance( + default_branch, (str, six.text_type) + ), default_branch + assert allow_squash_merge is github.GithubObject.NotSet or isinstance( + allow_squash_merge, bool + ), allow_squash_merge + assert allow_merge_commit is github.GithubObject.NotSet or isinstance( + allow_merge_commit, bool + ), allow_merge_commit + assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( + allow_rebase_merge, bool + ), allow_rebase_merge + assert archived is github.GithubObject.NotSet or ( + isinstance(archived, bool) and archived is True + ), archived post_parameters = { "name": name, } @@ -1337,9 +1491,7 @@ class Repository(github.GithubObject.CompletableGithubObject): if archived is not github.GithubObject.NotSet: post_parameters["archived"] = archived headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -1351,14 +1503,13 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: string """ assert isinstance(archive_format, (str, six.text_type)), archive_format - assert ref is github.GithubObject.NotSet or isinstance(ref, (str, six.text_type)), ref + assert ref is github.GithubObject.NotSet or isinstance( + ref, (str, six.text_type) + ), ref url = self.url + "/" + archive_format if ref is not github.GithubObject.NotSet: url += "/" + ref - headers, data = self._requester.requestJsonAndCheck( - "GET", - url - ) + headers, data = self._requester.requestJsonAndCheck("GET", url) return headers["location"] def get_assignees(self): @@ -1367,10 +1518,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - self.url + "/assignees", - None + github.NamedUser.NamedUser, self._requester, self.url + "/assignees", None ) def get_branch(self, branch): @@ -1381,8 +1529,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(branch, (str, six.text_type)), branch headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/branches/" + branch + "GET", self.url + "/branches/" + branch ) return github.Branch.Branch(self._requester, headers, data, completed=True) @@ -1392,10 +1539,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Branch.Branch` """ return github.PaginatedList.PaginatedList( - github.Branch.Branch, - self._requester, - self.url + "/branches", - None + github.Branch.Branch, self._requester, self.url + "/branches", None ) def get_collaborators(self, affiliation=github.GithubObject.NotSet): @@ -1406,18 +1550,19 @@ class Repository(github.GithubObject.CompletableGithubObject): """ url_parameters = dict() - allowed_affiliations = ['outside', 'direct', 'all'] + allowed_affiliations = ["outside", "direct", "all"] if affiliation is not github.GithubObject.NotSet: assert isinstance(affiliation, str), affiliation - assert affiliation in allowed_affiliations, \ - 'Affiliation can be one of ' + ', '.join(allowed_affiliations) - url_parameters['affiliation'] = affiliation + assert ( + affiliation in allowed_affiliations + ), "Affiliation can be one of " + ", ".join(allowed_affiliations) + url_parameters["affiliation"] = affiliation return github.PaginatedList.PaginatedList( github.NamedUser.NamedUser, self._requester, self.url + "/collaborators", - url_parameters + url_parameters, ) def get_comment(self, id): @@ -1428,10 +1573,11 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/comments/" + str(id) + "GET", self.url + "/comments/" + str(id) + ) + return github.CommitComment.CommitComment( + self._requester, headers, data, completed=True ) - return github.CommitComment.CommitComment(self._requester, headers, data, completed=True) def get_comments(self): """ @@ -1442,7 +1588,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.CommitComment.CommitComment, self._requester, self.url + "/comments", - None + None, ) def get_commit(self, sha): @@ -1453,12 +1599,18 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(sha, (str, six.text_type)), sha headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/commits/" + sha + "GET", self.url + "/commits/" + sha ) return github.Commit.Commit(self._requester, headers, data, completed=True) - def get_commits(self, sha=github.GithubObject.NotSet, path=github.GithubObject.NotSet, since=github.GithubObject.NotSet, until=github.GithubObject.NotSet, author=github.GithubObject.NotSet): + def get_commits( + self, + sha=github.GithubObject.NotSet, + path=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + until=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/commits `_ :param sha: string @@ -1468,11 +1620,27 @@ class Repository(github.GithubObject.CompletableGithubObject): :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, six.text_type)), sha - assert path is github.GithubObject.NotSet or isinstance(path, (str, six.text_type)), 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 author is github.GithubObject.NotSet or isinstance(author, (str, six.text_type, github.NamedUser.NamedUser, github.AuthenticatedUser.AuthenticatedUser)), author + assert sha is github.GithubObject.NotSet or isinstance( + sha, (str, six.text_type) + ), sha + assert path is github.GithubObject.NotSet or isinstance( + path, (str, six.text_type) + ), 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 author is github.GithubObject.NotSet or isinstance( + author, + ( + str, + six.text_type, + github.NamedUser.NamedUser, + github.AuthenticatedUser.AuthenticatedUser, + ), + ), author url_parameters = dict() if sha is not github.GithubObject.NotSet: url_parameters["sha"] = sha @@ -1483,15 +1651,18 @@ class Repository(github.GithubObject.CompletableGithubObject): if until is not github.GithubObject.NotSet: url_parameters["until"] = until.strftime("%Y-%m-%dT%H:%M:%SZ") if author is not github.GithubObject.NotSet: - if isinstance(author, (github.NamedUser.NamedUser, github.AuthenticatedUser.AuthenticatedUser)): + if isinstance( + author, + ( + github.NamedUser.NamedUser, + github.AuthenticatedUser.AuthenticatedUser, + ), + ): url_parameters["author"] = author.login else: url_parameters["author"] = author return github.PaginatedList.PaginatedList( - github.Commit.Commit, - self._requester, - self.url + "/commits", - url_parameters + github.Commit.Commit, self._requester, self.url + "/commits", url_parameters ) def get_contents(self, path, ref=github.GithubObject.NotSet): @@ -1502,35 +1673,39 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.ContentFile.ContentFile` or a list of them """ assert isinstance(path, (str, six.text_type)), path - assert ref is github.GithubObject.NotSet or isinstance(ref, (str, six.text_type)), ref + assert ref is github.GithubObject.NotSet or isinstance( + ref, (str, six.text_type) + ), ref # Path of '/' should be the empty string. - if path == '/': - path = '' + if path == "/": + path = "" url_parameters = dict() if ref is not github.GithubObject.NotSet: url_parameters["ref"] = ref headers, data = self._requester.requestJsonAndCheck( "GET", self.url + "/contents/" + six.moves.urllib.parse.quote(path), - parameters=url_parameters + parameters=url_parameters, ) # Handle 302 redirect response - if headers.get('status') == '302 Found' and headers.get('location'): + if headers.get("status") == "302 Found" and headers.get("location"): headers, data = self._requester.requestJsonAndCheck( - "GET", - headers['location'], - parameters=url_parameters + "GET", headers["location"], parameters=url_parameters ) if isinstance(data, list): return [ # Lazy completion only makes sense for files. See discussion # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130 - github.ContentFile.ContentFile(self._requester, headers, item, completed=(item["type"] != "file")) + github.ContentFile.ContentFile( + self._requester, headers, item, completed=(item["type"] != "file") + ) for item in data ] - return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) def get_top_referrers(self): """ @@ -1538,8 +1713,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`list` of :class:`github.Referrer.Referrer` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/traffic/popular/referrers" + "GET", self.url + "/traffic/popular/referrers" ) if isinstance(data, list): return [ @@ -1553,8 +1727,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`list` of :class:`github.Path.Path` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/traffic/popular/paths" + "GET", self.url + "/traffic/popular/paths" ) if isinstance(data, list): return [ @@ -1568,16 +1741,20 @@ class Repository(github.GithubObject.CompletableGithubObject): :param per: string, must be one of day or week, day by default :rtype: None or list of :class:`github.View.View` """ - assert per is github.GithubObject.NotSet or (isinstance(per, (str, six.text_type)) and (per == "day" or per == "week")), "per must be day or week, day by default" + assert per is github.GithubObject.NotSet or ( + isinstance(per, (str, six.text_type)) and (per == "day" or per == "week") + ), "per must be day or week, day by default" url_parameters = dict() if per is not github.GithubObject.NotSet: url_parameters["per"] = per headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/traffic/views", - parameters=url_parameters + "GET", self.url + "/traffic/views", parameters=url_parameters ) - if (isinstance(data, dict)) and ("views" in data) and (isinstance(data["views"], list)): + if ( + (isinstance(data, dict)) + and ("views" in data) + and (isinstance(data["views"], list)) + ): data["views"] = [ github.View.View(self._requester, headers, item, completed=True) for item in data["views"] @@ -1590,16 +1767,20 @@ class Repository(github.GithubObject.CompletableGithubObject): :param per: string, must be one of day or week, day by default :rtype: None or list of :class:`github.Clone.Clone` """ - assert per is github.GithubObject.NotSet or (isinstance(per, (str, six.text_type)) and (per == "day" or per == "week")), "per must be day or week, day by default" + assert per is github.GithubObject.NotSet or ( + isinstance(per, (str, six.text_type)) and (per == "day" or per == "week") + ), "per must be day or week, day by default" url_parameters = dict() if per is not github.GithubObject.NotSet: url_parameters["per"] = per headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/traffic/clones", - parameters=url_parameters + "GET", self.url + "/traffic/clones", parameters=url_parameters ) - if (isinstance(data, dict)) and ("clones" in data) and (isinstance(data["clones"], list)): + if ( + (isinstance(data, dict)) + and ("clones" in data) + and (isinstance(data["clones"], list)) + ): data["clones"] = [ github.Clones.Clones(self._requester, headers, item, completed=True) for item in data["clones"] @@ -1622,13 +1803,18 @@ class Repository(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/projects", url_parameters, - {"Accept": Consts.mediaTypeProjectsPreview} + {"Accept": Consts.mediaTypeProjectsPreview}, ) - def create_file(self, path, message, content, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet): + def create_file( + self, + path, + message, + content, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): """Create a file in this repository. :calls: `PUT /repos/:owner/:repo/contents/:path `_ @@ -1642,29 +1828,30 @@ class Repository(github.GithubObject.CompletableGithubObject): 'content': :class:`ContentFile `:, 'commit': :class:`Commit `} """ - assert isinstance(path, (str, six.text_type)), \ - 'path must be str/unicode object' - assert isinstance(message, (str, six.text_type)), \ - 'message must be str/unicode object' - assert isinstance(content, (str, six.text_type, bytes)), \ - 'content must be a str/unicode object' - assert branch is github.GithubObject.NotSet \ - or isinstance(branch, (str, six.text_type)), \ - 'branch must be a str/unicode object' - assert author is github.GithubObject.NotSet \ - or isinstance(author, github.InputGitAuthor), \ - 'author must be a github.InputGitAuthor object' - assert committer is github.GithubObject.NotSet \ - or isinstance(committer, github.InputGitAuthor), \ - 'committer must be a github.InputGitAuthor object' + assert isinstance(path, (str, six.text_type)), "path must be str/unicode object" + assert isinstance( + message, (str, six.text_type) + ), "message must be str/unicode object" + assert isinstance( + content, (str, six.text_type, bytes) + ), "content must be a str/unicode object" + assert branch is github.GithubObject.NotSet or isinstance( + branch, (str, six.text_type) + ), "branch must be a str/unicode object" + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), "author must be a github.InputGitAuthor object" + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), "committer must be a github.InputGitAuthor object" if not isinstance(content, bytes): - content = content.encode('utf-8') - content = b64encode(content).decode('utf-8') - put_parameters = {'message': message, 'content': content} + content = content.encode("utf-8") + content = b64encode(content).decode("utf-8") + put_parameters = {"message": message, "content": content} if branch is not github.GithubObject.NotSet: - put_parameters['branch'] = branch + put_parameters["branch"] = branch if author is not github.GithubObject.NotSet: put_parameters["author"] = author._identity if committer is not github.GithubObject.NotSet: @@ -1673,16 +1860,28 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "PUT", self.url + "/contents/" + six.moves.urllib.parse.quote(path), - input=put_parameters + input=put_parameters, ) - return {'content': github.ContentFile.ContentFile(self._requester, headers, data["content"], completed=False), - 'commit': github.Commit.Commit(self._requester, headers, data["commit"], completed=True)} + return { + "content": github.ContentFile.ContentFile( + self._requester, headers, data["content"], completed=False + ), + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + } - def update_file(self, path, message, content, sha, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet): + def update_file( + self, + path, + message, + content, + sha, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): """This method updates a file in a repository :calls: `PUT /repos/:owner/:repo/contents/:path `_ @@ -1697,33 +1896,32 @@ class Repository(github.GithubObject.CompletableGithubObject): 'content': :class:`ContentFile `:, 'commit': :class:`Commit `} """ - assert isinstance(path, (str, six.text_type)), \ - 'path must be str/unicode object' - assert isinstance(message, (str, six.text_type)), \ - 'message must be str/unicode object' - assert isinstance(content, (str, six.text_type, bytes)), \ - 'content must be a str/unicode object' - assert isinstance(sha, (str, six.text_type)), \ - 'sha must be a str/unicode object' - assert branch is github.GithubObject.NotSet \ - or isinstance(branch, (str, six.text_type)), \ - 'branch must be a str/unicode object' - assert author is github.GithubObject.NotSet \ - or isinstance(author, github.InputGitAuthor), \ - 'author must be a github.InputGitAuthor object' - assert committer is github.GithubObject.NotSet \ - or isinstance(committer, github.InputGitAuthor), \ - 'committer must be a github.InputGitAuthor object' + assert isinstance(path, (str, six.text_type)), "path must be str/unicode object" + assert isinstance( + message, (str, six.text_type) + ), "message must be str/unicode object" + assert isinstance( + content, (str, six.text_type, bytes) + ), "content must be a str/unicode object" + assert isinstance(sha, (str, six.text_type)), "sha must be a str/unicode object" + assert branch is github.GithubObject.NotSet or isinstance( + branch, (str, six.text_type) + ), "branch must be a str/unicode object" + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), "author must be a github.InputGitAuthor object" + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), "committer must be a github.InputGitAuthor object" if not isinstance(content, bytes): - content = content.encode('utf-8') - content = b64encode(content).decode('utf-8') + content = content.encode("utf-8") + content = b64encode(content).decode("utf-8") - put_parameters = {'message': message, 'content': content, - 'sha': sha} + put_parameters = {"message": message, "content": content, "sha": sha} if branch is not github.GithubObject.NotSet: - put_parameters['branch'] = branch + put_parameters["branch"] = branch if author is not github.GithubObject.NotSet: put_parameters["author"] = author._identity if committer is not github.GithubObject.NotSet: @@ -1732,16 +1930,27 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "PUT", self.url + "/contents/" + six.moves.urllib.parse.quote(path), - input=put_parameters + input=put_parameters, ) - return {'commit': github.Commit.Commit(self._requester, headers, data["commit"], completed=True), - 'content': github.ContentFile.ContentFile(self._requester, headers, data["content"], completed=False)} + return { + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + "content": github.ContentFile.ContentFile( + self._requester, headers, data["content"], completed=False + ), + } - def delete_file(self, path, message, sha, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet): + def delete_file( + self, + path, + message, + sha, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): """This method deletes a file in a repository :calls: `DELETE /repos/:owner/:repo/contents/:path `_ @@ -1755,25 +1964,24 @@ class Repository(github.GithubObject.CompletableGithubObject): 'content': :class:`null `:, 'commit': :class:`Commit `} """ - assert isinstance(path, (str, six.text_type)), \ - 'path must be str/unicode object' - assert isinstance(message, (str, six.text_type)), \ - 'message must be str/unicode object' - assert isinstance(sha, (str, six.text_type)), \ - 'sha must be a str/unicode object' - assert branch is github.GithubObject.NotSet \ - or isinstance(branch, (str, six.text_type)), \ - 'branch must be a str/unicode object' - assert author is github.GithubObject.NotSet \ - or isinstance(author, github.InputGitAuthor), \ - 'author must be a github.InputGitAuthor object' - assert committer is github.GithubObject.NotSet \ - or isinstance(committer, github.InputGitAuthor), \ - 'committer must be a github.InputGitAuthor object' + assert isinstance(path, (str, six.text_type)), "path must be str/unicode object" + assert isinstance( + message, (str, six.text_type) + ), "message must be str/unicode object" + assert isinstance(sha, (str, six.text_type)), "sha must be a str/unicode object" + assert branch is github.GithubObject.NotSet or isinstance( + branch, (str, six.text_type) + ), "branch must be a str/unicode object" + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), "author must be a github.InputGitAuthor object" + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), "committer must be a github.InputGitAuthor object" - url_parameters = {'message': message, 'sha': sha} + url_parameters = {"message": message, "sha": sha} if branch is not github.GithubObject.NotSet: - url_parameters['branch'] = branch + url_parameters["branch"] = branch if author is not github.GithubObject.NotSet: url_parameters["author"] = author._identity if committer is not github.GithubObject.NotSet: @@ -1782,16 +1990,22 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "DELETE", self.url + "/contents/" + six.moves.urllib.parse.quote(path), - input=url_parameters + input=url_parameters, ) - return {'commit': github.Commit.Commit(self._requester, headers, data["commit"], completed=True), - 'content': github.GithubObject.NotSet} + return { + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + "content": github.GithubObject.NotSet, + } - @deprecated(reason=""" + @deprecated( + reason=""" Repository.get_dir_contents() is deprecated, use Repository.get_contents() instead. - """) + """ + ) def get_dir_contents(self, path, ref=github.GithubObject.NotSet): """ :calls: `GET /repos/:owner/:repo/contents/:path `_ @@ -1815,7 +2029,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.NamedUser.NamedUser, self._requester, self.url + "/contributors", - url_parameters + url_parameters, ) def get_download(self, id): @@ -1826,8 +2040,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/downloads/" + str(id) + "GET", self.url + "/downloads/" + str(id) ) return github.Download.Download(self._requester, headers, data, completed=True) @@ -1837,10 +2050,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Download.Download` """ return github.PaginatedList.PaginatedList( - github.Download.Download, - self._requester, - self.url + "/downloads", - None + github.Download.Download, self._requester, self.url + "/downloads", None ) def get_events(self): @@ -1849,10 +2059,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - self.url + "/events", - None + github.Event.Event, self._requester, self.url + "/events", None ) def get_forks(self): @@ -1861,10 +2068,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - Repository, - self._requester, - self.url + "/forks", - None + Repository, self._requester, self.url + "/forks", None ) def create_fork(self, organization=github.GithubObject.NotSet): @@ -1892,8 +2096,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(sha, (str, six.text_type)), sha headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/git/blobs/" + sha + "GET", self.url + "/git/blobs/" + sha ) return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) @@ -1905,10 +2108,11 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(sha, (str, six.text_type)), sha headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/git/commits/" + sha + "GET", self.url + "/git/commits/" + sha + ) + return github.GitCommit.GitCommit( + self._requester, headers, data, completed=True ) - return github.GitCommit.GitCommit(self._requester, headers, data, completed=True) def get_git_ref(self, ref): """ @@ -1921,8 +2125,7 @@ class Repository(github.GithubObject.CompletableGithubObject): prefix = "/git/" assert isinstance(ref, (str, six.text_type)), ref headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + prefix + ref + "GET", self.url + prefix + ref ) return github.GitRef.GitRef(self._requester, headers, data, completed=True) @@ -1932,10 +2135,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRef.GitRef` """ return github.PaginatedList.PaginatedList( - github.GitRef.GitRef, - self._requester, - self.url + "/git/refs", - None + github.GitRef.GitRef, self._requester, self.url + "/git/refs", None ) def get_git_tag(self, sha): @@ -1946,8 +2146,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(sha, (str, six.text_type)), sha headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/git/tags/" + sha + "GET", self.url + "/git/tags/" + sha ) return github.GitTag.GitTag(self._requester, headers, data, completed=True) @@ -1959,15 +2158,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.GitTree.GitTree` """ assert isinstance(sha, (str, six.text_type)), sha - assert recursive is github.GithubObject.NotSet or isinstance(recursive, bool), recursive + assert recursive is github.GithubObject.NotSet or isinstance( + recursive, bool + ), recursive url_parameters = dict() if recursive is not github.GithubObject.NotSet and recursive: # GitHub API requires the recursive parameter be set to 1. url_parameters["recursive"] = 1 headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/git/trees/" + sha, - parameters=url_parameters + "GET", self.url + "/git/trees/" + sha, parameters=url_parameters ) return github.GitTree.GitTree(self._requester, headers, data, completed=True) @@ -1979,8 +2178,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/hooks/" + str(id) + "GET", self.url + "/hooks/" + str(id) ) return github.Hook.Hook(self._requester, headers, data, completed=True) @@ -1990,10 +2188,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` """ return github.PaginatedList.PaginatedList( - github.Hook.Hook, - self._requester, - self.url + "/hooks", - None + github.Hook.Hook, self._requester, self.url + "/hooks", None ) def get_issue(self, number): @@ -2004,12 +2199,22 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(number, six.integer_types), number headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/issues/" + str(number) + "GET", self.url + "/issues/" + str(number) ) return github.Issue.Issue(self._requester, headers, data, completed=True) - def get_issues(self, milestone=github.GithubObject.NotSet, state=github.GithubObject.NotSet, assignee=github.GithubObject.NotSet, mentioned=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet, creator=github.GithubObject.NotSet): + def get_issues( + self, + milestone=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + mentioned=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + creator=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/issues `_ :param milestone: :class:`github.Milestone.Milestone` or "none" or "*" @@ -2023,15 +2228,40 @@ class Repository(github.GithubObject.CompletableGithubObject): :param creator: string or :class:`github.NamedUser.NamedUser` :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` """ - assert milestone is github.GithubObject.NotSet or milestone == "*" or milestone == "none" or isinstance(milestone, github.Milestone.Milestone), milestone - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert assignee is github.GithubObject.NotSet or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, six.text_type)), assignee - assert mentioned is github.GithubObject.NotSet or isinstance(mentioned, github.NamedUser.NamedUser), mentioned - assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since - assert creator is github.GithubObject.NotSet or isinstance(creator, github.NamedUser.NamedUser) or isinstance(creator, (str, six.text_type)), creator + assert ( + milestone is github.GithubObject.NotSet + or milestone == "*" + or milestone == "none" + or isinstance(milestone, github.Milestone.Milestone) + ), milestone + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert ( + assignee is github.GithubObject.NotSet + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, (str, six.text_type)) + ), assignee + assert mentioned is github.GithubObject.NotSet or isinstance( + mentioned, github.NamedUser.NamedUser + ), mentioned + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) for element in labels + ), labels + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert ( + creator is github.GithubObject.NotSet + or isinstance(creator, github.NamedUser.NamedUser) + or isinstance(creator, (str, six.text_type)) + ), creator url_parameters = dict() if milestone is not github.GithubObject.NotSet: if isinstance(milestone, (str, six.text_type)): @@ -2061,13 +2291,15 @@ class Repository(github.GithubObject.CompletableGithubObject): else: url_parameters["creator"] = creator._identity return github.PaginatedList.PaginatedList( - github.Issue.Issue, - self._requester, - self.url + "/issues", - url_parameters + github.Issue.Issue, self._requester, self.url + "/issues", url_parameters ) - def get_issues_comments(self, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): + def get_issues_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/issues/comments `_ :param sort: string @@ -2075,9 +2307,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :param since: datetime.datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` """ - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if sort is not github.GithubObject.NotSet: url_parameters["sort"] = sort @@ -2089,7 +2327,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.IssueComment.IssueComment, self._requester, self.url + "/issues/comments", - url_parameters + url_parameters, ) def get_issues_event(self, id): @@ -2102,9 +2340,11 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "GET", self.url + "/issues/events/" + str(id), - headers={'Accept': Consts.mediaTypeLockReasonPreview} + headers={"Accept": Consts.mediaTypeLockReasonPreview}, + ) + return github.IssueEvent.IssueEvent( + self._requester, headers, data, completed=True ) - return github.IssueEvent.IssueEvent(self._requester, headers, data, completed=True) def get_issues_events(self): """ @@ -2116,7 +2356,7 @@ class Repository(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/issues/events", None, - headers={'Accept': Consts.mediaTypeLockReasonPreview} + headers={"Accept": Consts.mediaTypeLockReasonPreview}, ) def get_key(self, id): @@ -2127,10 +2367,11 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(id, six.integer_types), id headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/keys/" + str(id) + "GET", self.url + "/keys/" + str(id) + ) + return github.RepositoryKey.RepositoryKey( + self._requester, headers, data, completed=True ) - return github.RepositoryKey.RepositoryKey(self._requester, headers, data, completed=True) def get_keys(self): """ @@ -2141,7 +2382,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.RepositoryKey.RepositoryKey, self._requester, self.url + "/keys", - None + None, ) def get_label(self, name): @@ -2152,8 +2393,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(name, (str, six.text_type)), name headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/labels/" + six.moves.urllib.parse.quote(name) + "GET", self.url + "/labels/" + six.moves.urllib.parse.quote(name) ) return github.Label.Label(self._requester, headers, data, completed=True) @@ -2163,10 +2403,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` """ return github.PaginatedList.PaginatedList( - github.Label.Label, - self._requester, - self.url + "/labels", - None + github.Label.Label, self._requester, self.url + "/labels", None ) def get_languages(self): @@ -2175,8 +2412,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: dict of string to integer """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/languages" + "GET", self.url + "/languages" ) return data @@ -2187,10 +2423,11 @@ class Repository(github.GithubObject.CompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/license" + "GET", self.url + "/license" + ) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True ) - return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) def get_milestone(self, number): """ @@ -2200,12 +2437,18 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(number, six.integer_types), number headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/milestones/" + str(number) + "GET", self.url + "/milestones/" + str(number) + ) + return github.Milestone.Milestone( + self._requester, headers, data, completed=True ) - return github.Milestone.Milestone(self._requester, headers, data, completed=True) - def get_milestones(self, state=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet): + def get_milestones( + self, + state=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/milestones `_ :param state: string @@ -2213,9 +2456,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :param direction: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Milestone.Milestone` """ - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction url_parameters = dict() if state is not github.GithubObject.NotSet: url_parameters["state"] = state @@ -2227,7 +2476,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.Milestone.Milestone, self._requester, self.url + "/milestones", - url_parameters + url_parameters, ) def get_network_events(self): @@ -2239,7 +2488,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.Event.Event, self._requester, "/networks/" + self.owner.login + "/" + self.name + "/events", - None + None, ) def get_pull(self, number): @@ -2250,12 +2499,20 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(number, six.integer_types), number headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/pulls/" + str(number) + "GET", self.url + "/pulls/" + str(number) + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True ) - return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) - def get_pulls(self, state=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, base=github.GithubObject.NotSet, head=github.GithubObject.NotSet): + def get_pulls( + self, + state=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + base=github.GithubObject.NotSet, + head=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/pulls `_ :param state: string @@ -2265,11 +2522,21 @@ class Repository(github.GithubObject.CompletableGithubObject): :param head: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequest.PullRequest` """ - assert state is github.GithubObject.NotSet or isinstance(state, (str, six.text_type)), state - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert base is github.GithubObject.NotSet or isinstance(base, (str, six.text_type)), base - assert head is github.GithubObject.NotSet or isinstance(head, (str, six.text_type)), head + assert state is github.GithubObject.NotSet or isinstance( + state, (str, six.text_type) + ), state + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert base is github.GithubObject.NotSet or isinstance( + base, (str, six.text_type) + ), base + assert head is github.GithubObject.NotSet or isinstance( + head, (str, six.text_type) + ), head url_parameters = dict() if state is not github.GithubObject.NotSet: url_parameters["state"] = state @@ -2285,10 +2552,15 @@ class Repository(github.GithubObject.CompletableGithubObject): github.PullRequest.PullRequest, self._requester, self.url + "/pulls", - url_parameters + url_parameters, ) - def get_pulls_comments(self, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): + def get_pulls_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/pulls/comments `_ :param sort: string @@ -2298,7 +2570,12 @@ class Repository(github.GithubObject.CompletableGithubObject): """ return self.get_pulls_review_comments(sort, direction, since) - def get_pulls_review_comments(self, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): + def get_pulls_review_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/pulls/comments `_ :param sort: string @@ -2306,9 +2583,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :param since: datetime.datetime :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` """ - assert sort is github.GithubObject.NotSet or isinstance(sort, (str, six.text_type)), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, (str, six.text_type)), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert sort is github.GithubObject.NotSet or isinstance( + sort, (str, six.text_type) + ), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, (str, six.text_type) + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if sort is not github.GithubObject.NotSet: url_parameters["sort"] = sort @@ -2320,7 +2603,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.PullRequestComment.PullRequestComment, self._requester, self.url + "/pulls/comments", - url_parameters + url_parameters, ) def get_readme(self, ref=github.GithubObject.NotSet): @@ -2329,16 +2612,18 @@ class Repository(github.GithubObject.CompletableGithubObject): :param ref: string :rtype: :class:`github.ContentFile.ContentFile` """ - assert ref is github.GithubObject.NotSet or isinstance(ref, (str, six.text_type)), ref + assert ref is github.GithubObject.NotSet or isinstance( + ref, (str, six.text_type) + ), ref url_parameters = dict() if ref is not github.GithubObject.NotSet: url_parameters["ref"] = ref headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/readme", - parameters=url_parameters + "GET", self.url + "/readme", parameters=url_parameters + ) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True ) - return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) def get_source_import(self): """ @@ -2347,14 +2632,14 @@ class Repository(github.GithubObject.CompletableGithubObject): """ import_header = {"Accept": Consts.mediaTypeImportPreview} headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/import", - headers=import_header, + "GET", self.url + "/import", headers=import_header, ) if not data: return None else: - return github.SourceImport.SourceImport(self._requester, headers, data, completed=True) + return github.SourceImport.SourceImport( + self._requester, headers, data, completed=True + ) def get_stargazers(self): """ @@ -2362,10 +2647,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - self.url + "/stargazers", - None + github.NamedUser.NamedUser, self._requester, self.url + "/stargazers", None ) def get_stargazers_with_dates(self): @@ -2378,7 +2660,7 @@ class Repository(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/stargazers", None, - headers={'Accept': Consts.mediaTypeStarringPreview} + headers={"Accept": Consts.mediaTypeStarringPreview}, ) def get_stats_contributors(self): @@ -2387,14 +2669,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: None or list of :class:`github.StatsContributor.StatsContributor` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/stats/contributors" + "GET", self.url + "/stats/contributors" ) if not data: return None else: return [ - github.StatsContributor.StatsContributor(self._requester, headers, attributes, completed=True) + github.StatsContributor.StatsContributor( + self._requester, headers, attributes, completed=True + ) for attributes in data ] @@ -2404,14 +2687,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/stats/commit_activity" + "GET", self.url + "/stats/commit_activity" ) if not data: return None else: return [ - github.StatsCommitActivity.StatsCommitActivity(self._requester, headers, attributes, completed=True) + github.StatsCommitActivity.StatsCommitActivity( + self._requester, headers, attributes, completed=True + ) for attributes in data ] @@ -2421,14 +2705,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/stats/code_frequency" + "GET", self.url + "/stats/code_frequency" ) if not data: return None else: return [ - github.StatsCodeFrequency.StatsCodeFrequency(self._requester, headers, attributes, completed=True) + github.StatsCodeFrequency.StatsCodeFrequency( + self._requester, headers, attributes, completed=True + ) for attributes in data ] @@ -2438,13 +2723,14 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: None or :class:`github.StatsParticipation.StatsParticipation` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/stats/participation" + "GET", self.url + "/stats/participation" ) if not data: return None else: - return github.StatsParticipation.StatsParticipation(self._requester, headers, data, completed=True) + return github.StatsParticipation.StatsParticipation( + self._requester, headers, data, completed=True + ) def get_stats_punch_card(self): """ @@ -2452,13 +2738,14 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/stats/punch_card" + "GET", self.url + "/stats/punch_card" ) if not data: return None else: - return github.StatsPunchCard.StatsPunchCard(self._requester, headers, data, completed=True) + return github.StatsPunchCard.StatsPunchCard( + self._requester, headers, data, completed=True + ) def get_subscribers(self): """ @@ -2466,10 +2753,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - self.url + "/subscribers", - None + github.NamedUser.NamedUser, self._requester, self.url + "/subscribers", None ) def get_tags(self): @@ -2478,10 +2762,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag` """ return github.PaginatedList.PaginatedList( - github.Tag.Tag, - self._requester, - self.url + "/tags", - None + github.Tag.Tag, self._requester, self.url + "/tags", None ) def get_releases(self): @@ -2490,10 +2771,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRelease.GitRelease` """ return github.PaginatedList.PaginatedList( - github.GitRelease.GitRelease, - self._requester, - self.url + "/releases", - None + github.GitRelease.GitRelease, self._requester, self.url + "/releases", None ) def get_release(self, id): @@ -2504,16 +2782,18 @@ class Repository(github.GithubObject.CompletableGithubObject): """ if isinstance(id, int): headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/releases/" + str(id) + "GET", self.url + "/releases/" + str(id) + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True ) - return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) elif isinstance(id, (str, six.text_type)): headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/releases/tags/" + id + "GET", self.url + "/releases/tags/" + id + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True ) - return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) def get_latest_release(self): """ @@ -2521,10 +2801,11 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.GitRelease.GitRelease` """ headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/releases/latest" + "GET", self.url + "/releases/latest" + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True ) - return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) def get_teams(self): """ @@ -2532,10 +2813,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` """ return github.PaginatedList.PaginatedList( - github.Team.Team, - self._requester, - self.url + "/teams", - None + github.Team.Team, self._requester, self.url + "/teams", None ) def get_topics(self): @@ -2546,9 +2824,9 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "GET", self.url + "/topics", - headers={'Accept': Consts.mediaTypeTopicsPreview} + headers={"Accept": Consts.mediaTypeTopicsPreview}, ) - return data['names'] + return data["names"] def get_watchers(self): """ @@ -2556,10 +2834,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - self.url + "/watchers", - None + github.NamedUser.NamedUser, self._requester, self.url + "/watchers", None ) def has_in_assignees(self, assignee): @@ -2568,14 +2843,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :param assignee: string or :class:`github.NamedUser.NamedUser` :rtype: bool """ - assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, six.text_type)), assignee + assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance( + assignee, (str, six.text_type) + ), assignee if isinstance(assignee, github.NamedUser.NamedUser): assignee = assignee._identity status, headers, data = self._requester.requestJson( - "GET", - self.url + "/assignees/" + assignee + "GET", self.url + "/assignees/" + assignee ) return status == 204 @@ -2585,27 +2861,33 @@ class Repository(github.GithubObject.CompletableGithubObject): :param collaborator: string or :class:`github.NamedUser.NamedUser` :rtype: bool """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, six.text_type)), collaborator + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, (str, six.text_type) + ), collaborator if isinstance(collaborator, github.NamedUser.NamedUser): collaborator = collaborator._identity status, headers, data = self._requester.requestJson( - "GET", - self.url + "/collaborators/" + collaborator + "GET", self.url + "/collaborators/" + collaborator ) return status == 204 def _legacy_convert_issue(self, attributes): convertedAttributes = { "number": attributes["number"], - "url": "/repos" + six.moves.urllib.parse.urlparse(attributes["html_url"]).path, - "user": {"login": attributes["user"], "url": "/users/" + attributes["user"]}, + "url": "/repos" + + six.moves.urllib.parse.urlparse(attributes["html_url"]).path, + "user": { + "login": attributes["user"], + "url": "/users/" + attributes["user"], + }, } if "labels" in attributes: # pragma no branch - convertedAttributes["labels"] = [{"name": label} for label in attributes["labels"]] - for attr in ("title", "created_at", "comments", "body", "updated_at", - "state"): + convertedAttributes["labels"] = [ + {"name": label} for label in attributes["labels"] + ] + for attr in ("title", "created_at", "comments", "body", "updated_at", "state"): if attr in attributes: # pragma no branch convertedAttributes[attr] = attributes[attr] return convertedAttributes @@ -2621,14 +2903,32 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(keyword, (str, six.text_type)), keyword headers, data = self._requester.requestJsonAndCheck( "GET", - "/legacy/issues/search/" + self.owner.login + "/" + self.name + "/" + state + "/" + six.moves.urllib.parse.quote(keyword) + "/legacy/issues/search/" + + self.owner.login + + "/" + + self.name + + "/" + + state + + "/" + + six.moves.urllib.parse.quote(keyword), ) return [ - github.Issue.Issue(self._requester, headers, self._legacy_convert_issue(element), completed=False) + github.Issue.Issue( + self._requester, + headers, + self._legacy_convert_issue(element), + completed=False, + ) for element in data["issues"] ] - def get_notifications(self, all=github.GithubObject.NotSet, participating=github.GithubObject.NotSet, since=github.GithubObject.NotSet, before=github.GithubObject.NotSet): + def get_notifications( + self, + all=github.GithubObject.NotSet, + participating=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + before=github.GithubObject.NotSet, + ): """ :calls: `GET /repos/:owner/:repo/notifications `_ :param all: bool @@ -2639,9 +2939,15 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert all is github.GithubObject.NotSet or isinstance(all, bool), all - assert participating is github.GithubObject.NotSet or isinstance(participating, bool), participating - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since - assert before is github.GithubObject.NotSet or isinstance(before, datetime.datetime), before + assert participating is github.GithubObject.NotSet or isinstance( + participating, bool + ), participating + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert before is github.GithubObject.NotSet or isinstance( + before, datetime.datetime + ), before params = dict() if all is not github.GithubObject.NotSet: @@ -2657,7 +2963,7 @@ class Repository(github.GithubObject.CompletableGithubObject): github.Notification.Notification, self._requester, self.url + "/notifications", - params + params, ) def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()): @@ -2666,14 +2972,10 @@ class Repository(github.GithubObject.CompletableGithubObject): :param last_read_at: datetime """ assert isinstance(last_read_at, datetime.datetime) - put_parameters = { - "last_read_at": last_read_at.strftime('%Y-%m-%dT%H:%M:%SZ') - } + put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/notifications", - input=put_parameters + "PUT", self.url + "/notifications", input=put_parameters ) def merge(self, base, head, commit_message=github.GithubObject.NotSet): @@ -2686,7 +2988,9 @@ class Repository(github.GithubObject.CompletableGithubObject): """ assert isinstance(base, (str, six.text_type)), base assert isinstance(head, (str, six.text_type)), head - assert commit_message is github.GithubObject.NotSet or isinstance(commit_message, (str, six.text_type)), commit_message + assert commit_message is github.GithubObject.NotSet or isinstance( + commit_message, (str, six.text_type) + ), commit_message post_parameters = { "base": base, "head": head, @@ -2694,9 +2998,7 @@ class Repository(github.GithubObject.CompletableGithubObject): if commit_message is not github.GithubObject.NotSet: post_parameters["commit_message"] = commit_message headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/merges", - input=post_parameters + "POST", self.url + "/merges", input=post_parameters ) if data is None: return None @@ -2709,14 +3011,12 @@ class Repository(github.GithubObject.CompletableGithubObject): :param topics: list of strings :rtype: None """ - post_parameters = { - 'names': topics - } + post_parameters = {"names": topics} headers, data = self._requester.requestJsonAndCheck( "PUT", self.url + "/topics", - headers={'Accept': Consts.mediaTypeTopicsPreview}, - input=post_parameters + headers={"Accept": Consts.mediaTypeTopicsPreview}, + input=post_parameters, ) def get_vulnerability_alert(self): @@ -2727,7 +3027,7 @@ class Repository(github.GithubObject.CompletableGithubObject): status, _, _ = self._requester.requestJson( "GET", self.url + "/vulnerability-alerts", - headers={'Accept': Consts.vulnerabilityAlertsPreview} + headers={"Accept": Consts.vulnerabilityAlertsPreview}, ) return status == 204 @@ -2739,7 +3039,7 @@ class Repository(github.GithubObject.CompletableGithubObject): status, _, _ = self._requester.requestJson( "PUT", self.url + "/vulnerability-alerts", - headers={'Accept': Consts.vulnerabilityAlertsPreview} + headers={"Accept": Consts.vulnerabilityAlertsPreview}, ) return status == 204 @@ -2751,7 +3051,7 @@ class Repository(github.GithubObject.CompletableGithubObject): status, _, _ = self._requester.requestJson( "DELETE", self.url + "/vulnerability-alerts", - headers={'Accept': Consts.vulnerabilityAlertsPreview} + headers={"Accept": Consts.vulnerabilityAlertsPreview}, ) return status == 204 @@ -2763,7 +3063,7 @@ class Repository(github.GithubObject.CompletableGithubObject): status, _, _ = self._requester.requestJson( "PUT", self.url + "/automated-security-fixes", - headers={'Accept': Consts.automatedSecurityFixes} + headers={"Accept": Consts.automatedSecurityFixes}, ) return status == 204 @@ -2775,7 +3075,7 @@ class Repository(github.GithubObject.CompletableGithubObject): status, _, _ = self._requester.requestJson( "DELETE", self.url + "/automated-security-fixes", - headers={'Accept': Consts.automatedSecurityFixes} + headers={"Accept": Consts.automatedSecurityFixes}, ) return status == 204 @@ -2785,14 +3085,15 @@ class Repository(github.GithubObject.CompletableGithubObject): :param collaborator: string or :class:`github.NamedUser.NamedUser` :rtype: None """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, six.text_type)), collaborator + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, (str, six.text_type) + ), collaborator if isinstance(collaborator, github.NamedUser.NamedUser): collaborator = collaborator._identity headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/collaborators/" + collaborator + "DELETE", self.url + "/collaborators/" + collaborator ) def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): @@ -2819,19 +3120,21 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(mode, (str, six.text_type)), mode assert isinstance(event, (str, six.text_type)), event assert isinstance(callback, (str, six.text_type)), callback - assert secret is github.GithubObject.NotSet or isinstance(secret, (str, six.text_type)), secret + assert secret is github.GithubObject.NotSet or isinstance( + secret, (str, six.text_type) + ), secret post_parameters = collections.OrderedDict() post_parameters["hub.callback"] = callback - post_parameters["hub.topic"] = "https://github.com/" + self.full_name + "/events/" + event + post_parameters["hub.topic"] = ( + "https://github.com/" + self.full_name + "/events/" + event + ) post_parameters["hub.mode"] = mode if secret is not github.GithubObject.NotSet: post_parameters["hub.secret"] = secret headers, output = self._requester.requestMultipartAndCheck( - "POST", - "/hub", - input=post_parameters + "POST", "/hub", input=post_parameters ) @property @@ -2842,10 +3145,11 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(id, (int)), id resp_headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/releases/assets/" + str(id) + "GET", self.url + "/releases/assets/" + str(id) + ) + return github.GitReleaseAsset.GitReleaseAsset( + self._requester, resp_headers, data, completed=True ) - return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True) def _initAttributes(self): self._allow_merge_commit = github.GithubObject.NotSet @@ -2929,11 +3233,17 @@ class Repository(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "allow_merge_commit" in attributes: # pragma no branch - self._allow_merge_commit = self._makeBoolAttribute(attributes["allow_merge_commit"]) + self._allow_merge_commit = self._makeBoolAttribute( + attributes["allow_merge_commit"] + ) if "allow_rebase_merge" in attributes: # pragma no branch - self._allow_rebase_merge = self._makeBoolAttribute(attributes["allow_rebase_merge"]) + self._allow_rebase_merge = self._makeBoolAttribute( + attributes["allow_rebase_merge"] + ) if "allow_squash_merge" in attributes: # pragma no branch - self._allow_squash_merge = self._makeBoolAttribute(attributes["allow_squash_merge"]) + self._allow_squash_merge = self._makeBoolAttribute( + attributes["allow_squash_merge"] + ) if "archived" in attributes: # pragma no branch self._archived = self._makeBoolAttribute(attributes["archived"]) if "archive_url" in attributes: # pragma no branch @@ -2947,7 +3257,9 @@ class Repository(github.GithubObject.CompletableGithubObject): if "clone_url" in attributes: # pragma no branch self._clone_url = self._makeStringAttribute(attributes["clone_url"]) if "collaborators_url" in attributes: # pragma no branch - self._collaborators_url = self._makeStringAttribute(attributes["collaborators_url"]) + self._collaborators_url = self._makeStringAttribute( + attributes["collaborators_url"] + ) if "comments_url" in attributes: # pragma no branch self._comments_url = self._makeStringAttribute(attributes["comments_url"]) if "commits_url" in attributes: # pragma no branch @@ -2957,11 +3269,15 @@ class Repository(github.GithubObject.CompletableGithubObject): if "contents_url" in attributes: # pragma no branch self._contents_url = self._makeStringAttribute(attributes["contents_url"]) if "contributors_url" in attributes: # pragma no branch - self._contributors_url = self._makeStringAttribute(attributes["contributors_url"]) + self._contributors_url = self._makeStringAttribute( + attributes["contributors_url"] + ) if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "default_branch" in attributes: # pragma no branch - self._default_branch = self._makeStringAttribute(attributes["default_branch"]) + self._default_branch = self._makeStringAttribute( + attributes["default_branch"] + ) if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "downloads_url" in attributes: # pragma no branch @@ -2979,7 +3295,9 @@ class Repository(github.GithubObject.CompletableGithubObject): if "full_name" in attributes: # pragma no branch self._full_name = self._makeStringAttribute(attributes["full_name"]) if "git_commits_url" in attributes: # pragma no branch - self._git_commits_url = self._makeStringAttribute(attributes["git_commits_url"]) + self._git_commits_url = self._makeStringAttribute( + attributes["git_commits_url"] + ) if "git_refs_url" in attributes: # pragma no branch self._git_refs_url = self._makeStringAttribute(attributes["git_refs_url"]) if "git_tags_url" in attributes: # pragma no branch @@ -3003,9 +3321,13 @@ class Repository(github.GithubObject.CompletableGithubObject): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "issue_comment_url" in attributes: # pragma no branch - self._issue_comment_url = self._makeStringAttribute(attributes["issue_comment_url"]) + self._issue_comment_url = self._makeStringAttribute( + attributes["issue_comment_url"] + ) if "issue_events_url" in attributes: # pragma no branch - self._issue_events_url = self._makeStringAttribute(attributes["issue_events_url"]) + self._issue_events_url = self._makeStringAttribute( + attributes["issue_events_url"] + ) if "issues_url" in attributes: # pragma no branch self._issues_url = self._makeStringAttribute(attributes["issues_url"]) if "keys_url" in attributes: # pragma no branch @@ -3021,7 +3343,9 @@ class Repository(github.GithubObject.CompletableGithubObject): if "merges_url" in attributes: # pragma no branch self._merges_url = self._makeStringAttribute(attributes["merges_url"]) if "milestones_url" in attributes: # pragma no branch - self._milestones_url = self._makeStringAttribute(attributes["milestones_url"]) + self._milestones_url = self._makeStringAttribute( + attributes["milestones_url"] + ) if "mirror_url" in attributes: # pragma no branch self._mirror_url = self._makeStringAttribute(attributes["mirror_url"]) if "name" in attributes: # pragma no branch @@ -3029,19 +3353,29 @@ class Repository(github.GithubObject.CompletableGithubObject): if "network_count" in attributes: # pragma no branch self._network_count = self._makeIntAttribute(attributes["network_count"]) if "notifications_url" in attributes: # pragma no branch - self._notifications_url = self._makeStringAttribute(attributes["notifications_url"]) + self._notifications_url = self._makeStringAttribute( + attributes["notifications_url"] + ) if "open_issues" in attributes: # pragma no branch self._open_issues = self._makeIntAttribute(attributes["open_issues"]) if "open_issues_count" in attributes: # pragma no branch - self._open_issues_count = self._makeIntAttribute(attributes["open_issues_count"]) + self._open_issues_count = self._makeIntAttribute( + attributes["open_issues_count"] + ) if "organization" in attributes: # pragma no branch - self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"]) + self._organization = self._makeClassAttribute( + github.Organization.Organization, attributes["organization"] + ) if "owner" in attributes: # pragma no branch - self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"]) + self._owner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["owner"] + ) if "parent" in attributes: # pragma no branch self._parent = self._makeClassAttribute(Repository, attributes["parent"]) if "permissions" in attributes: # pragma no branch - self._permissions = self._makeClassAttribute(github.Permissions.Permissions, attributes["permissions"]) + self._permissions = self._makeClassAttribute( + github.Permissions.Permissions, attributes["permissions"] + ) if "private" in attributes: # pragma no branch self._private = self._makeBoolAttribute(attributes["private"]) if "pulls_url" in attributes: # pragma no branch @@ -3055,17 +3389,27 @@ class Repository(github.GithubObject.CompletableGithubObject): if "ssh_url" in attributes: # pragma no branch self._ssh_url = self._makeStringAttribute(attributes["ssh_url"]) if "stargazers_count" in attributes: # pragma no branch - self._stargazers_count = self._makeIntAttribute(attributes["stargazers_count"]) + self._stargazers_count = self._makeIntAttribute( + attributes["stargazers_count"] + ) if "stargazers_url" in attributes: # pragma no branch - self._stargazers_url = self._makeStringAttribute(attributes["stargazers_url"]) + self._stargazers_url = self._makeStringAttribute( + attributes["stargazers_url"] + ) if "statuses_url" in attributes: # pragma no branch self._statuses_url = self._makeStringAttribute(attributes["statuses_url"]) if "subscribers_url" in attributes: # pragma no branch - self._subscribers_url = self._makeStringAttribute(attributes["subscribers_url"]) + self._subscribers_url = self._makeStringAttribute( + attributes["subscribers_url"] + ) if "subscribers_count" in attributes: # pragma no branch - self._subscribers_count = self._makeIntAttribute(attributes["subscribers_count"]) + self._subscribers_count = self._makeIntAttribute( + attributes["subscribers_count"] + ) if "subscription_url" in attributes: # pragma no branch - self._subscription_url = self._makeStringAttribute(attributes["subscription_url"]) + self._subscription_url = self._makeStringAttribute( + attributes["subscription_url"] + ) if "svn_url" in attributes: # pragma no branch self._svn_url = self._makeStringAttribute(attributes["svn_url"]) if "tags_url" in attributes: # pragma no branch diff --git a/github/RepositoryKey.py b/github/RepositoryKey.py index a1de7d61..7ec47e49 100644 --- a/github/RepositoryKey.py +++ b/github/RepositoryKey.py @@ -36,6 +36,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -108,10 +109,7 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): :calls: `DELETE /repos/:owner/:repo/keys/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def _initAttributes(self): self._created_at = github.GithubObject.NotSet diff --git a/github/Requester.py b/github/Requester.py index 1ac87768..7e5a93a6 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -53,20 +53,21 @@ ################################################################################ from __future__ import absolute_import + import base64 import json import logging import mimetypes import os import re -import requests import time -import six.moves.urllib.parse from io import IOBase -from . import Consts -from . import GithubException +import requests import six +import six.moves.urllib.parse + +from . import Consts, GithubException class RequestsResponse: @@ -85,7 +86,9 @@ class RequestsResponse: class HTTPSRequestsConnectionClass(object): # mimic the httplib connection object - def __init__(self, host, port=None, strict=False, timeout=None, retry=None, **kwargs): + def __init__( + self, host, port=None, strict=False, timeout=None, retry=None, **kwargs + ): self.port = port if port else 443 self.host = host self.protocol = "https" @@ -96,7 +99,7 @@ class HTTPSRequestsConnectionClass(object): if retry: self.retry = retry self.adapter = requests.adapters.HTTPAdapter(max_retries=self.retry) - self.session.mount('https://', self.adapter) + self.session.mount("https://", self.adapter) def request(self, verb, url, input, headers): self.verb = verb @@ -107,7 +110,14 @@ class HTTPSRequestsConnectionClass(object): def getresponse(self): verb = getattr(self.session, self.verb.lower()) url = "%s://%s:%s%s" % (self.protocol, self.host, self.port, self.url) - r = verb(url, headers=self.headers, data=self.input, timeout=self.timeout, verify=self.verify, allow_redirects=False) + r = verb( + url, + headers=self.headers, + data=self.input, + timeout=self.timeout, + verify=self.verify, + allow_redirects=False, + ) return RequestsResponse(r) def close(self): @@ -116,7 +126,9 @@ class HTTPSRequestsConnectionClass(object): class HTTPRequestsConnectionClass(object): # mimic the httplib connection object - def __init__(self, host, port=None, strict=False, timeout=None, retry=None, **kwargs): + def __init__( + self, host, port=None, strict=False, timeout=None, retry=None, **kwargs + ): self.port = port if port else 80 self.host = host self.protocol = "http" @@ -127,7 +139,7 @@ class HTTPRequestsConnectionClass(object): if retry: self.retry = retry self.adapter = requests.adapters.HTTPAdapter(max_retries=self.retry) - self.session.mount('http://', self.adapter) + self.session.mount("http://", self.adapter) def request(self, verb, url, input, headers): self.verb = verb @@ -138,7 +150,14 @@ class HTTPRequestsConnectionClass(object): def getresponse(self): verb = getattr(self.session, self.verb.lower()) url = "%s://%s:%s%s" % (self.protocol, self.host, self.port, self.url) - r = verb(url, headers=self.headers, data=self.input, timeout=self.timeout, verify=self.verify, allow_redirects=False) + r = verb( + url, + headers=self.headers, + data=self.input, + timeout=self.timeout, + verify=self.verify, + allow_redirects=False, + ) return RequestsResponse(r) def close(self): @@ -190,7 +209,9 @@ class Requester: """ if self.DEBUG_FLAG: # pragma no branch (Flag always set in tests) new_frame = [requestHeader, None, None, None] - if self._frameCount < self.DEBUG_FRAME_BUFFER_SIZE - 1: # pragma no branch (Should be covered) + if ( + self._frameCount < self.DEBUG_FRAME_BUFFER_SIZE - 1 + ): # pragma no branch (Should be covered) self._frameBuffer.append(new_frame) else: self._frameBuffer[0] = new_frame # pragma no cover (Should be covered) @@ -198,16 +219,22 @@ class Requester: self._frameCount = len(self._frameBuffer) - 1 def DEBUG_ON_RESPONSE(self, statusCode, responseHeader, data): - ''' + """ Update current frame with response Current frame index will be attached to responseHeader - ''' + """ if self.DEBUG_FLAG: # pragma no branch (Flag always set in tests) - self._frameBuffer[self._frameCount][1:4] = [statusCode, responseHeader, data] + self._frameBuffer[self._frameCount][1:4] = [ + statusCode, + responseHeader, + data, + ] responseHeader[self.DEBUG_HEADER_KEY] = self._frameCount def check_me(self, obj): - if self.DEBUG_FLAG and self.ON_CHECK_ME is not None: # pragma no branch (Flag always set in tests) + if ( + self.DEBUG_FLAG and self.ON_CHECK_ME is not None + ): # pragma no branch (Flag always set in tests) frame = None if self.DEBUG_HEADER_KEY in obj._headers: frame_index = obj._headers[self.DEBUG_HEADER_KEY] @@ -220,12 +247,28 @@ class Requester: ############################################################# - def __init__(self, login_or_token, password, jwt, base_url, timeout, client_id, client_secret, user_agent, per_page, api_preview, verify, retry): + def __init__( + self, + login_or_token, + password, + jwt, + base_url, + timeout, + client_id, + client_secret, + user_agent, + per_page, + api_preview, + verify, + retry, + ): self._initializeDebugFeature() if password is not None: login = login_or_token - self.__authorizationHeader = "Basic " + base64.b64encode((login + ":" + password).encode("utf-8")).decode("utf-8").replace('\n', '') + self.__authorizationHeader = "Basic " + base64.b64encode( + (login + ":" + password).encode("utf-8") + ).decode("utf-8").replace("\n", "") elif login_or_token is not None: token = login_or_token self.__authorizationHeader = "token " + token @@ -258,20 +301,36 @@ class Requester: self.__clientId = client_id self.__clientSecret = client_secret - assert user_agent is not None, 'github now requires a user-agent. ' \ - 'See http://developer.github.com/v3/#user-agent-required' + assert user_agent is not None, ( + "github now requires a user-agent. " + "See http://developer.github.com/v3/#user-agent-required" + ) self.__userAgent = user_agent self.__apiPreview = api_preview self.__verify = verify def requestJsonAndCheck(self, verb, url, parameters=None, headers=None, input=None): - return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url))) + return self.__check( + *self.requestJson( + verb, url, parameters, headers, input, self.__customConnection(url) + ) + ) - def requestMultipartAndCheck(self, verb, url, parameters=None, headers=None, input=None): - return self.__check(*self.requestMultipart(verb, url, parameters, headers, input, self.__customConnection(url))) + def requestMultipartAndCheck( + self, verb, url, parameters=None, headers=None, input=None + ): + return self.__check( + *self.requestMultipart( + verb, url, parameters, headers, input, self.__customConnection(url) + ) + ) def requestBlobAndCheck(self, verb, url, parameters=None, headers=None, input=None): - return self.__check(*self.requestBlob(verb, url, parameters, headers, input, self.__customConnection(url))) + return self.__check( + *self.requestBlob( + verb, url, parameters, headers, input, self.__customConnection(url) + ) + ) def __check(self, status, responseHeaders, output): output = self.__structuredFromJson(output) @@ -283,25 +342,42 @@ class Requester: cnx = None if not url.startswith("/"): o = six.moves.urllib.parse.urlparse(url) - if o.hostname != self.__hostname or \ - (o.port and o.port != self.__port) or \ - (o.scheme != self.__scheme and not (o.scheme == "https" and self.__scheme == "http")): # issue80 - if o.scheme == 'http': - cnx = self.__httpConnectionClass(o.hostname, o.port, retry=self.__retry) - elif o.scheme == 'https': - cnx = self.__httpsConnectionClass(o.hostname, o.port, retry=self.__retry) + if ( + o.hostname != self.__hostname + or (o.port and o.port != self.__port) + or ( + o.scheme != self.__scheme + and not (o.scheme == "https" and self.__scheme == "http") + ) + ): # issue80 + if o.scheme == "http": + cnx = self.__httpConnectionClass( + o.hostname, o.port, retry=self.__retry + ) + elif o.scheme == "https": + cnx = self.__httpsConnectionClass( + o.hostname, o.port, retry=self.__retry + ) return cnx def __createException(self, status, headers, output): if status == 401 and output.get("message") == "Bad credentials": cls = GithubException.BadCredentialsException - elif status == 401 and Consts.headerOTP in headers and re.match(r'.*required.*', headers[Consts.headerOTP]): + elif ( + status == 401 + and Consts.headerOTP in headers + and re.match(r".*required.*", headers[Consts.headerOTP]) + ): cls = GithubException.TwoFactorException - elif status == 403 and output.get("message").startswith("Missing or invalid User Agent string"): + elif status == 403 and output.get("message").startswith( + "Missing or invalid User Agent string" + ): cls = GithubException.BadUserAgentException elif status == 403 and ( output.get("message").lower().startswith("api rate limit exceeded") - or output.get("message").lower().endswith("please wait a few minutes before you try again.") + or output.get("message") + .lower() + .endswith("please wait a few minutes before you try again.") ): cls = GithubException.RateLimitExceededException elif status == 404 and output.get("message") == "Not Found": @@ -319,15 +395,19 @@ class Requester: try: return json.loads(data) except ValueError: - return {'data': data} + return {"data": data} - def requestJson(self, verb, url, parameters=None, headers=None, input=None, cnx=None): + def requestJson( + self, verb, url, parameters=None, headers=None, input=None, cnx=None + ): def encode(input): return "application/json", json.dumps(input) return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode) - def requestMultipart(self, verb, url, parameters=None, headers=None, input=None, cnx=None): + def requestMultipart( + self, verb, url, parameters=None, headers=None, input=None, cnx=None + ): def encode(input): boundary = "----------------------------3c3ba8b523b2" eol = "\r\n" @@ -335,7 +415,9 @@ class Requester: encoded_input = "" for name, value in six.iteritems(input): encoded_input += "--" + boundary + eol - encoded_input += "Content-Disposition: form-data; name=\"" + name + "\"" + eol + encoded_input += ( + 'Content-Disposition: form-data; name="' + name + '"' + eol + ) encoded_input += eol encoded_input += value + eol encoded_input += "--" + boundary + "--" + eol @@ -349,15 +431,21 @@ class Requester: mime_type = headers["Content-Type"] else: guessed_type = mimetypes.guess_type(input) - mime_type = guessed_type[0] if guessed_type[0] is not None else Consts.defaultMediaType - f = open(local_path, 'rb') + mime_type = ( + guessed_type[0] + if guessed_type[0] is not None + else Consts.defaultMediaType + ) + f = open(local_path, "rb") return mime_type, f if input: headers["Content-Length"] = str(os.path.getsize(input)) return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode) - def __requestEncode(self, cnx, verb, url, parameters, requestHeaders, input, encode): + def __requestEncode( + self, cnx, verb, url, parameters, requestHeaders, input, encode + ): assert verb in ["HEAD", "GET", "POST", "PATCH", "PUT", "DELETE"] if parameters is None: parameters = dict() @@ -378,10 +466,18 @@ class Requester: self.NEW_DEBUG_FRAME(requestHeaders) - status, responseHeaders, output = self.__requestRaw(cnx, verb, url, requestHeaders, encoded_input) + status, responseHeaders, output = self.__requestRaw( + cnx, verb, url, requestHeaders, encoded_input + ) - if Consts.headerRateRemaining in responseHeaders and Consts.headerRateLimit in responseHeaders: - self.rate_limiting = (int(responseHeaders[Consts.headerRateRemaining]), int(responseHeaders[Consts.headerRateLimit])) + if ( + Consts.headerRateRemaining in responseHeaders + and Consts.headerRateLimit in responseHeaders + ): + self.rate_limiting = ( + int(responseHeaders[Consts.headerRateRemaining]), + int(responseHeaders[Consts.headerRateLimit]), + ) if Consts.headerRateReset in responseHeaders: self.rate_limiting_resettime = int(responseHeaders[Consts.headerRateReset]) @@ -396,12 +492,7 @@ class Requester: original_cnx = cnx if cnx is None: cnx = self.__createConnection() - cnx.request( - verb, - url, - input, - requestHeaders - ) + cnx.request(verb, url, input, requestHeaders) response = cnx.getresponse() status = response.status @@ -415,12 +506,14 @@ class Requester: self.__log(verb, url, requestHeaders, input, status, responseHeaders, output) - if status == 202 and (verb == 'GET' or verb == 'HEAD'): # only for requests that are considered 'safe' in RFC 2616 + if status == 202 and ( + verb == "GET" or verb == "HEAD" + ): # only for requests that are considered 'safe' in RFC 2616 time.sleep(Consts.PROCESSING_202_WAIT_TIME) return self.__requestRaw(original_cnx, verb, url, requestHeaders, input) - if status == 301 and 'location' in responseHeaders: - o = six.moves.urllib.parse.urlparse(responseHeaders['location']) + if status == 301 and "location" in responseHeaders: + o = six.moves.urllib.parse.urlparse(responseHeaders["location"]) return self.__requestRaw(original_cnx, verb, o.path, requestHeaders, input) return status, responseHeaders, output @@ -439,7 +532,11 @@ class Requester: url = self.__prefix + url else: o = six.moves.urllib.parse.urlparse(url) - assert o.hostname in [self.__hostname, "uploads.github.com", "status.github.com"], o.hostname + assert o.hostname in [ + self.__hostname, + "uploads.github.com", + "status.github.com", + ], o.hostname assert o.path.startswith((self.__prefix, "/api/")) assert o.port == self.__port url = o.path @@ -461,7 +558,9 @@ class Requester: if self.__persist and self.__connection is not None: return self.__connection - self.__connection = self.__connectionClass(self.__hostname, self.__port, retry=self.__retry, **kwds) + self.__connection = self.__connectionClass( + self.__hostname, self.__port, retry=self.__retry, **kwds + ) return self.__connection @@ -470,11 +569,26 @@ class Requester: if logger.isEnabledFor(logging.DEBUG): if "Authorization" in requestHeaders: if requestHeaders["Authorization"].startswith("Basic"): - requestHeaders["Authorization"] = "Basic (login and password removed)" + requestHeaders[ + "Authorization" + ] = "Basic (login and password removed)" elif requestHeaders["Authorization"].startswith("token"): requestHeaders["Authorization"] = "token (oauth token removed)" elif requestHeaders["Authorization"].startswith("Bearer"): requestHeaders["Authorization"] = "Bearer (jwt removed)" else: # pragma no cover (Cannot happen, but could if we add an authentication method => be prepared) - requestHeaders["Authorization"] = "(unknown auth removed)" # pragma no cover (Cannot happen, but could if we add an authentication method => be prepared) - logger.debug("%s %s://%s%s %s %s ==> %i %s %s", verb, self.__scheme, self.__hostname, url, requestHeaders, input, status, responseHeaders, output) + requestHeaders[ + "Authorization" + ] = "(unknown auth removed)" # pragma no cover (Cannot happen, but could if we add an authentication method => be prepared) + logger.debug( + "%s %s://%s%s %s %s ==> %i %s %s", + verb, + self.__scheme, + self.__hostname, + url, + requestHeaders, + input, + status, + responseHeaders, + output, + ) diff --git a/github/RequiredPullRequestReviews.py b/github/RequiredPullRequestReviews.py index 0ffbfa54..daaf2483 100644 --- a/github/RequiredPullRequestReviews.py +++ b/github/RequiredPullRequestReviews.py @@ -23,8 +23,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser import github.Team @@ -35,7 +35,13 @@ class RequiredPullRequestReviews(github.GithubObject.CompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"url": self._url.value, "dismiss_stale_reviews": self._dismiss_stale_reviews.value, "require_code_owner_reviews": self._require_code_owner_reviews.value}) + return self.get__repr__( + { + "url": self._url.value, + "dismiss_stale_reviews": self._dismiss_stale_reviews.value, + "require_code_owner_reviews": self._require_code_owner_reviews.value, + } + ) @property def dismiss_stale_reviews(self): @@ -95,14 +101,25 @@ class RequiredPullRequestReviews(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "dismissal_restrictions" in attributes: # pragma no branch if "users" in attributes["dismissal_restrictions"]: - self._users = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, attributes["dismissal_restrictions"]["users"]) + self._users = self._makeListOfClassesAttribute( + github.NamedUser.NamedUser, + attributes["dismissal_restrictions"]["users"], + ) if "teams" in attributes["dismissal_restrictions"]: # pragma no branch - self._teams = self._makeListOfClassesAttribute(github.Team.Team, attributes["dismissal_restrictions"]["teams"]) + self._teams = self._makeListOfClassesAttribute( + github.Team.Team, attributes["dismissal_restrictions"]["teams"] + ) if "dismiss_stale_reviews" in attributes: # pragma no branch - self._dismiss_stale_reviews = self._makeBoolAttribute(attributes["dismiss_stale_reviews"]) + self._dismiss_stale_reviews = self._makeBoolAttribute( + attributes["dismiss_stale_reviews"] + ) if "require_code_owner_reviews" in attributes: # pragma no branch - self._require_code_owner_reviews = self._makeBoolAttribute(attributes["require_code_owner_reviews"]) + self._require_code_owner_reviews = self._makeBoolAttribute( + attributes["require_code_owner_reviews"] + ) if "required_approving_review_count" in attributes: # pragma no branch - self._required_approving_review_count = self._makeIntAttribute(attributes["required_approving_review_count"]) + self._required_approving_review_count = self._makeIntAttribute( + attributes["required_approving_review_count"] + ) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) diff --git a/github/RequiredStatusChecks.py b/github/RequiredStatusChecks.py index 24be0c0f..94d74a48 100644 --- a/github/RequiredStatusChecks.py +++ b/github/RequiredStatusChecks.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/SourceImport.py b/github/SourceImport.py index 910e25bb..2eef55e9 100644 --- a/github/SourceImport.py +++ b/github/SourceImport.py @@ -23,8 +23,9 @@ ################################################################################ from __future__ import absolute_import -from github import Consts + import github.GithubObject +from github import Consts class SourceImport(github.GithubObject.CompletableGithubObject): @@ -33,12 +34,14 @@ class SourceImport(github.GithubObject.CompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "vcs_url": self._vcs_url.value, - "repository_url": self._repository_url.value, - "status": self._status.value, - "url": self._url.value - }) + return self.get__repr__( + { + "vcs_url": self._vcs_url.value, + "repository_url": self._repository_url.value, + "status": self._status.value, + "url": self._url.value, + } + ) @property def authors_count(self): @@ -169,15 +172,23 @@ class SourceImport(github.GithubObject.CompletableGithubObject): if "authors_url" in attributes: # pragma no branch self._authors_url = self._makeStringAttribute(attributes["authors_url"]) if "has_large_files" in attributes: # pragma no branch - self._has_large_files = self._makeBoolAttribute(attributes["has_large_files"]) + self._has_large_files = self._makeBoolAttribute( + attributes["has_large_files"] + ) if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "large_files_count" in attributes: # pragma no branch - self._large_files_count = self._makeIntAttribute(attributes["large_files_count"]) + self._large_files_count = self._makeIntAttribute( + attributes["large_files_count"] + ) if "large_files_size" in attributes: # pragma no branch - self._large_files_size = self._makeIntAttribute(attributes["large_files_size"]) + self._large_files_size = self._makeIntAttribute( + attributes["large_files_size"] + ) if "repository_url" in attributes: # pragma no branch - self._repository_url = self._makeStringAttribute(attributes["repository_url"]) + self._repository_url = self._makeStringAttribute( + attributes["repository_url"] + ) if "status" in attributes: # pragma no branch self._status = self._makeStringAttribute(attributes["status"]) if "status_text" in attributes: # pragma no branch diff --git a/github/Stargazer.py b/github/Stargazer.py index add2423f..3982caf9 100644 --- a/github/Stargazer.py +++ b/github/Stargazer.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github @@ -58,7 +59,9 @@ class Stargazer(github.GithubObject.NonCompletableGithubObject): self._url = github.GithubObject.NotSet def _useAttributes(self, attributes): - if 'starred_at' in attributes: - self._starred_at = self._makeDatetimeAttribute(attributes['starred_at']) - if 'user' in attributes: - self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes['user']) + if "starred_at" in attributes: + self._starred_at = self._makeDatetimeAttribute(attributes["starred_at"]) + if "user" in attributes: + self._user = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["user"] + ) diff --git a/github/StatsCodeFrequency.py b/github/StatsCodeFrequency.py index 5f6b42aa..ab41868a 100755 --- a/github/StatsCodeFrequency.py +++ b/github/StatsCodeFrequency.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/StatsCommitActivity.py b/github/StatsCommitActivity.py index a8e39714..714e94f8 100755 --- a/github/StatsCommitActivity.py +++ b/github/StatsCommitActivity.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/StatsContributor.py b/github/StatsContributor.py index f21980b8..0bbb248b 100755 --- a/github/StatsContributor.py +++ b/github/StatsContributor.py @@ -27,8 +27,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser @@ -114,8 +114,12 @@ class StatsContributor(github.GithubObject.NonCompletableGithubObject): def _useAttributes(self, attributes): if "author" in attributes: # pragma no branch - self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) + self._author = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["author"] + ) if "total" in attributes: # pragma no branch self._total = self._makeIntAttribute(attributes["total"]) if "weeks" in attributes: # pragma no branch - self._weeks = self._makeListOfClassesAttribute(self.Week, attributes["weeks"]) + self._weeks = self._makeListOfClassesAttribute( + self.Week, attributes["weeks"] + ) diff --git a/github/StatsParticipation.py b/github/StatsParticipation.py index 223bd6ae..60a64ceb 100755 --- a/github/StatsParticipation.py +++ b/github/StatsParticipation.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject diff --git a/github/StatsPunchCard.py b/github/StatsPunchCard.py index 58d4218f..a9742d90 100755 --- a/github/StatsPunchCard.py +++ b/github/StatsPunchCard.py @@ -27,8 +27,8 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject +import github.GithubObject import github.NamedUser # TODO remove unused diff --git a/github/Tag.py b/github/Tag.py index 0315dc24..1f60de70 100644 --- a/github/Tag.py +++ b/github/Tag.py @@ -32,9 +32,9 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject import github.Commit +import github.GithubObject class Tag(github.GithubObject.NonCompletableGithubObject): @@ -43,10 +43,9 @@ class Tag(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "name": self._name.value, - "commit": self._commit.value - }) + return self.get__repr__( + {"name": self._name.value, "commit": self._commit.value} + ) @property def commit(self): @@ -84,7 +83,9 @@ class Tag(github.GithubObject.NonCompletableGithubObject): def _useAttributes(self, attributes): if "commit" in attributes: # pragma no branch - self._commit = self._makeClassAttribute(github.Commit.Commit, attributes["commit"]) + self._commit = self._makeClassAttribute( + github.Commit.Commit, attributes["commit"] + ) if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "tarball_url" in attributes: # pragma no branch diff --git a/github/Team.py b/github/Team.py index c5691336..2ed2a1e6 100644 --- a/github/Team.py +++ b/github/Team.py @@ -42,16 +42,16 @@ ################################################################################ from __future__ import absolute_import -import github.GithubObject -import github.PaginatedList -import github.Repository +import github.GithubObject import github.NamedUser import github.Organization +import github.PaginatedList +import github.Repository import github.TeamDiscussion +import six from . import Consts -import six class Team(github.GithubObject.CompletableGithubObject): @@ -169,8 +169,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/members/" + member._identity + "PUT", self.url + "/members/" + member._identity ) def add_membership(self, member, role=github.GithubObject.NotSet): @@ -182,9 +181,10 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member assert role is github.GithubObject.NotSet or isinstance( - role, (str, six.text_type)), role + role, (str, six.text_type) + ), role if role is not github.GithubObject.NotSet: - assert role in ['member', 'maintainer'] + assert role in ["member", "maintainer"] put_parameters = { "role": role, } @@ -193,9 +193,7 @@ class Team(github.GithubObject.CompletableGithubObject): "role": "member", } headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/memberships/" + member._identity, - input=put_parameters + "PUT", self.url + "/memberships/" + member._identity, input=put_parameters ) def add_to_repos(self, repo): @@ -206,8 +204,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(repo, github.Repository.Repository), repo headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/repos/" + repo._identity + "PUT", self.url + "/repos/" + repo._identity ) def set_repo_permission(self, repo, permission): @@ -222,9 +219,7 @@ class Team(github.GithubObject.CompletableGithubObject): "permission": permission, } headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/repos/" + repo._identity, - input=put_parameters + "PUT", self.url + "/repos/" + repo._identity, input=put_parameters ) def delete(self): @@ -232,12 +227,15 @@ class Team(github.GithubObject.CompletableGithubObject): :calls: `DELETE /teams/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, name, description=github.GithubObject.NotSet, permission=github.GithubObject.NotSet, privacy=github.GithubObject.NotSet): + def edit( + self, + name, + description=github.GithubObject.NotSet, + permission=github.GithubObject.NotSet, + privacy=github.GithubObject.NotSet, + ): """ :calls: `PATCH /teams/:id `_ :param name: string @@ -247,9 +245,15 @@ class Team(github.GithubObject.CompletableGithubObject): :rtype: None """ assert isinstance(name, (str, six.text_type)), name - assert description is github.GithubObject.NotSet or isinstance(description, (str, six.text_type)), description - assert permission is github.GithubObject.NotSet or isinstance(permission, (str, six.text_type)), permission - assert privacy is github.GithubObject.NotSet or isinstance(privacy, (str, six.text_type)), privacy + assert description is github.GithubObject.NotSet or isinstance( + description, (str, six.text_type) + ), description + assert permission is github.GithubObject.NotSet or isinstance( + permission, (str, six.text_type) + ), permission + assert privacy is github.GithubObject.NotSet or isinstance( + privacy, (str, six.text_type) + ), privacy post_parameters = { "name": name, } @@ -260,9 +264,7 @@ class Team(github.GithubObject.CompletableGithubObject): if privacy is not github.GithubObject.NotSet: post_parameters["privacy"] = privacy headers, data = self._requester.requestJsonAndCheck( - "PATCH", - self.url, - input=post_parameters + "PATCH", self.url, input=post_parameters ) self._useAttributes(data) @@ -276,9 +278,7 @@ class Team(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/discussions", None, - headers={ - "Accept": Consts.mediaTypeTeamDiscussionsPreview - } + headers={"Accept": Consts.mediaTypeTeamDiscussionsPreview}, ) def get_members(self, role=github.GithubObject.NotSet): @@ -287,16 +287,18 @@ class Team(github.GithubObject.CompletableGithubObject): :param role: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ - assert role is github.GithubObject.NotSet or isinstance(role, (str, six.text_type)), role + assert role is github.GithubObject.NotSet or isinstance( + role, (str, six.text_type) + ), role url_parameters = dict() if role is not github.GithubObject.NotSet: - assert role in ['member', 'maintainer', 'all'] + assert role in ["member", "maintainer", "all"] url_parameters["role"] = role return github.PaginatedList.PaginatedList( github.NamedUser.NamedUser, self._requester, self.url + "/members", - url_parameters + url_parameters, ) def get_repos(self): @@ -305,10 +307,7 @@ class Team(github.GithubObject.CompletableGithubObject): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - github.Repository.Repository, - self._requester, - self.url + "/repos", - None + github.Repository.Repository, self._requester, self.url + "/repos", None ) def invitations(self): @@ -321,9 +320,7 @@ class Team(github.GithubObject.CompletableGithubObject): self._requester, self.url + "/invitations", None, - headers={ - "Accept": Consts.mediaTypeOrganizationInvitationPreview - } + headers={"Accept": Consts.mediaTypeOrganizationInvitationPreview}, ) def has_in_members(self, member): @@ -334,8 +331,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member status, headers, data = self._requester.requestJson( - "GET", - self.url + "/members/" + member._identity + "GET", self.url + "/members/" + member._identity ) return status == 204 @@ -347,8 +343,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(repo, github.Repository.Repository), repo status, headers, data = self._requester.requestJson( - "GET", - self.url + "/repos/" + repo._identity + "GET", self.url + "/repos/" + repo._identity ) return status == 204 @@ -360,8 +355,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/memberships/" + member._identity + "DELETE", self.url + "/memberships/" + member._identity ) def remove_from_members(self, member): @@ -375,8 +369,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(member, github.NamedUser.NamedUser), member headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/members/" + member._identity + "DELETE", self.url + "/members/" + member._identity ) def remove_from_repos(self, repo): @@ -387,8 +380,7 @@ class Team(github.GithubObject.CompletableGithubObject): """ assert isinstance(repo, github.Repository.Repository), repo headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/repos/" + repo._identity + "DELETE", self.url + "/repos/" + repo._identity ) @property @@ -425,12 +417,16 @@ class Team(github.GithubObject.CompletableGithubObject): if "repos_count" in attributes: # pragma no branch self._repos_count = self._makeIntAttribute(attributes["repos_count"]) if "repositories_url" in attributes: # pragma no branch - self._repositories_url = self._makeStringAttribute(attributes["repositories_url"]) + self._repositories_url = self._makeStringAttribute( + attributes["repositories_url"] + ) if "slug" in attributes: # pragma no branch self._slug = self._makeStringAttribute(attributes["slug"]) if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "organization" in attributes: # pragma no branch - self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"]) + self._organization = self._makeClassAttribute( + github.Organization.Organization, attributes["organization"] + ) if "privacy" in attributes: # pragma no branch self._privacy = self._makeStringAttribute(attributes["privacy"]) diff --git a/github/TeamDiscussion.py b/github/TeamDiscussion.py index 872f1a53..cd1ddf4f 100644 --- a/github/TeamDiscussion.py +++ b/github/TeamDiscussion.py @@ -34,7 +34,9 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject): """ def __repr__(self): - return self.get__repr__({"number": self._number.value, "title": self._title.value}) + return self.get__repr__( + {"number": self._number.value, "title": self._title.value} + ) @property def author(self): @@ -193,7 +195,9 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject): def _useAttributes(self, attributes): if "author" in attributes: # pragma no branch - self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) + self._author = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["author"] + ) if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "body_html" in attributes: # pragma no branch @@ -209,7 +213,9 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject): if "html_url" in attributes: # pragma no branch self._html_url = self._makeStringAttribute(attributes["html_url"]) if "last_edited_at" in attributes: # pragma no branch - self._last_edited_at = self._makeDatetimeAttribute(attributes["last_edited_at"]) + self._last_edited_at = self._makeDatetimeAttribute( + attributes["last_edited_at"] + ) if "node_id" in attributes: # pragma no branch self._node_id = self._makeStringAttribute(attributes["node_id"]) if "number" in attributes: # pragma no branch diff --git a/github/Topic.py b/github/Topic.py index 643b886b..cdee4214 100644 --- a/github/Topic.py +++ b/github/Topic.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -130,7 +131,9 @@ class Topic(github.GithubObject.NonCompletableGithubObject): if "display_name" in attributes: # pragma no branch self._display_name = self._makeStringAttribute(attributes["display_name"]) if "short_description" in attributes: # pragma no branch - self._short_description = self._makeStringAttribute(attributes["short_description"]) + self._short_description = self._makeStringAttribute( + attributes["short_description"] + ) if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "created_by" in attributes: # pragma no branch diff --git a/github/UserKey.py b/github/UserKey.py index 9f9ac594..c18a60d4 100644 --- a/github/UserKey.py +++ b/github/UserKey.py @@ -32,6 +32,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -88,10 +89,7 @@ class UserKey(github.GithubObject.CompletableGithubObject): :calls: `DELETE /user/keys/:id `_ :rtype: None """ - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url - ) + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) def _initAttributes(self): self._id = github.GithubObject.NotSet diff --git a/github/View.py b/github/View.py index f64078dd..0c7b6547 100644 --- a/github/View.py +++ b/github/View.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + import github.GithubObject @@ -37,11 +38,13 @@ class View(github.GithubObject.NonCompletableGithubObject): """ def __repr__(self): - return self.get__repr__({ - "timestamp": self._timestamp.value, - "count": self._count.value, - "uniques": self._uniques.value - }) + return self.get__repr__( + { + "timestamp": self._timestamp.value, + "count": self._count.value, + "uniques": self._uniques.value, + } + ) @property def timestamp(self): diff --git a/github/__init__.py b/github/__init__.py index 158eaed5..d6fe13e6 100644 --- a/github/__init__.py +++ b/github/__init__.py @@ -38,10 +38,20 @@ All classes inherit from :class:`github.GithubObject.GithubObject`. """ from __future__ import absolute_import + import logging from github.MainClass import Github, GithubIntegration -from .GithubException import GithubException, BadCredentialsException, UnknownObjectException, BadUserAgentException, RateLimitExceededException, BadAttributeException, TwoFactorException + +from .GithubException import ( + BadAttributeException, + BadCredentialsException, + BadUserAgentException, + GithubException, + RateLimitExceededException, + TwoFactorException, + UnknownObjectException, +) from .InputFileContent import InputFileContent from .InputGitAuthor import InputGitAuthor from .InputGitTreeElement import InputGitTreeElement diff --git a/scripts/add_attribute.py b/scripts/add_attribute.py index 6c3945e2..18ad75b7 100644 --- a/scripts/add_attribute.py +++ b/scripts/add_attribute.py @@ -29,8 +29,9 @@ ################################################################################ from __future__ import absolute_import -import sys + import os.path +import sys className, attributeName, attributeType = sys.argv[1:4] if len(sys.argv) > 4: @@ -40,11 +41,35 @@ else: types = { - "string": ("string", None, "self._makeStringAttribute(attributes[\"" + attributeName + "\"])"), - "int": ("integer", None, "self._makeIntAttribute(attributes[\"" + attributeName + "\"])"), - "bool": ("bool", None, "self._makeBoolAttribute(attributes[\"" + attributeName + "\"])"), - "datetime": ("datetime.datetime", "(str, unicode)", "self._makeDatetimeAttribute(attributes[\"" + attributeName + "\"])"), - "class": (":class:`" + attributeClassType + "`", None, "self._makeClassAttribute(" + attributeClassType + ", attributes[\"" + attributeName + "\"])"), + "string": ( + "string", + None, + 'self._makeStringAttribute(attributes["' + attributeName + '"])', + ), + "int": ( + "integer", + None, + 'self._makeIntAttribute(attributes["' + attributeName + '"])', + ), + "bool": ( + "bool", + None, + 'self._makeBoolAttribute(attributes["' + attributeName + '"])', + ), + "datetime": ( + "datetime.datetime", + "(str, unicode)", + 'self._makeDatetimeAttribute(attributes["' + attributeName + '"])', + ), + "class": ( + ":class:`" + attributeClassType + "`", + None, + "self._makeClassAttribute(" + + attributeClassType + + ', attributes["' + + attributeName + + '"])', + ), } attributeDocType, attributeAssertType, attributeValue = types[attributeType] @@ -74,15 +99,19 @@ while not added: elif line.startswith(" def "): attrName = line[8:-7] # Properties will be inserted after __repr__, but before any other function. - if attrName != "__repr__" and (attrName == "_identity" or attrName > attributeName or not isProperty): + if attrName != "__repr__" and ( + attrName == "_identity" or attrName > attributeName or not isProperty + ): if not isProperty: newLines.append(" @property") newLines.append(" def " + attributeName + "(self):") - newLines.append(" \"\"\"") + newLines.append(' """') newLines.append(" :type: " + attributeDocType) - newLines.append(" \"\"\"") + newLines.append(' """') if isCompletable: - newLines.append(" self._completeIfNotSet(self._" + attributeName + ")") + newLines.append( + " self._completeIfNotSet(self._" + attributeName + ")" + ) newLines.append(" return self._" + attributeName + ".value") newLines.append("") if isProperty: @@ -104,7 +133,9 @@ while not added: if line: attrName = line[14:-29] if not line or attrName > attributeName: - newLines.append(" self._" + attributeName + " = github.GithubObject.NotSet") + newLines.append( + " self._" + attributeName + " = github.GithubObject.NotSet" + ) added = True newLines.append(line) @@ -124,10 +155,26 @@ while not added: if line: attrName = line[12:-36] if not line or attrName > attributeName: - newLines.append(" if \"" + attributeName + "\" in attributes: # pragma no branch") + newLines.append( + ' if "' + + attributeName + + '" in attributes: # pragma no branch' + ) if attributeAssertType: - newLines.append(" assert attributes[\"" + attributeName + "\"] is None or isinstance(attributes[\"" + attributeName + "\"], " + attributeAssertType + "), attributes[\"" + attributeName + "\"]") - newLines.append(" self._" + attributeName + " = " + attributeValue) + newLines.append( + ' assert attributes["' + + attributeName + + '"] is None or isinstance(attributes["' + + attributeName + + '"], ' + + attributeAssertType + + '), attributes["' + + attributeName + + '"]' + ) + newLines.append( + " self._" + attributeName + " = " + attributeValue + ) added = True newLines.append(line) diff --git a/scripts/fix_headers.py b/scripts/fix_headers.py index bb764102..1e71479d 100755 --- a/scripts/fix_headers.py +++ b/scripts/fix_headers.py @@ -26,12 +26,11 @@ # # ################################################################################ -from __future__ import absolute_import -from __future__ import print_function +from __future__ import absolute_import, print_function + import os import subprocess - eightySharps = "#" * 80 @@ -64,7 +63,9 @@ def generateLicenseSection(filename): def listContributors(filename): contributors = set() - for line in subprocess.check_output(["git", "log", "--format=format:%ad %an <%ae>", "--date=short", "--", filename]).split("\n"): + for line in subprocess.check_output( + ["git", "log", "--format=format:%ad %an <%ae>", "--date=short", "--", filename] + ).split("\n"): year = line[0:4] name = line[11:] contributors.add((year, name)) @@ -108,7 +109,11 @@ class PythonHeader: if len(bodyLines) > 0 and bodyLines[0] != "": newLines.append("") - if "import " not in bodyLines[0] and bodyLines[0] != '"""' and not bodyLines[0].startswith("##########"): + if ( + "import " not in bodyLines[0] + and bodyLines[0] != '"""' + and not bodyLines[0].startswith("##########") + ): newLines.append("") newLines += bodyLines @@ -132,7 +137,7 @@ class StandardHeader: def findHeadersAndFiles(): - for root, dirs, files in os.walk('.', topdown=True): + for root, dirs, files in os.walk(".", topdown=True): if ".git" in dirs: dirs.remove(".git") if "developer.github.com" in dirs: diff --git a/setup.py b/setup.py index c1b88cc0..17cbfd10 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,6 @@ import textwrap import setuptools - version = "1.44.1" tests_require = [ @@ -67,7 +66,8 @@ if __name__ == "__main__": author="Vincent Jacques", author_email="vincent@vincent-jacques.net", url="http://pygithub.readthedocs.io/en/latest/", - long_description=textwrap.dedent("""\ + long_description=textwrap.dedent( + """\ (Very short) Tutorial ===================== @@ -90,7 +90,8 @@ if __name__ == "__main__": Reference documentation ======================= - See http://pygithub.readthedocs.io/en/latest/"""), + See http://pygithub.readthedocs.io/en/latest/""" + ), packages=["github"], package_data={}, classifiers=[ @@ -111,14 +112,7 @@ if __name__ == "__main__": ], test_suite="tests.AllTests", python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", - install_requires=[ - "deprecated", - "pyjwt", - "requests>=2.14.0", - "six" - ], - extras_require={ - "integrations": ["cryptography"] - }, - tests_require=tests_require + install_requires=["deprecated", "pyjwt", "requests>=2.14.0", "six"], + extras_require={"integrations": ["cryptography"]}, + tests_require=tests_require, ) diff --git a/tests/AllTests.py b/tests/AllTests.py index 3891f06b..4b83a250 100644 --- a/tests/AllTests.py +++ b/tests/AllTests.py @@ -45,20 +45,28 @@ from __future__ import absolute_import from .AuthenticatedUser import AuthenticatedUser from .Authentication import Authentication from .Authorization import Authorization +from .BadAttributes import BadAttributes from .Branch import Branch from .BranchProtection import BranchProtection from .Commit import Commit from .CommitCombinedStatus import CommitCombinedStatus from .CommitComment import CommitComment from .CommitStatus import CommitStatus +from .ConditionalRequestUpdate import ConditionalRequestUpdate +from .Connection import Connection from .ContentFile import ContentFile from .Download import Download +from .Enterprise import Enterprise +from .Equality import Equality from .Event import Event +from .Exceptions import Exceptions, SpecificExceptions +from .ExposeAllAttributes import ExposeAllAttributes from .Gist import Gist from .GistComment import GistComment from .GitBlob import GitBlob from .GitCommit import GitCommit from .Github_ import Github +from .GithubIntegration import GithubIntegration from .GitRef import GitRef from .GitRelease import Release from .GitReleaseAsset import ReleaseAsset @@ -66,51 +74,6 @@ from .GitTag import GitTag from .GitTree import GitTree from .Hook import Hook from .Issue import Issue -from .IssueComment import IssueComment -from .Reaction import Reaction -from .IssueEvent import IssueEvent -from .License import License -from .Label import Label -from .Milestone import Milestone -from .NamedUser import NamedUser -from .Markdown import Markdown -from .Notification import Notification -from .OrganizationHasInMembers import OrganizationHasInMembers -from .Organization import Organization -from .Project import Project -from .PullRequest import PullRequest -from .PullRequestComment import PullRequestComment -from .PullRequestReview import PullRequestReview -from .PullRequestFile import PullRequestFile -from .RateLimiting import RateLimiting -from .Repository import LazyRepository, Repository -from .RepositoryKey import RepositoryKey -from .RequiredPullRequestReviews import RequiredPullRequestReviews -from .RequiredStatusChecks import RequiredStatusChecks -from .SourceImport import SourceImport -from .Tag import Tag -from .Team import Team -from .Topic import Topic -from .Traffic import Traffic -from .UserKey import UserKey -from .Migration import Migration -from .GithubIntegration import GithubIntegration - -from .PaginatedList import PaginatedList -from .Exceptions import Exceptions, SpecificExceptions -from .Enterprise import Enterprise -from .Logging_ import Logging -from .RawData import RawData -from .ConditionalRequestUpdate import ConditionalRequestUpdate -from .Persistence import Persistence -from .ExposeAllAttributes import ExposeAllAttributes -from .BadAttributes import BadAttributes -from .Equality import Equality -from .Search import Search -from .Retry import Retry - -from .Connection import Connection - from .Issue33 import Issue33 from .Issue50 import Issue50 from .Issue54 import Issue54 @@ -129,13 +92,45 @@ from .Issue216 import Issue216 from .Issue278 import Issue278 from .Issue494 import Issue494 from .Issue572 import Issue572 +from .Issue823 import Issue823 from .Issue937 import Issue937 from .Issue945 import Issue945 -from .Issue823 import Issue823 - +from .IssueComment import IssueComment +from .IssueEvent import IssueEvent +from .Label import Label +from .License import License +from .Logging_ import Logging +from .Markdown import Markdown +from .Migration import Migration +from .Milestone import Milestone +from .NamedUser import NamedUser +from .Notification import Notification +from .Organization import Organization +from .OrganizationHasInMembers import OrganizationHasInMembers +from .PaginatedList import PaginatedList +from .Persistence import Persistence +from .Project import Project +from .PullRequest import PullRequest from .PullRequest1168 import PullRequest1168 from .PullRequest1169 import PullRequest1169 - +from .PullRequestComment import PullRequestComment +from .PullRequestFile import PullRequestFile +from .PullRequestReview import PullRequestReview +from .RateLimiting import RateLimiting +from .RawData import RawData +from .Reaction import Reaction +from .Repository import LazyRepository, Repository +from .RepositoryKey import RepositoryKey +from .RequiredPullRequestReviews import RequiredPullRequestReviews +from .RequiredStatusChecks import RequiredStatusChecks +from .Retry import Retry +from .Search import Search +from .SourceImport import SourceImport +from .Tag import Tag +from .Team import Team +from .Topic import Topic +from .Traffic import Traffic +from .UserKey import UserKey __all__ = [ AuthenticatedUser, diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index 2b2de785..9137b30c 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -33,10 +33,12 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + +import datetime import github -import datetime + +from . import Framework class AuthenticatedUser(Framework.TestCase): @@ -45,7 +47,10 @@ class AuthenticatedUser(Framework.TestCase): self.user = self.g.get_user() def testAttributes(self): - self.assertEqual(self.user.avatar_url, "https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png") + self.assertEqual( + self.user.avatar_url, + "https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + ) self.assertEqual(self.user.bio, "") self.assertEqual(self.user.blog, "http://vincent-jacques.net") self.assertEqual(self.user.collaborators, 0) @@ -82,7 +87,15 @@ class AuthenticatedUser(Framework.TestCase): self.user.edit() def testEditWithAllArguments(self): - self.user.edit("Name edited by PyGithub", "Email edited by PyGithub", "Blog edited by PyGithub", "Company edited by PyGithub", "Location edited by PyGithub", True, "Bio edited by PyGithub") + self.user.edit( + "Name edited by PyGithub", + "Email edited by PyGithub", + "Blog edited by PyGithub", + "Company edited by PyGithub", + "Location edited by PyGithub", + True, + "Bio edited by PyGithub", + ) self.assertEqual(self.user.name, "Name edited by PyGithub") self.assertEqual(self.user.email, "Email edited by PyGithub") self.assertEqual(self.user.blog, "Blog edited by PyGithub") @@ -92,25 +105,125 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(self.user.bio, "Bio edited by PyGithub") def testEmails(self): - self.assertEqual(self.user.get_emails(), ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"]) + self.assertEqual( + self.user.get_emails(), + ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"], + ) self.user.add_to_emails("1@foobar.com", "2@foobar.com") - self.assertEqual(self.user.get_emails(), ["vincent@vincent-jacques.net", "1@foobar.com", "2@foobar.com", "github.com@vincent-jacques.net"]) + self.assertEqual( + self.user.get_emails(), + [ + "vincent@vincent-jacques.net", + "1@foobar.com", + "2@foobar.com", + "github.com@vincent-jacques.net", + ], + ) self.user.remove_from_emails("1@foobar.com", "2@foobar.com") - self.assertEqual(self.user.get_emails(), ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"]) + self.assertEqual( + self.user.get_emails(), + ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"], + ) def testFollowing(self): nvie = self.g.get_user("nvie") - self.assertListKeyEqual(self.user.get_following(), lambda u: u.login, ["schacon", "jamis", "chad", "unclebob", "dabrahams", "jnorthrup", "brugidou", "regisb", "walidk", "tanzilli", "fjardon", "r3c", "sdanzan", "vineus", "cjuniet", "gturri", "ant9000", "asquini", "claudyus", "jardon-u", "s-bernard", "kamaradclimber", "Lyloa", "nvie"]) + self.assertListKeyEqual( + self.user.get_following(), + lambda u: u.login, + [ + "schacon", + "jamis", + "chad", + "unclebob", + "dabrahams", + "jnorthrup", + "brugidou", + "regisb", + "walidk", + "tanzilli", + "fjardon", + "r3c", + "sdanzan", + "vineus", + "cjuniet", + "gturri", + "ant9000", + "asquini", + "claudyus", + "jardon-u", + "s-bernard", + "kamaradclimber", + "Lyloa", + "nvie", + ], + ) self.assertTrue(self.user.has_in_following(nvie)) self.user.remove_from_following(nvie) self.assertFalse(self.user.has_in_following(nvie)) self.user.add_to_following(nvie) self.assertTrue(self.user.has_in_following(nvie)) - self.assertListKeyEqual(self.user.get_followers(), lambda u: u.login, ["jnorthrup", "brugidou", "regisb", "walidk", "afzalkhan", "sdanzan", "vineus", "gturri", "fjardon", "cjuniet", "jardon-u", "kamaradclimber", "L42y"]) + self.assertListKeyEqual( + self.user.get_followers(), + lambda u: u.login, + [ + "jnorthrup", + "brugidou", + "regisb", + "walidk", + "afzalkhan", + "sdanzan", + "vineus", + "gturri", + "fjardon", + "cjuniet", + "jardon-u", + "kamaradclimber", + "L42y", + ], + ) def testWatching(self): gitflow = self.g.get_user("nvie").get_repo("gitflow") - self.assertListKeyEqual(self.user.get_watched(), lambda r: r.name, ["git", "boost.php", "capistrano", "boost.perl", "git-subtree", "git-hg", "homebrew", "celtic_knot", "twisted-intro", "markup", "hub", "gitflow", "murder", "boto", "agit", "d3", "pygit2", "git-pulls", "django_mathlatex", "scrumblr", "developer.github.com", "python-github3", "PlantUML", "bootstrap", "drawnby", "django-socketio", "django-realtime", "playground", "BozoCrack", "FatherBeaver", "PyGithub", "django", "django", "TestPyGithub"]) + self.assertListKeyEqual( + self.user.get_watched(), + lambda r: r.name, + [ + "git", + "boost.php", + "capistrano", + "boost.perl", + "git-subtree", + "git-hg", + "homebrew", + "celtic_knot", + "twisted-intro", + "markup", + "hub", + "gitflow", + "murder", + "boto", + "agit", + "d3", + "pygit2", + "git-pulls", + "django_mathlatex", + "scrumblr", + "developer.github.com", + "python-github3", + "PlantUML", + "bootstrap", + "drawnby", + "django-socketio", + "django-realtime", + "playground", + "BozoCrack", + "FatherBeaver", + "PyGithub", + "django", + "django", + "TestPyGithub", + ], + ) self.assertTrue(self.user.has_in_watched(gitflow)) self.user.remove_from_watched(gitflow) self.assertFalse(self.user.has_in_watched(gitflow)) @@ -119,7 +232,47 @@ class AuthenticatedUser(Framework.TestCase): def testStarring(self): gitflow = self.g.get_user("nvie").get_repo("gitflow") - self.assertListKeyEqual(self.user.get_starred(), lambda r: r.name, ["git", "boost.php", "capistrano", "boost.perl", "git-subtree", "git-hg", "homebrew", "celtic_knot", "twisted-intro", "markup", "hub", "gitflow", "murder", "boto", "agit", "d3", "pygit2", "git-pulls", "django_mathlatex", "scrumblr", "developer.github.com", "python-github3", "PlantUML", "bootstrap", "drawnby", "django-socketio", "django-realtime", "playground", "BozoCrack", "FatherBeaver", "amaunet", "django", "django", "moviePlanning", "folly"]) + self.assertListKeyEqual( + self.user.get_starred(), + lambda r: r.name, + [ + "git", + "boost.php", + "capistrano", + "boost.perl", + "git-subtree", + "git-hg", + "homebrew", + "celtic_knot", + "twisted-intro", + "markup", + "hub", + "gitflow", + "murder", + "boto", + "agit", + "d3", + "pygit2", + "git-pulls", + "django_mathlatex", + "scrumblr", + "developer.github.com", + "python-github3", + "PlantUML", + "bootstrap", + "drawnby", + "django-socketio", + "django-realtime", + "playground", + "BozoCrack", + "FatherBeaver", + "amaunet", + "django", + "django", + "moviePlanning", + "folly", + ], + ) self.assertTrue(self.user.has_in_starred(gitflow)) self.user.remove_from_starred(gitflow) self.assertFalse(self.user.has_in_starred(gitflow)) @@ -128,7 +281,43 @@ class AuthenticatedUser(Framework.TestCase): def testSubscriptions(self): gitflow = self.g.get_user("nvie").get_repo("gitflow") - self.assertListKeyEqual(self.user.get_subscriptions(), lambda r: r.name, ["gitflow", "ViDE", "Boost.HierarchicalEnum", "QuadProgMm", "DrawSyntax", "DrawTurksHead", "PrivateStuff", "vincent-jacques.net", "Hacking", "C4Planner", "developer.github.com", "PyGithub", "PyGithub", "django", "CinePlanning", "PyGithub", "PyGithub", "PyGithub", "IpMap", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub"]) + self.assertListKeyEqual( + self.user.get_subscriptions(), + lambda r: r.name, + [ + "gitflow", + "ViDE", + "Boost.HierarchicalEnum", + "QuadProgMm", + "DrawSyntax", + "DrawTurksHead", + "PrivateStuff", + "vincent-jacques.net", + "Hacking", + "C4Planner", + "developer.github.com", + "PyGithub", + "PyGithub", + "django", + "CinePlanning", + "PyGithub", + "PyGithub", + "PyGithub", + "IpMap", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + ], + ) self.assertTrue(self.user.has_in_subscriptions(gitflow)) self.user.remove_from_subscriptions(gitflow) self.assertFalse(self.user.has_in_subscriptions(gitflow)) @@ -136,20 +325,34 @@ class AuthenticatedUser(Framework.TestCase): self.assertTrue(self.user.has_in_subscriptions(gitflow)) def testGetAuthorizations(self): - self.assertListKeyEqual(self.user.get_authorizations(), lambda a: a.id, [372294]) + self.assertListKeyEqual( + self.user.get_authorizations(), lambda a: a.id, [372294] + ) def testCreateRepository(self): repo = self.user.create_repo(name="TestPyGithub") self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/TestPyGithub") def testCreateRepositoryWithAllArguments(self): - repo = self.user.create_repo(name="TestPyGithub", description="Repo created by PyGithub", homepage="http://foobar.com", - private=False, has_issues=False, has_projects=False, has_wiki=False, has_downloads=False, - allow_squash_merge=False, allow_merge_commit=False, allow_rebase_merge=True) + repo = self.user.create_repo( + name="TestPyGithub", + description="Repo created by PyGithub", + homepage="http://foobar.com", + private=False, + has_issues=False, + has_projects=False, + has_wiki=False, + has_downloads=False, + allow_squash_merge=False, + allow_merge_commit=False, + allow_rebase_merge=True, + ) self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/TestPyGithub") def testCreateRepositoryWithAutoInit(self): - repo = self.user.create_repo(name="TestPyGithub", auto_init=True, gitignore_template="Python") + repo = self.user.create_repo( + name="TestPyGithub", auto_init=True, gitignore_template="Python" + ) self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/TestPyGithub") def testCreateAuthorizationWithoutArguments(self): @@ -157,70 +360,301 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(authorization.id, 372259) def testCreateAuthorizationWithAllArguments(self): - authorization = self.user.create_authorization(["repo"], "Note created by PyGithub", "http://vincent-jacques.net/PyGithub") + authorization = self.user.create_authorization( + ["repo"], "Note created by PyGithub", "http://vincent-jacques.net/PyGithub" + ) self.assertEqual(authorization.id, 372294) def testCreateAuthorizationWithClientIdAndSecret(self): # I don't have a client_id and client_secret so the ReplayData for this test is forged - authorization = self.user.create_authorization(client_id="01234567890123456789", client_secret="0123456789012345678901234567890123456789") + authorization = self.user.create_authorization( + client_id="01234567890123456789", + client_secret="0123456789012345678901234567890123456789", + ) self.assertEqual(authorization.id, 372294) def testCreateGist(self): - gist = self.user.create_gist(True, {"foobar.txt": github.InputFileContent("File created by PyGithub")}, "Gist created by PyGithub") + gist = self.user.create_gist( + True, + {"foobar.txt": github.InputFileContent("File created by PyGithub")}, + "Gist created by PyGithub", + ) self.assertEqual(gist.description, "Gist created by PyGithub") self.assertEqual(list(gist.files.keys()), ["foobar.txt"]) self.assertEqual(gist.files["foobar.txt"].content, "File created by PyGithub") def testCreateGistWithoutDescription(self): - gist = self.user.create_gist(True, {"foobar.txt": github.InputFileContent("File created by PyGithub")}) + gist = self.user.create_gist( + True, {"foobar.txt": github.InputFileContent("File created by PyGithub")} + ) self.assertEqual(gist.description, None) self.assertEqual(list(gist.files.keys()), ["foobar.txt"]) self.assertEqual(gist.files["foobar.txt"].content, "File created by PyGithub") def testCreateKey(self): - key = self.user.create_key("Key added through PyGithub", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE") + key = self.user.create_key( + "Key added through PyGithub", + "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE", + ) self.assertEqual(key.id, 2626650) def testGetEvents(self): - self.assertListKeyBegin(self.user.get_events(), lambda e: e.type, ["PushEvent", "IssuesEvent", "IssueCommentEvent", "PushEvent"]) + self.assertListKeyBegin( + self.user.get_events(), + lambda e: e.type, + ["PushEvent", "IssuesEvent", "IssueCommentEvent", "PushEvent"], + ) def testGetOrganizationEvents(self): - self.assertListKeyBegin(self.user.get_organization_events(self.g.get_organization("BeaverSoftware")), lambda e: e.type, ["CreateEvent", "CreateEvent", "PushEvent", "PushEvent"]) + self.assertListKeyBegin( + self.user.get_organization_events( + self.g.get_organization("BeaverSoftware") + ), + lambda e: e.type, + ["CreateEvent", "CreateEvent", "PushEvent", "PushEvent"], + ) def testGetGists(self): - self.assertListKeyEqual(self.user.get_gists(), lambda g: g.id, ["2793505", "2793179", "11cb445f8197e17d303d", "1942384", "dcb7de17e8a52b74541d"]) - self.assertListKeyEqual(self.user.get_gists(since=datetime.datetime(2012, 3, 1, 23, 0, 0)), lambda g: g.id, ["2793505", "2793179", "11cb445f8197e17d303d"]) + self.assertListKeyEqual( + self.user.get_gists(), + lambda g: g.id, + [ + "2793505", + "2793179", + "11cb445f8197e17d303d", + "1942384", + "dcb7de17e8a52b74541d", + ], + ) + self.assertListKeyEqual( + self.user.get_gists(since=datetime.datetime(2012, 3, 1, 23, 0, 0)), + lambda g: g.id, + ["2793505", "2793179", "11cb445f8197e17d303d"], + ) def testGetStarredGists(self): - self.assertListKeyEqual(self.user.get_starred_gists(), lambda g: g.id, ["1942384", "dcb7de17e8a52b74541d"]) + self.assertListKeyEqual( + self.user.get_starred_gists(), + lambda g: g.id, + ["1942384", "dcb7de17e8a52b74541d"], + ) def testGetIssues(self): - self.assertListKeyEqual(self.user.get_issues(), lambda i: (i.id, i.repository.name), [(4639931, "PyGithub"), (4452000, "PyGithub"), (4356743, "PyGithub"), (3716033, "PyGithub"), (3715946, "PyGithub"), (3643837, "PyGithub"), (3628022, "PyGithub"), (3624595, "PyGithub"), (3624570, "PyGithub"), (3624561, "PyGithub"), (3624556, "PyGithub"), (3619973, "PyGithub"), (3527266, "PyGithub"), (3527245, "PyGithub"), (3527231, "PyGithub")]) + self.assertListKeyEqual( + self.user.get_issues(), + lambda i: (i.id, i.repository.name), + [ + (4639931, "PyGithub"), + (4452000, "PyGithub"), + (4356743, "PyGithub"), + (3716033, "PyGithub"), + (3715946, "PyGithub"), + (3643837, "PyGithub"), + (3628022, "PyGithub"), + (3624595, "PyGithub"), + (3624570, "PyGithub"), + (3624561, "PyGithub"), + (3624556, "PyGithub"), + (3619973, "PyGithub"), + (3527266, "PyGithub"), + (3527245, "PyGithub"), + (3527231, "PyGithub"), + ], + ) def testGetIssuesWithAllArguments(self): requestedByUser = self.user.get_repo("PyGithub").get_label("Requested by user") - issues = self.user.get_issues("assigned", "closed", [requestedByUser], "comments", "asc", datetime.datetime(2012, 5, 28, 23, 0, 0)) - self.assertListKeyEqual(issues, lambda i: i.id, [6816576, 8495415, 6889934, 8339699, 8075253, 8033963, 9089893, 9489725, 11746141, 5152384, 5177381, 5783131, 6454054, 6641076, 6653907, 7331214, 9489813, 9776615, 10360280, 4356743, 6583381, 6751469, 8189836, 10758585, 12097154, 12867103, 5191621, 5256315, 6363719, 9209408, 6912733, 9948505, 11503771, 10922412, 11844658, 12566144, 6353712, 9323084, 10379143, 5387373, 12179668, 6911794, 11731917, 6807542, 6780606]) + issues = self.user.get_issues( + "assigned", + "closed", + [requestedByUser], + "comments", + "asc", + datetime.datetime(2012, 5, 28, 23, 0, 0), + ) + self.assertListKeyEqual( + issues, + lambda i: i.id, + [ + 6816576, + 8495415, + 6889934, + 8339699, + 8075253, + 8033963, + 9089893, + 9489725, + 11746141, + 5152384, + 5177381, + 5783131, + 6454054, + 6641076, + 6653907, + 7331214, + 9489813, + 9776615, + 10360280, + 4356743, + 6583381, + 6751469, + 8189836, + 10758585, + 12097154, + 12867103, + 5191621, + 5256315, + 6363719, + 9209408, + 6912733, + 9948505, + 11503771, + 10922412, + 11844658, + 12566144, + 6353712, + 9323084, + 10379143, + 5387373, + 12179668, + 6911794, + 11731917, + 6807542, + 6780606, + ], + ) def testGetUserIssues(self): - self.assertListKeyEqual(self.user.get_user_issues(), lambda i: i.id, [14447880, 13505356, 12541184, 10586808, 6741461, 6741457, 6727331, 5641572]) + self.assertListKeyEqual( + self.user.get_user_issues(), + lambda i: i.id, + [ + 14447880, + 13505356, + 12541184, + 10586808, + 6741461, + 6741457, + 6727331, + 5641572, + ], + ) def testGetUserIssuesWithAllArguments(self): requestedByUser = self.user.get_repo("PyGithub").get_label("Requested by user") - issues = self.user.get_user_issues("assigned", "closed", [requestedByUser], "comments", "asc", datetime.datetime(2012, 5, 28, 23, 0, 0)) - self.assertListKeyEqual(issues, lambda i: i.id, [6816576, 8495415, 6889934, 8339699, 8075253, 8033963, 9089893, 9489725, 11746141, 5152384, 5177381, 5783131, 6454054, 6641076, 6653907, 7331214, 9489813, 9776615, 10360280, 4356743, 6583381, 6751469, 8189836, 10758585, 12097154, 12867103, 5191621, 5256315, 6363719, 9209408, 6912733, 9948505, 11503771, 10922412, 11844658, 12566144, 6353712, 9323084, 10379143, 5387373, 12179668, 6911794, 11731917, 6807542, 6780606]) + issues = self.user.get_user_issues( + "assigned", + "closed", + [requestedByUser], + "comments", + "asc", + datetime.datetime(2012, 5, 28, 23, 0, 0), + ) + self.assertListKeyEqual( + issues, + lambda i: i.id, + [ + 6816576, + 8495415, + 6889934, + 8339699, + 8075253, + 8033963, + 9089893, + 9489725, + 11746141, + 5152384, + 5177381, + 5783131, + 6454054, + 6641076, + 6653907, + 7331214, + 9489813, + 9776615, + 10360280, + 4356743, + 6583381, + 6751469, + 8189836, + 10758585, + 12097154, + 12867103, + 5191621, + 5256315, + 6363719, + 9209408, + 6912733, + 9948505, + 11503771, + 10922412, + 11844658, + 12566144, + 6353712, + 9323084, + 10379143, + 5387373, + 12179668, + 6911794, + 11731917, + 6807542, + 6780606, + ], + ) def testGetKeys(self): - self.assertListKeyEqual(self.user.get_keys(), lambda k: k.title, ["vincent@home", "vincent@gandi", "vincent@aws", "vincent@macbook"]) + self.assertListKeyEqual( + self.user.get_keys(), + lambda k: k.title, + ["vincent@home", "vincent@gandi", "vincent@aws", "vincent@macbook"], + ) def testGetOrgs(self): - self.assertListKeyEqual(self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"]) + self.assertListKeyEqual( + self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"] + ) def testGetRepos(self): - self.assertListKeyEqual(self.user.get_repos(), lambda r: r.name, ["TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + self.assertListKeyEqual( + self.user.get_repos(), + lambda r: r.name, + [ + "TestPyGithub", + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "Hacking", + "vincent-jacques.net", + "Contests", + "Candidates", + "Tests", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) def testGetReposWithArguments(self): - self.assertListKeyEqual(self.user.get_repos("all", "owner", "public", "full_name", "desc"), lambda r: r.name, ["ViDE", "QuadProgMm", "PyGithub", "DrawTurksHead", "DrawSyntax", "django", "developer.github.com", "C4Planner", "Boost.HierarchicalEnum", "acme-public-website"]) + self.assertListKeyEqual( + self.user.get_repos("all", "owner", "public", "full_name", "desc"), + lambda r: r.name, + [ + "ViDE", + "QuadProgMm", + "PyGithub", + "DrawTurksHead", + "DrawSyntax", + "django", + "developer.github.com", + "C4Planner", + "Boost.HierarchicalEnum", + "acme-public-website", + ], + ) def testCreateFork(self): repo = self.user.create_fork(self.g.get_user("nvie").get_repo("gitflow")) @@ -234,22 +668,45 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(notification.subject.title, "Feature/coveralls") 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)) + self.assertEqual( + notification.updated_at, datetime.datetime(2013, 3, 15, 5, 43, 11) + ) self.assertEqual(notification.url, None) self.assertEqual(notification.subject.url, None) self.assertEqual(notification.subject.latest_comment_url, None) def testGetNotifications(self): - self.assertListKeyEqual(self.user.get_notifications(participating=True), lambda n: n.id, ["8406712"]) + self.assertListKeyEqual( + self.user.get_notifications(participating=True), lambda n: n.id, ["8406712"] + ) def testGetNotificationsWithOtherArguments(self): - self.assertListKeyEqual(self.user.get_notifications(all=True), lambda n: n.id, []) + self.assertListKeyEqual( + self.user.get_notifications(all=True), lambda n: n.id, [] + ) 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.datetime(2018, 10, 18, 18, 20, 0o1, 0) + ) def testGetTeams(self): - self.assertListKeyEqual(self.user.get_teams(), lambda t: t.name, ["Owners", "Honoraries", "Honoraries", "Honoraries", "Honoraries", "Honoraries", "Honoraries", "Honoraries", "Honoraries", "Honoraries"]) + self.assertListKeyEqual( + self.user.get_teams(), + lambda t: t.name, + [ + "Owners", + "Honoraries", + "Honoraries", + "Honoraries", + "Honoraries", + "Honoraries", + "Honoraries", + "Honoraries", + "Honoraries", + "Honoraries", + ], + ) def testAcceptInvitation(self): self.assertEqual(self.user.accept_invitation(4294886), None) @@ -262,7 +719,11 @@ class AuthenticatedUser(Framework.TestCase): self.assertEqual(invitation.inviter.login, "jacquev6") def testCreateMigration(self): - self.assertTrue(isinstance(self.user.create_migration(["sample-repo"]), github.Migration.Migration)) + self.assertTrue( + isinstance( + self.user.create_migration(["sample-repo"]), github.Migration.Migration + ) + ) def testGetMigrations(self): self.assertEqual(self.user.get_migrations().totalCount, 46) diff --git a/tests/Authentication.py b/tests/Authentication.py index 2c1213d9..a38fec52 100644 --- a/tests/Authentication.py +++ b/tests/Authentication.py @@ -29,9 +29,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + import github +from . import Framework + class Authentication(Framework.BasicTestCase): def testNoAuthentication(self): @@ -53,7 +55,11 @@ class Authentication(Framework.BasicTestCase): # Warning: I don't have a secret key, so the requests for this test are forged def testSecretKeyAuthentication(self): g = github.Github(client_id=self.client_id, client_secret=self.client_secret) - self.assertListKeyEqual(g.get_organization("BeaverSoftware").get_repos("public"), lambda r: r.name, ["FatherBeaver", "PyGithub"]) + self.assertListKeyEqual( + g.get_organization("BeaverSoftware").get_repos("public"), + lambda r: r.name, + ["FatherBeaver", "PyGithub"], + ) def testUserAgent(self): g = github.Github(user_agent="PyGithubTester") diff --git a/tests/Authorization.py b/tests/Authorization.py index 78350b60..434d4ec9 100644 --- a/tests/Authorization.py +++ b/tests/Authorization.py @@ -28,10 +28,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Authorization(Framework.TestCase): def setUp(self): @@ -39,16 +40,27 @@ class Authorization(Framework.TestCase): self.authorization = self.g.get_user().get_authorization(372259) def testAttributes(self): - self.assertEqual(self.authorization.app.url, "http://developer.github.com/v3/oauth/#oauth-authorizations-api") + self.assertEqual( + self.authorization.app.url, + "http://developer.github.com/v3/oauth/#oauth-authorizations-api", + ) self.assertEqual(self.authorization.app.name, "GitHub API") - self.assertEqual(self.authorization.created_at, datetime.datetime(2012, 5, 22, 18, 3, 17)) + self.assertEqual( + self.authorization.created_at, datetime.datetime(2012, 5, 22, 18, 3, 17) + ) self.assertEqual(self.authorization.id, 372259) self.assertEqual(self.authorization.note, None) self.assertEqual(self.authorization.note_url, None) self.assertEqual(self.authorization.scopes, []) - self.assertEqual(self.authorization.token, "82459c4500086f8f0cc67d2936c17d1e27ad1c33") - self.assertEqual(self.authorization.updated_at, datetime.datetime(2012, 5, 22, 18, 3, 17)) - self.assertEqual(self.authorization.url, "https://api.github.com/authorizations/372259") + self.assertEqual( + self.authorization.token, "82459c4500086f8f0cc67d2936c17d1e27ad1c33" + ) + self.assertEqual( + self.authorization.updated_at, datetime.datetime(2012, 5, 22, 18, 3, 17) + ) + self.assertEqual( + self.authorization.url, "https://api.github.com/authorizations/372259" + ) def testEdit(self): self.authorization.edit() @@ -61,9 +73,14 @@ class Authorization(Framework.TestCase): self.assertEqual(self.authorization.scopes, ["user"]) self.assertEqual(self.authorization.note, None) self.assertEqual(self.authorization.note_url, None) - self.authorization.edit(note="Note created by PyGithub", note_url="http://vincent-jacques.net/PyGithub") + self.authorization.edit( + note="Note created by PyGithub", + note_url="http://vincent-jacques.net/PyGithub", + ) self.assertEqual(self.authorization.note, "Note created by PyGithub") - self.assertEqual(self.authorization.note_url, "http://vincent-jacques.net/PyGithub") + self.assertEqual( + self.authorization.note_url, "http://vincent-jacques.net/PyGithub" + ) def testDelete(self): self.authorization.delete() diff --git a/tests/BadAttributes.py b/tests/BadAttributes.py index 69bb1b76..77884a35 100755 --- a/tests/BadAttributes.py +++ b/tests/BadAttributes.py @@ -27,12 +27,14 @@ ################################################################################ from __future__ import absolute_import + import datetime -from . import Framework import github import six +from . import Framework + # Replay data is forged to simulate bad things returned by Github class BadAttributes(Framework.TestCase): @@ -54,8 +56,13 @@ class BadAttributes(Framework.TestCase): user.created_at self.assertEqual(raisedexp.exception.actual_value, "foobar") self.assertEqual(raisedexp.exception.expected_type, (str, six.text_type)) - self.assertEqual(raisedexp.exception.transformation_exception.__class__, ValueError) - self.assertEqual(raisedexp.exception.transformation_exception.args, ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",)) + self.assertEqual( + raisedexp.exception.transformation_exception.__class__, ValueError + ) + self.assertEqual( + raisedexp.exception.transformation_exception.args, + ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",), + ) def testBadTransformedAttribute(self): user = self.g.get_user("klmitch") @@ -87,7 +94,9 @@ class BadAttributes(Framework.TestCase): self.assertEqual(raisedexp.exception.actual_value, 42) def testBadTransformedAttributeInList(self): - commit = self.g.get_repo("klmitch/turnstile", lazy=True).get_commit("38d9082a898d0822b5ccdfd78f3a536e2efa6c26") + commit = self.g.get_repo("klmitch/turnstile", lazy=True).get_commit( + "38d9082a898d0822b5ccdfd78f3a536e2efa6c26" + ) with self.assertRaises(github.BadAttributeException) as raisedexp: commit.files @@ -101,13 +110,163 @@ class BadAttributes(Framework.TestCase): with self.assertRaises(github.BadAttributeException) as raisedexp: gist.files self.assertEqual(raisedexp.exception.actual_value, {"test.py": 42}) - self.assertEqual(raisedexp.exception.expected_type, {(str, six.text_type): dict}) + self.assertEqual( + raisedexp.exception.expected_type, {(str, six.text_type): dict} + ) self.assertEqual(raisedexp.exception.transformation_exception, None) def testIssue195(self): hooks = self.g.get_hooks() # We can loop on all hooks as long as we don't access circleci's events attribute - self.assertListKeyEqual(hooks, lambda h: h.name, [u'activecollab', u'acunote', u'agilebench', u'agilezen', u'amazonsns', u'apiary', u'apoio', u'appharbor', u'apropos', u'asana', u'backlog', u'bamboo', u'basecamp', u'bcx', u'blimp', u'boxcar', u'buddycloud', u'bugherd', u'bugly', u'bugzilla', u'campfire', u'cia', u'circleci', u'codeclimate', u'codeportingcsharp2java', u'codeship', u'coffeedocinfo', u'conductor', u'coop', u'copperegg', u'cube', u'depending', u'deployhq', u'devaria', u'docker', u'ducksboard', u'email', u'firebase', u'fisheye', u'flowdock', u'fogbugz', u'freckle', u'friendfeed', u'gemini', u'gemnasium', u'geocommit', u'getlocalization', u'gitlive', u'grmble', u'grouptalent', u'grove', u'habitualist', u'hakiri', u'hall', u'harvest', u'hipchat', u'hostedgraphite', u'hubcap', u'hubci', u'humbug', u'icescrum', u'irc', u'irker', u'ironmq', u'ironworker', u'jabber', u'jaconda', u'jeapie', u'jenkins', u'jenkinsgit', u'jira', u'jqueryplugins', u'kanbanery', u'kickoff', u'leanto', u'lechat', u'lighthouse', u'lingohub', u'loggly', u'mantisbt', u'masterbranch', u'mqttpub', u'nma', u'nodejitsu', u'notifo', u'ontime', u'pachube', u'packagist', u'phraseapp', u'pivotaltracker', u'planbox', u'planio', u'prowl', u'puppetlinter', u'pushalot', u'pushover', u'pythonpackages', u'railsbp', u'railsbrakeman', u'rally', u'rapidpush', u'rationaljazzhub', u'rationalteamconcert', u'rdocinfo', u'readthedocs', u'redmine', u'rubyforge', u'scrumdo', u'shiningpanda', u'sifter', u'simperium', u'slatebox', u'snowyevening', u'socialcast', u'softlayermessaging', u'sourcemint', u'splendidbacon', u'sprintly', u'sqsqueue', u'stackmob', u'statusnet', u'talker', u'targetprocess', u'tddium', u'teamcity', u'tender', u'tenxer', u'testpilot', u'toggl', u'trac', u'trajectory', u'travis', u'trello', u'twilio', u'twitter', u'unfuddle', u'web', u'weblate', u'webtranslateit', u'yammer', u'youtrack', u'zendesk', u'zohoprojects']) + self.assertListKeyEqual( + hooks, + lambda h: h.name, + [ + u"activecollab", + u"acunote", + u"agilebench", + u"agilezen", + u"amazonsns", + u"apiary", + u"apoio", + u"appharbor", + u"apropos", + u"asana", + u"backlog", + u"bamboo", + u"basecamp", + u"bcx", + u"blimp", + u"boxcar", + u"buddycloud", + u"bugherd", + u"bugly", + u"bugzilla", + u"campfire", + u"cia", + u"circleci", + u"codeclimate", + u"codeportingcsharp2java", + u"codeship", + u"coffeedocinfo", + u"conductor", + u"coop", + u"copperegg", + u"cube", + u"depending", + u"deployhq", + u"devaria", + u"docker", + u"ducksboard", + u"email", + u"firebase", + u"fisheye", + u"flowdock", + u"fogbugz", + u"freckle", + u"friendfeed", + u"gemini", + u"gemnasium", + u"geocommit", + u"getlocalization", + u"gitlive", + u"grmble", + u"grouptalent", + u"grove", + u"habitualist", + u"hakiri", + u"hall", + u"harvest", + u"hipchat", + u"hostedgraphite", + u"hubcap", + u"hubci", + u"humbug", + u"icescrum", + u"irc", + u"irker", + u"ironmq", + u"ironworker", + u"jabber", + u"jaconda", + u"jeapie", + u"jenkins", + u"jenkinsgit", + u"jira", + u"jqueryplugins", + u"kanbanery", + u"kickoff", + u"leanto", + u"lechat", + u"lighthouse", + u"lingohub", + u"loggly", + u"mantisbt", + u"masterbranch", + u"mqttpub", + u"nma", + u"nodejitsu", + u"notifo", + u"ontime", + u"pachube", + u"packagist", + u"phraseapp", + u"pivotaltracker", + u"planbox", + u"planio", + u"prowl", + u"puppetlinter", + u"pushalot", + u"pushover", + u"pythonpackages", + u"railsbp", + u"railsbrakeman", + u"rally", + u"rapidpush", + u"rationaljazzhub", + u"rationalteamconcert", + u"rdocinfo", + u"readthedocs", + u"redmine", + u"rubyforge", + u"scrumdo", + u"shiningpanda", + u"sifter", + u"simperium", + u"slatebox", + u"snowyevening", + u"socialcast", + u"softlayermessaging", + u"sourcemint", + u"splendidbacon", + u"sprintly", + u"sqsqueue", + u"stackmob", + u"statusnet", + u"talker", + u"targetprocess", + u"tddium", + u"teamcity", + u"tender", + u"tenxer", + u"testpilot", + u"toggl", + u"trac", + u"trajectory", + u"travis", + u"trello", + u"twilio", + u"twitter", + u"unfuddle", + u"web", + u"weblate", + u"webtranslateit", + u"yammer", + u"youtrack", + u"zendesk", + u"zohoprojects", + ], + ) for hook in hooks: if hook.name != "circleci": hook.events @@ -116,6 +275,31 @@ class BadAttributes(Framework.TestCase): if hook.name == "circleci": with self.assertRaises(github.BadAttributeException) as raisedexp: hook.events - self.assertEqual(raisedexp.exception.actual_value, [["commit_comment", "create", "delete", "download", "follow", "fork", "fork_apply", "gist", "gollum", "issue_comment", "issues", "member", "public", "pull_request", "pull_request_review_comment", "push", "status", "team_add", "watch"]]) + self.assertEqual( + raisedexp.exception.actual_value, + [ + [ + "commit_comment", + "create", + "delete", + "download", + "follow", + "fork", + "fork_apply", + "gist", + "gollum", + "issue_comment", + "issues", + "member", + "public", + "pull_request", + "pull_request_review_comment", + "push", + "status", + "team_add", + "watch", + ] + ], + ) self.assertEqual(raisedexp.exception.expected_type, [(str, six.text_type)]) self.assertEqual(raisedexp.exception.transformation_exception, None) diff --git a/tests/Branch.py b/tests/Branch.py index 48079f13..66b2dc09 100644 --- a/tests/Branch.py +++ b/tests/Branch.py @@ -31,10 +31,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import github +from . import Framework + class Branch(Framework.TestCase): def setUp(self): @@ -42,58 +43,102 @@ class Branch(Framework.TestCase): self.repo = self.g.get_user().get_repo("PyGithub") self.branch = self.repo.get_branch("topic/RewriteWithGeneratedCode") self.protected_branch = self.repo.get_branch("integrations") - self.organization_branch = self.g.get_repo("PyGithub/PyGithub", lazy=True).get_branch("master") + self.organization_branch = self.g.get_repo( + "PyGithub/PyGithub", lazy=True + ).get_branch("master") def testAttributes(self): self.assertEqual(self.branch.name, "topic/RewriteWithGeneratedCode") - self.assertEqual(self.branch.commit.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") - self.assertEqual(self.branch.protection_url, "https://api.github.com/repos/jacquev6/PyGithub/branches/topic/RewriteWithGeneratedCode/protection") + self.assertEqual( + self.branch.commit.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a" + ) + self.assertEqual( + self.branch.protection_url, + "https://api.github.com/repos/jacquev6/PyGithub/branches/topic/RewriteWithGeneratedCode/protection", + ) self.assertFalse(self.branch.protected) # test __repr__() based on this attributes - self.assertEqual(self.branch.__repr__(), 'Branch(name="topic/RewriteWithGeneratedCode")') + self.assertEqual( + self.branch.__repr__(), 'Branch(name="topic/RewriteWithGeneratedCode")' + ) def testEditProtection(self): - self.protected_branch.edit_protection(strict=True, require_code_owner_reviews=True, required_approving_review_count=2) + self.protected_branch.edit_protection( + strict=True, + require_code_owner_reviews=True, + required_approving_review_count=2, + ) branch_protection = self.protected_branch.get_protection() self.assertTrue(branch_protection.required_status_checks.strict) self.assertEqual(branch_protection.required_status_checks.contexts, []) self.assertTrue(branch_protection.enforce_admins) - self.assertFalse(branch_protection.required_pull_request_reviews.dismiss_stale_reviews) - self.assertTrue(branch_protection.required_pull_request_reviews.require_code_owner_reviews) - self.assertEqual(branch_protection.required_pull_request_reviews.required_approving_review_count, 2) + self.assertFalse( + branch_protection.required_pull_request_reviews.dismiss_stale_reviews + ) + self.assertTrue( + branch_protection.required_pull_request_reviews.require_code_owner_reviews + ) + self.assertEqual( + branch_protection.required_pull_request_reviews.required_approving_review_count, + 2, + ) def testEditProtectionDismissalUsersWithUserOwnedBranch(self): with self.assertRaises(github.GithubException) as raisedexp: self.protected_branch.edit_protection(dismissal_users=["jacquev6"]) self.assertEqual(raisedexp.exception.status, 422) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#update-branch-protection', - u'message': u'Validation Failed', - u'errors': [u'Only organization repositories can have users and team restrictions'] - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#update-branch-protection", + u"message": u"Validation Failed", + u"errors": [ + u"Only organization repositories can have users and team restrictions" + ], + }, ) def testEditProtectionPushRestrictionsWithUserOwnedBranch(self): with self.assertRaises(github.GithubException) as raisedexp: - self.protected_branch.edit_protection(user_push_restrictions=["jacquev6"], team_push_restrictions=[]) + self.protected_branch.edit_protection( + user_push_restrictions=["jacquev6"], team_push_restrictions=[] + ) self.assertEqual(raisedexp.exception.status, 422) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#update-branch-protection', - u'message': u'Validation Failed', - u'errors': [u'Only organization repositories can have users and team restrictions'] - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#update-branch-protection", + u"message": u"Validation Failed", + u"errors": [ + u"Only organization repositories can have users and team restrictions" + ], + }, ) def testEditProtectionPushRestrictionsAndDismissalUser(self): - self.organization_branch.edit_protection(dismissal_users=["jacquev6"], user_push_restrictions=["jacquev6"]) + self.organization_branch.edit_protection( + dismissal_users=["jacquev6"], user_push_restrictions=["jacquev6"] + ) branch_protection = self.organization_branch.get_protection() - self.assertListKeyEqual(branch_protection.required_pull_request_reviews.dismissal_users, lambda u: u.login, ["jacquev6"]) - self.assertListKeyEqual(branch_protection.required_pull_request_reviews.dismissal_teams, lambda u: u.slug, []) - self.assertListKeyEqual(branch_protection.get_user_push_restrictions(), lambda u: u.login, ["jacquev6"]) - self.assertListKeyEqual(branch_protection.get_team_push_restrictions(), lambda u: u.slug, []) + self.assertListKeyEqual( + branch_protection.required_pull_request_reviews.dismissal_users, + lambda u: u.login, + ["jacquev6"], + ) + self.assertListKeyEqual( + branch_protection.required_pull_request_reviews.dismissal_teams, + lambda u: u.slug, + [], + ) + self.assertListKeyEqual( + branch_protection.get_user_push_restrictions(), + lambda u: u.login, + ["jacquev6"], + ) + self.assertListKeyEqual( + branch_protection.get_team_push_restrictions(), lambda u: u.slug, [] + ) def testRemoveProtection(self): self.assertTrue(self.protected_branch.protected) @@ -104,10 +149,11 @@ class Branch(Framework.TestCase): protected_branch.get_protection() self.assertEqual(raisedexp.exception.status, 404) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#get-branch-protection', - u'message': u'Branch not protected' - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#get-branch-protection", + u"message": u"Branch not protected", + }, ) def testEditRequiredStatusChecks(self): @@ -122,47 +168,64 @@ class Branch(Framework.TestCase): self.protected_branch.get_required_status_checks() self.assertEqual(raisedexp.exception.status, 404) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch', - u'message': u'Required status checks not enabled' - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch", + u"message": u"Required status checks not enabled", + }, ) def testEditRequiredPullRequestReviews(self): - self.protected_branch.edit_required_pull_request_reviews(dismiss_stale_reviews=True, required_approving_review_count=2) - required_pull_request_reviews = self.protected_branch.get_required_pull_request_reviews() + self.protected_branch.edit_required_pull_request_reviews( + dismiss_stale_reviews=True, required_approving_review_count=2 + ) + required_pull_request_reviews = ( + self.protected_branch.get_required_pull_request_reviews() + ) self.assertTrue(required_pull_request_reviews.dismiss_stale_reviews) self.assertTrue(required_pull_request_reviews.require_code_owner_reviews) - self.assertEqual(required_pull_request_reviews.required_approving_review_count, 2) + self.assertEqual( + required_pull_request_reviews.required_approving_review_count, 2 + ) def testEditRequiredPullRequestReviewsWithTooLargeApprovingReviewCount(self): with self.assertRaises(github.GithubException) as raisedexp: - self.protected_branch.edit_required_pull_request_reviews(required_approving_review_count=9) + self.protected_branch.edit_required_pull_request_reviews( + required_approving_review_count=9 + ) self.assertEqual(raisedexp.exception.status, 422) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch', - u'message': u'Invalid request.\n\n9 must be less than or equal to 6.' - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch", + u"message": u"Invalid request.\n\n9 must be less than or equal to 6.", + }, ) def testEditRequiredPullRequestReviewsWithUserBranchAndDismissalUsers(self): with self.assertRaises(github.GithubException) as raisedexp: - self.protected_branch.edit_required_pull_request_reviews(dismissal_users=["jacquev6"]) + self.protected_branch.edit_required_pull_request_reviews( + dismissal_users=["jacquev6"] + ) self.assertEqual(raisedexp.exception.status, 422) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch', - u'message': u'Dismissal restrictions are supported only for repositories owned by an organization.' - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch", + u"message": u"Dismissal restrictions are supported only for repositories owned by an organization.", + }, ) def testRemoveRequiredPullRequestReviews(self): self.protected_branch.remove_required_pull_request_reviews() - required_pull_request_reviews = self.protected_branch.get_required_pull_request_reviews() + required_pull_request_reviews = ( + self.protected_branch.get_required_pull_request_reviews() + ) self.assertFalse(required_pull_request_reviews.dismiss_stale_reviews) self.assertFalse(required_pull_request_reviews.require_code_owner_reviews) - self.assertEqual(required_pull_request_reviews.required_approving_review_count, 1) + self.assertEqual( + required_pull_request_reviews.required_approving_review_count, 1 + ) def testAdminEnforcement(self): self.protected_branch.remove_admin_enforcement() @@ -172,29 +235,61 @@ class Branch(Framework.TestCase): def testAddUserPushRestrictions(self): self.organization_branch.add_user_push_restrictions("sfdye") - self.assertListKeyEqual(self.organization_branch.get_user_push_restrictions(), lambda u: u.login, ["jacquev6", "sfdye"]) + self.assertListKeyEqual( + self.organization_branch.get_user_push_restrictions(), + lambda u: u.login, + ["jacquev6", "sfdye"], + ) def testReplaceUserPushRestrictions(self): - self.assertListKeyEqual(self.organization_branch.get_user_push_restrictions(), lambda u: u.login, ["jacquev6"]) + self.assertListKeyEqual( + self.organization_branch.get_user_push_restrictions(), + lambda u: u.login, + ["jacquev6"], + ) self.organization_branch.replace_user_push_restrictions("sfdye") - self.assertListKeyEqual(self.organization_branch.get_user_push_restrictions(), lambda u: u.login, ["sfdye"]) + self.assertListKeyEqual( + self.organization_branch.get_user_push_restrictions(), + lambda u: u.login, + ["sfdye"], + ) def testRemoveUserPushRestrictions(self): self.organization_branch.remove_user_push_restrictions("jacquev6") - self.assertListKeyEqual(self.organization_branch.get_user_push_restrictions(), lambda u: u.login, ["sfdye"]) + self.assertListKeyEqual( + self.organization_branch.get_user_push_restrictions(), + lambda u: u.login, + ["sfdye"], + ) def testAddTeamPushRestrictions(self): self.organization_branch.add_team_push_restrictions("pygithub-owners") - self.assertListKeyEqual(self.organization_branch.get_team_push_restrictions(), lambda t: t.slug, ["pygithub-owners"]) + self.assertListKeyEqual( + self.organization_branch.get_team_push_restrictions(), + lambda t: t.slug, + ["pygithub-owners"], + ) def testReplaceTeamPushRestrictions(self): - self.assertListKeyEqual(self.organization_branch.get_team_push_restrictions(), lambda t: t.slug, ["pygithub-owners"]) + self.assertListKeyEqual( + self.organization_branch.get_team_push_restrictions(), + lambda t: t.slug, + ["pygithub-owners"], + ) self.organization_branch.replace_team_push_restrictions("org-team") - self.assertListKeyEqual(self.organization_branch.get_team_push_restrictions(), lambda t: t.slug, ["org-team"]) + self.assertListKeyEqual( + self.organization_branch.get_team_push_restrictions(), + lambda t: t.slug, + ["org-team"], + ) def testRemoveTeamPushRestrictions(self): self.organization_branch.remove_team_push_restrictions("org-team") - self.assertListKeyEqual(self.organization_branch.get_team_push_restrictions(), lambda t: t.slug, ["pygithub-owners"]) + self.assertListKeyEqual( + self.organization_branch.get_team_push_restrictions(), + lambda t: t.slug, + ["pygithub-owners"], + ) def testRemovePushRestrictions(self): self.organization_branch.remove_push_restrictions() @@ -202,10 +297,11 @@ class Branch(Framework.TestCase): list(self.organization_branch.get_user_push_restrictions()) self.assertEqual(raisedexp.exception.status, 404) self.assertEqual( - raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch', - u'message': u'Push restrictions not enabled' - } + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch", + u"message": u"Push restrictions not enabled", + }, ) def testGetRequiredSignatures(self): diff --git a/tests/BranchProtection.py b/tests/BranchProtection.py index d5f19351..769d96b1 100644 --- a/tests/BranchProtection.py +++ b/tests/BranchProtection.py @@ -23,16 +23,30 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class BranchProtection(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.branch_protection = self.g.get_user().get_repo("PyGithub").get_branch("integrations").get_protection() + self.branch_protection = ( + self.g.get_user() + .get_repo("PyGithub") + .get_branch("integrations") + .get_protection() + ) def testAttributes(self): self.assertTrue(self.branch_protection.required_status_checks.strict) - self.assertEqual(self.branch_protection.required_status_checks.contexts, ["foo/bar"]) - self.assertEqual(self.branch_protection.url, "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection") - self.assertEqual(self.branch_protection.__repr__(), 'BranchProtection(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection")') + self.assertEqual( + self.branch_protection.required_status_checks.contexts, ["foo/bar"] + ) + self.assertEqual( + self.branch_protection.url, + "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection", + ) + self.assertEqual( + self.branch_protection.__repr__(), + 'BranchProtection(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection")', + ) diff --git a/tests/Commit.py b/tests/Commit.py index ea863046..d8b29fdc 100644 --- a/tests/Commit.py +++ b/tests/Commit.py @@ -30,44 +30,77 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + import six +from . import Framework + class Commit(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.commit = self.g.get_user().get_repo("PyGithub").get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + self.commit = ( + self.g.get_user() + .get_repo("PyGithub") + .get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + ) self.commit.author.login # to force lazy completion def testAttributes(self): self.assertEqual(self.commit.author.login, "jacquev6") - self.assertEqual(self.commit.commit.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + self.assertEqual( + self.commit.commit.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", + ) self.assertEqual(self.commit.committer.login, "jacquev6") self.assertEqual(len(self.commit.files), 1) self.assertEqual(self.commit.files[0].additions, 0) - self.assertEqual(self.commit.files[0].blob_url, "https://github.com/jacquev6/PyGithub/blob/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py") + self.assertEqual( + self.commit.files[0].blob_url, + "https://github.com/jacquev6/PyGithub/blob/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py", + ) self.assertEqual(self.commit.files[0].changes, 20) self.assertEqual(self.commit.files[0].deletions, 20) - self.assertEqual(self.commit.files[0].filename, "github/GithubObjects/GitAuthor.py") + self.assertEqual( + self.commit.files[0].filename, "github/GithubObjects/GitAuthor.py" + ) self.assertTrue(isinstance(self.commit.files[0].patch, (str, six.text_type))) - self.assertEqual(self.commit.files[0].raw_url, "https://github.com/jacquev6/PyGithub/raw/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py") - self.assertEqual(self.commit.files[0].sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + self.assertEqual( + self.commit.files[0].raw_url, + "https://github.com/jacquev6/PyGithub/raw/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py", + ) + self.assertEqual( + self.commit.files[0].sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a" + ) self.assertEqual(self.commit.files[0].status, "modified") self.assertEqual(len(self.commit.parents), 1) - self.assertEqual(self.commit.parents[0].sha, "b46ed0dfde5ad02d3b91eb54a41c5ed960710eae") + self.assertEqual( + self.commit.parents[0].sha, "b46ed0dfde5ad02d3b91eb54a41c5ed960710eae" + ) self.assertEqual(self.commit.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") self.assertEqual(self.commit.stats.deletions, 20) self.assertEqual(self.commit.stats.additions, 0) self.assertEqual(self.commit.stats.total, 20) - self.assertEqual(self.commit.url, "https://api.github.com/repos/jacquev6/PyGithub/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a") - self.assertEqual(self.commit.commit.tree.sha, "4c6bd50994f0f9823f898b1c6c964ad7d4fa11ab") + self.assertEqual( + self.commit.url, + "https://api.github.com/repos/jacquev6/PyGithub/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", + ) + self.assertEqual( + self.commit.commit.tree.sha, "4c6bd50994f0f9823f898b1c6c964ad7d4fa11ab" + ) # test __repr__() based on this attributes - self.assertEqual(self.commit.__repr__(), 'Commit(sha="1292bf0e22c796e91cc3d6e24b544aece8c21f2a")') + self.assertEqual( + self.commit.__repr__(), + 'Commit(sha="1292bf0e22c796e91cc3d6e24b544aece8c21f2a")', + ) def testGetComments(self): - self.assertListKeyEqual(self.commit.get_comments(), lambda c: c.id, [1347033, 1347083, 1347397, 1349654]) + self.assertListKeyEqual( + self.commit.get_comments(), + lambda c: c.id, + [1347033, 1347083, 1347397, 1349654], + ) def testCreateComment(self): comment = self.commit.create_comment("Comment created by PyGithub") @@ -77,17 +110,29 @@ class Commit(Framework.TestCase): self.assertEqual(comment.position, None) def testCreateCommentOnFileLine(self): - comment = self.commit.create_comment("Comment created by PyGithub", path="codegen/templates/GithubObject.MethodBody.UseResult.py", line=26) + comment = self.commit.create_comment( + "Comment created by PyGithub", + path="codegen/templates/GithubObject.MethodBody.UseResult.py", + line=26, + ) self.assertEqual(comment.id, 1362000) self.assertEqual(comment.line, 26) - self.assertEqual(comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py") + self.assertEqual( + comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py" + ) self.assertEqual(comment.position, None) def testCreateCommentOnFilePosition(self): - comment = self.commit.create_comment("Comment also created by PyGithub", path="codegen/templates/GithubObject.MethodBody.UseResult.py", position=3) + comment = self.commit.create_comment( + "Comment also created by PyGithub", + path="codegen/templates/GithubObject.MethodBody.UseResult.py", + position=3, + ) self.assertEqual(comment.id, 1362001) self.assertEqual(comment.line, None) - self.assertEqual(comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py") + self.assertEqual( + comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py" + ) self.assertEqual(comment.position, 3) def testCreateStatusWithoutOptionalParameters(self): @@ -98,8 +143,14 @@ class Commit(Framework.TestCase): self.assertEqual(status.description, None) def testCreateStatusWithAllParameters(self): - status = self.commit.create_status("success", "https://github.com/jacquev6/PyGithub/issues/67", "Status successfuly created by PyGithub") + status = self.commit.create_status( + "success", + "https://github.com/jacquev6/PyGithub/issues/67", + "Status successfuly created by PyGithub", + ) self.assertEqual(status.id, 277040) self.assertEqual(status.state, "success") - self.assertEqual(status.target_url, "https://github.com/jacquev6/PyGithub/issues/67") + self.assertEqual( + status.target_url, "https://github.com/jacquev6/PyGithub/issues/67" + ) self.assertEqual(status.description, "Status successfuly created by PyGithub") diff --git a/tests/CommitCombinedStatus.py b/tests/CommitCombinedStatus.py index e3adbd46..e8fae897 100644 --- a/tests/CommitCombinedStatus.py +++ b/tests/CommitCombinedStatus.py @@ -27,32 +27,61 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class CommitCombinedStatus(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.combined_status = self.g.get_repo("edx/edx-platform", lazy=True).get_commit("74e70119a23fa3ffb3db19d4590eccfebd72b659").get_combined_status() + self.combined_status = ( + self.g.get_repo("edx/edx-platform", lazy=True) + .get_commit("74e70119a23fa3ffb3db19d4590eccfebd72b659") + .get_combined_status() + ) def testAttributes(self): self.assertEqual(self.combined_status.state, "success") - self.assertEqual(self.combined_status.statuses[0].url, "https://api.github.com/repos/edx/edx-platform/statuses/74e70119a23fa3ffb3db19d4590eccfebd72b659") + self.assertEqual( + self.combined_status.statuses[0].url, + "https://api.github.com/repos/edx/edx-platform/statuses/74e70119a23fa3ffb3db19d4590eccfebd72b659", + ) self.assertEqual(self.combined_status.statuses[1].id, 390603044) self.assertEqual(self.combined_status.statuses[2].state, "success") - self.assertEqual(self.combined_status.statuses[3].description, "Build finished.") - self.assertEqual(self.combined_status.statuses[4].target_url, "https://build.testeng.edx.org/job/edx-platform-python-unittests-pr/10504/") - self.assertEqual(self.combined_status.statuses[4].created_at, datetime.datetime(2015, 12, 14, 13, 24, 18)) - self.assertEqual(self.combined_status.statuses[3].updated_at, datetime.datetime(2015, 12, 14, 13, 23, 35)) - self.assertEqual(self.combined_status.sha, "74e70119a23fa3ffb3db19d4590eccfebd72b659") + self.assertEqual( + self.combined_status.statuses[3].description, "Build finished." + ) + self.assertEqual( + self.combined_status.statuses[4].target_url, + "https://build.testeng.edx.org/job/edx-platform-python-unittests-pr/10504/", + ) + self.assertEqual( + self.combined_status.statuses[4].created_at, + datetime.datetime(2015, 12, 14, 13, 24, 18), + ) + self.assertEqual( + self.combined_status.statuses[3].updated_at, + datetime.datetime(2015, 12, 14, 13, 23, 35), + ) + self.assertEqual( + self.combined_status.sha, "74e70119a23fa3ffb3db19d4590eccfebd72b659" + ) self.assertEqual(self.combined_status.total_count, 6) self.assertEqual(self.combined_status.repository.id, 10391073) self.assertEqual(self.combined_status.repository.full_name, "edx/edx-platform") - self.assertEqual(self.combined_status.commit_url, "https://api.github.com/repos/edx/edx-platform/commits/74e70119a23fa3ffb3db19d4590eccfebd72b659") - self.assertEqual(self.combined_status.url, "https://api.github.com/repos/edx/edx-platform/commits/74e70119a23fa3ffb3db19d4590eccfebd72b659/status") + self.assertEqual( + self.combined_status.commit_url, + "https://api.github.com/repos/edx/edx-platform/commits/74e70119a23fa3ffb3db19d4590eccfebd72b659", + ) + self.assertEqual( + self.combined_status.url, + "https://api.github.com/repos/edx/edx-platform/commits/74e70119a23fa3ffb3db19d4590eccfebd72b659/status", + ) # test __repr__() based on this attributes - self.assertEqual(self.combined_status.__repr__(), - 'CommitCombinedStatus(state="success", sha="74e70119a23fa3ffb3db19d4590eccfebd72b659")') + self.assertEqual( + self.combined_status.__repr__(), + 'CommitCombinedStatus(state="success", sha="74e70119a23fa3ffb3db19d4590eccfebd72b659")', + ) diff --git a/tests/CommitComment.py b/tests/CommitComment.py index 5cbb3cbc..49911db7 100644 --- a/tests/CommitComment.py +++ b/tests/CommitComment.py @@ -30,10 +30,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class CommitComment(Framework.TestCase): def setUp(self): @@ -42,20 +43,34 @@ class CommitComment(Framework.TestCase): def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") - self.assertEqual(self.comment.commit_id, "6945921c529be14c3a8f566dd1e483674516d46d") - self.assertEqual(self.comment.created_at, datetime.datetime(2012, 5, 22, 18, 40, 18)) - self.assertEqual(self.comment.html_url, "https://github.com/jacquev6/PyGithub/commit/6945921c529be14c3a8f566dd1e483674516d46d#commitcomment-1361949") + self.assertEqual( + self.comment.commit_id, "6945921c529be14c3a8f566dd1e483674516d46d" + ) + self.assertEqual( + self.comment.created_at, datetime.datetime(2012, 5, 22, 18, 40, 18) + ) + self.assertEqual( + self.comment.html_url, + "https://github.com/jacquev6/PyGithub/commit/6945921c529be14c3a8f566dd1e483674516d46d#commitcomment-1361949", + ) self.assertEqual(self.comment.id, 1361949) self.assertEqual(self.comment.line, None) 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.assertEqual(self.comment.url, "https://api.github.com/repos/jacquev6/PyGithub/comments/1361949") + self.assertEqual( + self.comment.updated_at, datetime.datetime(2012, 5, 22, 18, 40, 18) + ) + self.assertEqual( + self.comment.url, + "https://api.github.com/repos/jacquev6/PyGithub/comments/1361949", + ) self.assertEqual(self.comment.user.login, "jacquev6") # test __repr__() based on this attributes - self.assertEqual(self.comment.__repr__(), - 'CommitComment(user=NamedUser(login="jacquev6"), id=1361949)') + self.assertEqual( + self.comment.__repr__(), + 'CommitComment(user=NamedUser(login="jacquev6"), id=1361949)', + ) def testEdit(self): self.comment.edit("Comment edited by PyGithub") diff --git a/tests/CommitStatus.py b/tests/CommitStatus.py index 50be17ae..84c76d5a 100644 --- a/tests/CommitStatus.py +++ b/tests/CommitStatus.py @@ -31,29 +31,46 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class CommitStatus(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.statuses = list(self.g.get_user().get_repo("PyGithub").get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a").get_statuses()) + self.statuses = list( + self.g.get_user() + .get_repo("PyGithub") + .get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + .get_statuses() + ) def testAttributes(self): - self.assertEqual(self.statuses[0].created_at, datetime.datetime(2012, 9, 8, 11, 30, 56)) - self.assertEqual(self.statuses[0].updated_at, datetime.datetime(2012, 9, 8, 11, 30, 56)) + self.assertEqual( + self.statuses[0].created_at, datetime.datetime(2012, 9, 8, 11, 30, 56) + ) + self.assertEqual( + self.statuses[0].updated_at, datetime.datetime(2012, 9, 8, 11, 30, 56) + ) self.assertEqual(self.statuses[0].creator.login, "jacquev6") - self.assertEqual(self.statuses[0].description, "Status successfuly created by PyGithub") + self.assertEqual( + self.statuses[0].description, "Status successfuly created by PyGithub" + ) self.assertEqual(self.statuses[1].description, None) self.assertEqual(self.statuses[0].id, 277040) self.assertEqual(self.statuses[0].state, "success") self.assertEqual(self.statuses[1].state, "pending") self.assertEqual(self.statuses[0].context, "build") - self.assertEqual(self.statuses[0].target_url, "https://github.com/jacquev6/PyGithub/issues/67") + self.assertEqual( + self.statuses[0].target_url, + "https://github.com/jacquev6/PyGithub/issues/67", + ) self.assertEqual(self.statuses[1].target_url, None) # test __repr__() based on this attributes - self.assertEqual(self.statuses[0].__repr__(), - 'CommitStatus(state="success", id=277040, context="build")') + self.assertEqual( + self.statuses[0].__repr__(), + 'CommitStatus(state="success", id=277040, context="build")', + ) diff --git a/tests/ConditionalRequestUpdate.py b/tests/ConditionalRequestUpdate.py index 799a30ce..16c7acfb 100644 --- a/tests/ConditionalRequestUpdate.py +++ b/tests/ConditionalRequestUpdate.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -37,10 +38,15 @@ class ConditionalRequestUpdate(Framework.TestCase): self.repo = self.g.get_repo("akfish/PyGithub", lazy=False) def testDidNotUpdate(self): - self.assertFalse(self.repo.update(), msg="The repo is not changed. But update() != False") + self.assertFalse( + self.repo.update(), msg="The repo is not changed. But update() != False" + ) def testDidUpdate(self): - self.assertTrue(self.repo.update(), msg="The repo should be changed by now. But update() != True") + self.assertTrue( + self.repo.update(), + msg="The repo should be changed by now. But update() != True", + ) def testUpdateObjectWithoutEtag(self): r = self.g.get_repo("jacquev6/PyGithub", lazy=False) diff --git a/tests/Connection.py b/tests/Connection.py index 31ed0eb8..f3d1db07 100644 --- a/tests/Connection.py +++ b/tests/Connection.py @@ -27,16 +27,17 @@ from __future__ import absolute_import import itertools import unittest from io import StringIO -try: - from unittest.mock import Mock -except ImportError: - from mock import Mock import httpretty from parameterized import parameterized from . import Framework +try: + from unittest.mock import Mock +except ImportError: + from mock import Mock + PARAMETERS = itertools.product( [ @@ -45,20 +46,20 @@ PARAMETERS = itertools.product( ], [ ( - "{\"body\":\"BODY TEXT\"}", - '\nGET\napi.github.com\nNone\n/user\n{\'Authorization\': \'Basic login_and_password_removed\', \'User-Agent\': \'PyGithub/Python\'}\nNone\n200\n[]\n{"body":"BODY TEXT"}\n\n', + '{"body":"BODY TEXT"}', + "\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\n{\"body\":\"BODY TEXT\"}\n\n", ), ( - u"{\"body\":\"BODY\xa0TEXT\"}", - u'\nGET\napi.github.com\nNone\n/user\n{\'Authorization\': \'Basic login_and_password_removed\', \'User-Agent\': \'PyGithub/Python\'}\nNone\n200\n[]\n{"body":"BODY\xa0TEXT"}\n\n', + u'{"body":"BODY\xa0TEXT"}', + u"\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\n{\"body\":\"BODY\xa0TEXT\"}\n\n", ), ( "BODY TEXT", - '\nGET\napi.github.com\nNone\n/user\n{\'Authorization\': \'Basic login_and_password_removed\', \'User-Agent\': \'PyGithub/Python\'}\nNone\n200\n[]\nBODY TEXT\n\n', + "\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\nBODY TEXT\n\n", ), ( u"BODY\xa0TEXT", - u'\nGET\napi.github.com\nNone\n/user\n{\'Authorization\': \'Basic login_and_password_removed\', \'User-Agent\': \'PyGithub/Python\'}\nNone\n200\n[]\nBODY\xa0TEXT\n\n', + u"\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\nBODY\xa0TEXT\n\n", ), ], ) @@ -72,12 +73,14 @@ class RecordingMockConnection(Framework.RecordingConnection): class Connection(unittest.TestCase): @parameterized.expand(itertools.chain(*p) for p in PARAMETERS) - def testRecordAndReplay(self, replaying_connection_class, protocol, response_body, expected_recording): + def testRecordAndReplay( + self, replaying_connection_class, protocol, response_body, expected_recording + ): file = StringIO() host = "api.github.com" verb = "GET" url = "/user" - headers = {'Authorization': 'Basic p4ssw0rd', 'User-Agent': 'PyGithub/Python'} + headers = {"Authorization": "Basic p4ssw0rd", "User-Agent": "PyGithub/Python"} response = Mock() response.status = 200 @@ -88,7 +91,9 @@ class Connection(unittest.TestCase): connection.getresponse.return_value = response # write mock response to buffer - recording_connection = RecordingMockConnection(file, protocol, host, None, lambda *args, **kwds: connection) + recording_connection = RecordingMockConnection( + file, protocol, host, None, lambda *args, **kwds: connection + ) recording_connection.request(verb, url, None, headers) recording_connection.getresponse() recording_connection.close() @@ -97,7 +102,9 @@ class Connection(unittest.TestCase): file_value_lines = file.getvalue().split("\n") expected_recording_lines = (protocol + expected_recording).split("\n") self.assertEquals(file_value_lines[:5], expected_recording_lines[:5]) - self.assertEquals(eval(file_value_lines[5]), eval(expected_recording_lines[5])) # dict literal, so keys not in guaranteed order + self.assertEquals( + eval(file_value_lines[5]), eval(expected_recording_lines[5]) + ) # dict literal, so keys not in guaranteed order self.assertEquals(file_value_lines[6:], expected_recording_lines[6:]) # required for replay to work as expected @@ -105,7 +112,9 @@ class Connection(unittest.TestCase): # rewind buffer and attempt to replay response from it file.seek(0) - replaying_connection = replaying_connection_class(self, file, host=host, port=None) + replaying_connection = replaying_connection_class( + self, file, host=host, port=None + ) replaying_connection.request(verb, url, None, headers) replaying_connection.getresponse() diff --git a/tests/ContentFile.py b/tests/ContentFile.py index a5d903d8..4b4719a4 100644 --- a/tests/ContentFile.py +++ b/tests/ContentFile.py @@ -31,6 +31,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -48,7 +49,10 @@ class ContentFile(Framework.TestCase): self.assertEqual(len(self.file.content), 10212) self.assertEqual(len(self.file.decoded_content), 7531) self.assertEqual(self.file.sha, "5628799a7d517a4aaa0c1a7004d07569cd154df0") - self.assertEqual(self.file.download_url, "https://raw.githubusercontent.com/jacquev6/PyGithub/master/README.md") + self.assertEqual( + self.file.download_url, + "https://raw.githubusercontent.com/jacquev6/PyGithub/master/README.md", + ) # test __repr__() based on this attributes self.assertEqual(self.file.__repr__(), 'ContentFile(path="ReadMe.md")') diff --git a/tests/Download.py b/tests/Download.py index 11072f10..bf258b60 100644 --- a/tests/Download.py +++ b/tests/Download.py @@ -29,10 +29,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Download(Framework.TestCase): def setUp(self): @@ -44,11 +45,16 @@ class Download(Framework.TestCase): self.assertEqual(self.download.acl, None) 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.assertEqual( + self.download.created_at, datetime.datetime(2012, 5, 22, 18, 58, 32) + ) self.assertEqual(self.download.description, None) self.assertEqual(self.download.download_count, 0) self.assertEqual(self.download.expirationdate, None) - self.assertEqual(self.download.html_url, "https://github.com/downloads/jacquev6/PyGithub/Foobar.txt") + self.assertEqual( + self.download.html_url, + "https://github.com/downloads/jacquev6/PyGithub/Foobar.txt", + ) self.assertEqual(self.download.id, 242550) self.assertEqual(self.download.mime_type, None) self.assertEqual(self.download.name, "Foobar.txt") @@ -59,10 +65,13 @@ class Download(Framework.TestCase): self.assertEqual(self.download.s3_url, None) self.assertEqual(self.download.signature, None) self.assertEqual(self.download.size, 1024) - self.assertEqual(self.download.url, "https://api.github.com/repos/jacquev6/PyGithub/downloads/242550") + self.assertEqual( + self.download.url, + "https://api.github.com/repos/jacquev6/PyGithub/downloads/242550", + ) # test __repr__() based on this attributes - self.assertEqual(self.download.__repr__(), 'Download(id=242550)') + self.assertEqual(self.download.__repr__(), "Download(id=242550)") def testDelete(self): self.download.delete() diff --git a/tests/Enterprise.py b/tests/Enterprise.py index 81e441fe..35627947 100644 --- a/tests/Enterprise.py +++ b/tests/Enterprise.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + import github from . import Framework @@ -36,24 +37,122 @@ from . import Framework # Replay data for this test case is forged, because I don't have access to a real Github Enterprise install class Enterprise(Framework.BasicTestCase): def testHttps(self): - g = github.Github(self.login, self.password, base_url="https://my.enterprise.com") - self.assertListKeyEqual(g.get_user().get_repos(), lambda r: r.name, ["TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + g = github.Github( + self.login, self.password, base_url="https://my.enterprise.com" + ) + self.assertListKeyEqual( + g.get_user().get_repos(), + lambda r: r.name, + [ + "TestPyGithub", + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "Hacking", + "vincent-jacques.net", + "Contests", + "Candidates", + "Tests", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) def testHttp(self): - g = github.Github(self.login, self.password, base_url="http://my.enterprise.com") - self.assertListKeyEqual(g.get_user().get_repos(), lambda r: r.name, ["TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + g = github.Github( + self.login, self.password, base_url="http://my.enterprise.com" + ) + self.assertListKeyEqual( + g.get_user().get_repos(), + lambda r: r.name, + [ + "TestPyGithub", + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "Hacking", + "vincent-jacques.net", + "Contests", + "Candidates", + "Tests", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) - def testUnknownUrlScheme(self): # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument + def testUnknownUrlScheme( + self, + ): # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument with self.assertRaises(AssertionError) as raisedexp: - github.Github(self.login, self.password, base_url="foobar://my.enterprise.com") + github.Github( + self.login, self.password, base_url="foobar://my.enterprise.com" + ) self.assertEqual(raisedexp.exception.args[0], "Unknown URL scheme") def testLongUrl(self): - g = github.Github(self.login, self.password, base_url="http://my.enterprise.com/path/to/github") + g = github.Github( + self.login, + self.password, + base_url="http://my.enterprise.com/path/to/github", + ) repos = g.get_user().get_repos() - self.assertListKeyEqual(repos, lambda r: r.name, ["TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + self.assertListKeyEqual( + repos, + lambda r: r.name, + [ + "TestPyGithub", + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "Hacking", + "vincent-jacques.net", + "Contests", + "Candidates", + "Tests", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) self.assertEqual(repos[0].owner.name, "Vincent Jacques") def testSpecificPort(self): - g = github.Github(self.login, self.password, base_url="http://my.enterprise.com:8080") - self.assertListKeyEqual(g.get_user().get_repos(), lambda r: r.name, ["TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + g = github.Github( + self.login, self.password, base_url="http://my.enterprise.com:8080" + ) + self.assertListKeyEqual( + g.get_user().get_repos(), + lambda r: r.name, + [ + "TestPyGithub", + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "Hacking", + "vincent-jacques.net", + "Contests", + "Candidates", + "Tests", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) diff --git a/tests/Equality.py b/tests/Equality.py index 9b11d6df..223f1b41 100755 --- a/tests/Equality.py +++ b/tests/Equality.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Event.py b/tests/Event.py index 5cb4ec6a..973461c9 100644 --- a/tests/Event.py +++ b/tests/Event.py @@ -29,10 +29,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Event(Framework.TestCase): def setUp(self): @@ -41,13 +42,137 @@ 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.assertEqual( + self.event.created_at, datetime.datetime(2012, 5, 26, 10, 1, 39) + ) self.assertEqual(self.event.id, "1556114751") self.assertEqual(self.event.org, None) - self.assertEqual(self.event.payload, {'commits': [{'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/5bb654d26dd014d36794acd1e6ecf3736f12aad7', 'sha': '5bb654d26dd014d36794acd1e6ecf3736f12aad7', 'message': 'Implement the three authentication schemes', 'distinct': False, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/cb0313157bf904f2d364377d35d9397b269547a5', 'sha': 'cb0313157bf904f2d364377d35d9397b269547a5', 'message': "Merge branch 'topic/Authentication' into develop", 'distinct': False, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/0cec0d25e606c023a62a4fc7cdc815309ebf6d16', 'sha': '0cec0d25e606c023a62a4fc7cdc815309ebf6d16', 'message': 'Publish version 0.7', 'distinct': False, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7', 'sha': 'ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7', 'message': "Merge branch 'develop'", 'distinct': False, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/3a3bf4763192ee1234eb0557628133e06f3dfc76', 'sha': '3a3bf4763192ee1234eb0557628133e06f3dfc76', 'message': "Merge branch 'master' into topic/RewriteWithGeneratedCode\n\nConflicts:\n\tgithub/Github.py\n\tgithub/Requester.py", 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/608f17794664f61693a3dc05e6056fea8fbef0ff', 'sha': '608f17794664f61693a3dc05e6056fea8fbef0ff', 'message': 'Restore some form of Authorization header in replay data', 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/2c04b8adbd91d38eef4f0767337ab7a12b2f684b', 'sha': '2c04b8adbd91d38eef4f0767337ab7a12b2f684b', 'message': 'Allow test without pre-set-up Github', 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/5b97389988b6fe43e15a079702f6f1671257fb28', 'sha': '5b97389988b6fe43e15a079702f6f1671257fb28', 'message': 'Test three authentication schemes', 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/12747613c5ec00deccf296b8619ad507f7050475', 'sha': '12747613c5ec00deccf296b8619ad507f7050475', 'message': 'Test Issue.getComments', 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/2982fa96c5ca75abe717d974d83f9135d664232e', 'sha': '2982fa96c5ca75abe717d974d83f9135d664232e', 'message': 'Test the new Repository.full_name attribute', 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}, {'url': 'https://api.github.com/repos/jacquev6/PyGithub/commits/619eae8d51c5988f0d2889fc767fa677438ba95d', 'sha': '619eae8d51c5988f0d2889fc767fa677438ba95d', 'message': 'Improve coverage of AuthenticatedUser', 'distinct': True, 'author': {'name': 'Vincent Jacques', 'email': 'vincent@vincent-jacques.net'}}], 'head': '619eae8d51c5988f0d2889fc767fa677438ba95d', 'push_id': 80673538, 'ref': 'refs/heads/topic/RewriteWithGeneratedCode', 'size': 11}) + self.assertEqual( + self.event.payload, + { + "commits": [ + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/5bb654d26dd014d36794acd1e6ecf3736f12aad7", + "sha": "5bb654d26dd014d36794acd1e6ecf3736f12aad7", + "message": "Implement the three authentication schemes", + "distinct": False, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/cb0313157bf904f2d364377d35d9397b269547a5", + "sha": "cb0313157bf904f2d364377d35d9397b269547a5", + "message": "Merge branch 'topic/Authentication' into develop", + "distinct": False, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/0cec0d25e606c023a62a4fc7cdc815309ebf6d16", + "sha": "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", + "message": "Publish version 0.7", + "distinct": False, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", + "sha": "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", + "message": "Merge branch 'develop'", + "distinct": False, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/3a3bf4763192ee1234eb0557628133e06f3dfc76", + "sha": "3a3bf4763192ee1234eb0557628133e06f3dfc76", + "message": "Merge branch 'master' into topic/RewriteWithGeneratedCode\n\nConflicts:\n\tgithub/Github.py\n\tgithub/Requester.py", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/608f17794664f61693a3dc05e6056fea8fbef0ff", + "sha": "608f17794664f61693a3dc05e6056fea8fbef0ff", + "message": "Restore some form of Authorization header in replay data", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/2c04b8adbd91d38eef4f0767337ab7a12b2f684b", + "sha": "2c04b8adbd91d38eef4f0767337ab7a12b2f684b", + "message": "Allow test without pre-set-up Github", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/5b97389988b6fe43e15a079702f6f1671257fb28", + "sha": "5b97389988b6fe43e15a079702f6f1671257fb28", + "message": "Test three authentication schemes", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/12747613c5ec00deccf296b8619ad507f7050475", + "sha": "12747613c5ec00deccf296b8619ad507f7050475", + "message": "Test Issue.getComments", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/2982fa96c5ca75abe717d974d83f9135d664232e", + "sha": "2982fa96c5ca75abe717d974d83f9135d664232e", + "message": "Test the new Repository.full_name attribute", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + { + "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/619eae8d51c5988f0d2889fc767fa677438ba95d", + "sha": "619eae8d51c5988f0d2889fc767fa677438ba95d", + "message": "Improve coverage of AuthenticatedUser", + "distinct": True, + "author": { + "name": "Vincent Jacques", + "email": "vincent@vincent-jacques.net", + }, + }, + ], + "head": "619eae8d51c5988f0d2889fc767fa677438ba95d", + "push_id": 80673538, + "ref": "refs/heads/topic/RewriteWithGeneratedCode", + "size": 11, + }, + ) self.assertTrue(self.event.public) self.assertEqual(self.event.repo.name, "jacquev6/PyGithub") self.assertEqual(self.event.type, "PushEvent") # test __repr__() based on this attributes - self.assertEqual(self.event.__repr__(), 'Event(type="PushEvent", id="1556114751")') + self.assertEqual( + self.event.__repr__(), 'Event(type="PushEvent", id="1556114751")' + ) diff --git a/tests/Exceptions.py b/tests/Exceptions.py index acd34480..a593478c 100644 --- a/tests/Exceptions.py +++ b/tests/Exceptions.py @@ -32,13 +32,15 @@ ################################################################################ from __future__ import absolute_import -import github -from github.GithubException import IncompletableObject + import pickle -from . import Framework +import github +from github.GithubException import IncompletableObject from six.moves import range +from . import Framework + class Exceptions(Framework.TestCase): def testInvalidInput(self): @@ -46,17 +48,18 @@ class Exceptions(Framework.TestCase): self.g.get_user().create_key("Bad key", "xxx") self.assertEqual(raisedexp.exception.status, 422) self.assertEqual( - raisedexp.exception.data, { + raisedexp.exception.data, + { "errors": [ { "code": "custom", "field": "key", "message": "key is invalid. It must begin with 'ssh-rsa' or 'ssh-dss'. Check that you're copying the public half of the key", - "resource": "PublicKey" + "resource": "PublicKey", } ], - "message": "Validation Failed" - } + "message": "Validation Failed", + }, ) def testNonJsonDataReturnedByGithub(self): @@ -68,7 +71,7 @@ class Exceptions(Framework.TestCase): raisedexp.exception.data, { "data": "

503 Service Unavailable

No server is available to handle this request.", - } + }, ) def testUnknownObject(self): @@ -93,21 +96,34 @@ class Exceptions(Framework.TestCase): self.assertEqual(str(raisedexp.exception), '401 {"message": "Bad credentials"}') def testExceptionPickling(self): - pickle.loads(pickle.dumps(github.GithubException('foo', 'bar'))) + pickle.loads(pickle.dumps(github.GithubException("foo", "bar"))) class SpecificExceptions(Framework.TestCase): def testBadCredentials(self): - self.assertRaises(github.BadCredentialsException, lambda: github.Github("BadUser", "BadPassword").get_user().login) + self.assertRaises( + github.BadCredentialsException, + lambda: github.Github("BadUser", "BadPassword").get_user().login, + ) def test2FARequired(self): - self.assertRaises(github.TwoFactorException, lambda: github.Github("2fauser", "password").get_user().login) + self.assertRaises( + github.TwoFactorException, + lambda: github.Github("2fauser", "password").get_user().login, + ) def testUnknownObject(self): - self.assertRaises(github.UnknownObjectException, lambda: self.g.get_user().get_repo("Xxx")) + self.assertRaises( + github.UnknownObjectException, lambda: self.g.get_user().get_repo("Xxx") + ) def testBadUserAgent(self): - self.assertRaises(github.BadUserAgentException, lambda: github.Github(self.login, self.password, user_agent="").get_user().name) + self.assertRaises( + github.BadUserAgentException, + lambda: github.Github(self.login, self.password, user_agent="") + .get_user() + .name, + ) def testRateLimitExceeded(self): g = github.Github() @@ -119,7 +135,6 @@ class SpecificExceptions(Framework.TestCase): self.assertRaises(github.RateLimitExceededException, exceed) def testAuthenticatedRateLimitExceeded(self): - def exceed(): for i in range(100): res = self.g.search_code("jacquev6") diff --git a/tests/ExposeAllAttributes.py b/tests/ExposeAllAttributes.py index 22161deb..23550640 100644 --- a/tests/ExposeAllAttributes.py +++ b/tests/ExposeAllAttributes.py @@ -25,11 +25,12 @@ # # ################################################################################ -from __future__ import absolute_import -from __future__ import print_function -from . import Framework +from __future__ import absolute_import, print_function + import six +from . import Framework + class ExposeAllAttributes(Framework.TestCase): def testAllClasses(self): @@ -47,7 +48,9 @@ class ExposeAllAttributes(Framework.TestCase): gistComment = gist.get_comment(4565) gistFile = gist.files[".gitignore"] gistHistoryState = gist.history[0] - gitCommit = repository.get_git_commit("be37b8a7f3a68631c32672dcd84d9eba27438ee6") + gitCommit = repository.get_git_commit( + "be37b8a7f3a68631c32672dcd84d9eba27438ee6" + ) gitAuthor = gitCommit.author gitTree = repository.get_git_tree("6f7c2d8c66d78863f7b91792deaead619799a1ce") gitTreeElement = gitTree.tree[0] @@ -77,61 +80,65 @@ class ExposeAllAttributes(Framework.TestCase): notification = authenticatedUser.get_notification("8406712") notificationSubject = notification.subject - missingAttributes = self.gatherMissingAttributes([ - authenticatedUser, - # authorization, # Security issue if put as-is in ReplayData - # authorizationApplication, # Security issue if put as-is in ReplayData - branch, - commit, - commitComment, - commitStats, - commitStatus, - comparison, - contentFile, - # download, # Deprecated: https://github.com/blog/1302-goodbye-uploads - event, - file, - gist, - gistComment, - gistFile, - gistHistoryState, - gitAuthor, - gitBlob, - gitCommit, - gitignoreTemplate, - gitObject, - gitRef, - # gitTag, - gitTree, - gitTreeElement, - hook, - hookDescription, - hookResponse, - issue, - issueComment, - issueEvent, - issuePullRequest, - label, - milestone, - namedUser, - notification, - notificationSubject, - organization, - permissions, - plan, - pullRequest, - pullRequestComment, - # pullRequestMergeStatus, # Only obtained when merging a pull request through the API - pullRequestPart, - rateLimit, - repository, - # repositoryKey, # Security issue if put as-is in ReplayData - # tag, - team, - # userKey, # Security issue if put as-is in ReplayData - ]) + missingAttributes = self.gatherMissingAttributes( + [ + authenticatedUser, + # authorization, # Security issue if put as-is in ReplayData + # authorizationApplication, # Security issue if put as-is in ReplayData + branch, + commit, + commitComment, + commitStats, + commitStatus, + comparison, + contentFile, + # download, # Deprecated: https://github.com/blog/1302-goodbye-uploads + event, + file, + gist, + gistComment, + gistFile, + gistHistoryState, + gitAuthor, + gitBlob, + gitCommit, + gitignoreTemplate, + gitObject, + gitRef, + # gitTag, + gitTree, + gitTreeElement, + hook, + hookDescription, + hookResponse, + issue, + issueComment, + issueEvent, + issuePullRequest, + label, + milestone, + namedUser, + notification, + notificationSubject, + organization, + permissions, + plan, + pullRequest, + pullRequestComment, + # pullRequestMergeStatus, # Only obtained when merging a pull request through the API + pullRequestPart, + rateLimit, + repository, + # repositoryKey, # Security issue if put as-is in ReplayData + # tag, + team, + # userKey, # Security issue if put as-is in ReplayData + ] + ) - for className, attributesMissingInClass in sorted(six.iteritems(missingAttributes)): + for className, attributesMissingInClass in sorted( + six.iteritems(missingAttributes) + ): for attrName, value in sorted(six.iteritems(attributesMissingInClass)): print(className, attrName, "->", repr(value)) diff --git a/tests/Framework.py b/tests/Framework.py index 3416e6b4..489390dc 100644 --- a/tests/Framework.py +++ b/tests/Framework.py @@ -36,25 +36,25 @@ # # ################################################################################ -from __future__ import absolute_import -from __future__ import print_function +from __future__ import absolute_import, print_function + import io import json import os import traceback import unittest -import httpretty -from requests.structures import CaseInsensitiveDict -from urllib3.util import Url import github +import httpretty import six +from requests.structures import CaseInsensitiveDict +from urllib3.util import Url def readLine(file_): line = file_.readline() if isinstance(line, bytes): - line = line.decode('utf-8') + line = line.decode("utf-8") return line.strip() @@ -98,7 +98,7 @@ class RecordingConnection: self.__cnx = self._realConnection(host, port, *args, **kwds) def request(self, verb, url, input, headers): - print(verb, url, input, headers, end=' ') + print(verb, url, input, headers, end=" ") self.__cnx.request(verb, url, input, headers) # fixAuthorizationHeader changes the parameter directly to remove Authorization token. # however, this is the real dictionary that *will be sent* by "requests", @@ -115,7 +115,7 @@ class RecordingConnection: self.__writeLine(self.__port) self.__writeLine(url) self.__writeLine(anonymous_headers) - self.__writeLine(six.text_type(input).replace('\n', '').replace('\r', '')) + self.__writeLine(six.text_type(input).replace("\n", "").replace("\r", "")) def getresponse(self): res = self.__cnx.getresponse() @@ -136,7 +136,7 @@ class RecordingConnection: return self.__cnx.close() def __writeLine(self, line): - self.__file.write(six.text_type(line) + u'\n') + self.__file.write(six.text_type(line) + u"\n") class RecordingHttpConnection(RecordingConnection): @@ -165,14 +165,12 @@ class ReplayingConnection: self.__cnx = self._realConnection(host, port, *args, **kwds) def request(self, verb, url, input, headers): - full_url = Url(scheme=self.__protocol, host=self.__host, port=self.__port, path=url) - - httpretty.register_uri( - verb, - full_url.url, - body=self.__request_callback + full_url = Url( + scheme=self.__protocol, host=self.__host, port=self.__port, path=url ) + httpretty.register_uri(verb, full_url.url, body=self.__request_callback) + self.__cnx.request(verb, url, input, headers) def __readNextRequest(self, verb, url, input, headers): @@ -181,14 +179,21 @@ class ReplayingConnection: self.__testCase.assertEqual(verb, readLine(self.__file)) self.__testCase.assertEqual(self.__host, readLine(self.__file)) self.__testCase.assertEqual(str(self.__port), readLine(self.__file)) - self.__testCase.assertEqual(self.__splitUrl(url), self.__splitUrl(readLine(self.__file))) + self.__testCase.assertEqual( + self.__splitUrl(url), self.__splitUrl(readLine(self.__file)) + ) self.__testCase.assertEqual(headers, eval(readLine(self.__file))) expectedInput = readLine(self.__file) if isinstance(input, (str, six.text_type)): if input.startswith("{"): - self.__testCase.assertEqual(json.loads(input.replace('\n', '').replace('\r', '')), json.loads(expectedInput)) + self.__testCase.assertEqual( + json.loads(input.replace("\n", "").replace("\r", "")), + json.loads(expectedInput), + ) else: - self.__testCase.assertEqual(input.replace('\n', '').replace('\r', ''), expectedInput) + self.__testCase.assertEqual( + input.replace("\n", "").replace("\r", ""), expectedInput + ) else: # for non-string input (e.g. upload asset), let it pass. pass @@ -202,18 +207,20 @@ class ReplayingConnection: return (base, sorted(qs.split("&"))) def __request_callback(self, request, uri, response_headers): - self.__readNextRequest(self.__cnx.verb, self.__cnx.url, self.__cnx.input, self.__cnx.headers) + self.__readNextRequest( + self.__cnx.verb, self.__cnx.url, self.__cnx.input, self.__cnx.headers + ) status = int(readLine(self.__file)) self.response_headers = CaseInsensitiveDict(eval(readLine(self.__file))) - output = bytearray(readLine(self.__file), 'utf-8') + output = bytearray(readLine(self.__file), "utf-8") readLine(self.__file) # make a copy of the headers and remove the ones that interfere with the response handling adding_headers = CaseInsensitiveDict(self.response_headers) - adding_headers.pop('content-length', None) - adding_headers.pop('transfer-encoding', None) - adding_headers.pop('content-encoding', None) + adding_headers.pop("content-length", None) + adding_headers.pop("transfer-encoding", None) + adding_headers.pop("content-encoding", None) response_headers.update(adding_headers) return [status, response_headers, output] @@ -256,12 +263,19 @@ class BasicTestCase(unittest.TestCase): unittest.TestCase.setUp(self) self.__fileName = "" self.__file = None - if self.recordMode: # pragma no cover (Branch useful only when recording new tests, not used during automated tests) + if ( + self.recordMode + ): # pragma no cover (Branch useful only when recording new tests, not used during automated tests) github.Requester.Requester.injectConnectionClasses( - lambda ignored, *args, **kwds: RecordingHttpConnection(self.__openFile("w"), *args, **kwds), - lambda ignored, *args, **kwds: RecordingHttpsConnection(self.__openFile("w"), *args, **kwds) + lambda ignored, *args, **kwds: RecordingHttpConnection( + self.__openFile("w"), *args, **kwds + ), + lambda ignored, *args, **kwds: RecordingHttpsConnection( + self.__openFile("w"), *args, **kwds + ), ) import GithubCredentials + self.login = GithubCredentials.login self.password = GithubCredentials.password self.oauth_token = GithubCredentials.oauth_token @@ -271,8 +285,12 @@ class BasicTestCase(unittest.TestCase): # self.client_secret = GithubCredentials.client_secret else: github.Requester.Requester.injectConnectionClasses( - lambda ignored, *args, **kwds: ReplayingHttpConnection(self, self.__openFile("r"), *args, **kwds), - lambda ignored, *args, **kwds: ReplayingHttpsConnection(self, self.__openFile("r"), *args, **kwds) + lambda ignored, *args, **kwds: ReplayingHttpConnection( + self, self.__openFile("r"), *args, **kwds + ), + lambda ignored, *args, **kwds: ReplayingHttpsConnection( + self, self.__openFile("r"), *args, **kwds + ), ) self.login = "login" self.password = "password" @@ -292,9 +310,18 @@ class BasicTestCase(unittest.TestCase): def __openFile(self, mode): for (_, _, functionName, _) in traceback.extract_stack(): - if functionName.startswith("test") or functionName == "setUp" or functionName == "tearDown": - if functionName != "test": # because in class Hook(Framework.TestCase), method testTest calls Hook.test - fileName = os.path.join(self.replayDataFolder, self.__class__.__name__ + "." + functionName + ".txt") + if ( + functionName.startswith("test") + or functionName == "setUp" + or functionName == "tearDown" + ): + if ( + functionName != "test" + ): # because in class Hook(Framework.TestCase), method testTest calls Hook.test + fileName = os.path.join( + self.replayDataFolder, + self.__class__.__name__ + "." + functionName + ".txt", + ) if fileName != self.__fileName: self.__closeReplayFileIfNeeded() self.__fileName = fileName @@ -303,7 +330,9 @@ class BasicTestCase(unittest.TestCase): def __closeReplayFileIfNeeded(self): if self.__file is not None: - if not self.recordMode: # pragma no branch (Branch useful only when recording new tests, not used during automated tests) + if ( + not self.recordMode + ): # pragma no branch (Branch useful only when recording new tests, not used during automated tests) self.assertEqual(readLine(self.__file), "") self.__file.close() diff --git a/tests/Gist.py b/tests/Gist.py index 0685b545..1a422367 100644 --- a/tests/Gist.py +++ b/tests/Gist.py @@ -29,10 +29,12 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + +import datetime import github -import datetime + +from . import Framework class Gist(Framework.TestCase): @@ -46,7 +48,10 @@ class Gist(Framework.TestCase): self.assertEqual(gist.files["GithubAPI.lua"].filename, "GithubAPI.lua") self.assertEqual(gist.files["GithubAPI.lua"].language, "Lua") self.assertEqual(gist.files["GithubAPI.lua"].content[:10], "-- GithubA") - self.assertEqual(gist.files["GithubAPI.lua"].raw_url, "https://gist.githubusercontent.com/jacquev6/6296732/raw/88aafa25fb28e17013054a117354a37f0d78963c/GithubAPI.lua") + self.assertEqual( + gist.files["GithubAPI.lua"].raw_url, + "https://gist.githubusercontent.com/jacquev6/6296732/raw/88aafa25fb28e17013054a117354a37f0d78963c/GithubAPI.lua", + ) self.assertEqual(gist.forks, []) self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git") self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git") @@ -54,11 +59,18 @@ class Gist(Framework.TestCase): self.assertEqual(gist.history[0].change_status.additions, 793) 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)) - self.assertEqual(gist.history[0].url, "https://api.github.com/gists/6296732/c464aecd7fea16684e935607eeea7ae4f8caa0e2") + self.assertEqual( + gist.history[0].committed_at, datetime.datetime(2013, 8, 21, 16, 12, 27) + ) + self.assertEqual( + gist.history[0].url, + "https://api.github.com/gists/6296732/c464aecd7fea16684e935607eeea7ae4f8caa0e2", + ) self.assertEqual(gist.history[0].user, None) self.assertEqual(gist.history[0].owner.login, "jacquev6") - self.assertEqual(gist.history[0].version, "c464aecd7fea16684e935607eeea7ae4f8caa0e2") + self.assertEqual( + gist.history[0].version, "c464aecd7fea16684e935607eeea7ae4f8caa0e2" + ) self.assertEqual(gist.html_url, "https://gist.github.com/6296732") self.assertEqual(gist.id, "6296732") self.assertTrue(gist.public) @@ -82,7 +94,10 @@ class Gist(Framework.TestCase): def testEditWithAllParameters(self): gist = self.g.get_gist("2729810") - gist.edit("Description edited by PyGithub", {"barbaz.txt": github.InputFileContent("File also created by PyGithub")}) + gist.edit( + "Description edited by PyGithub", + {"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(set(gist.files.keys()), {"foobar.txt", "barbaz.txt"}) @@ -96,7 +111,13 @@ class Gist(Framework.TestCase): def testRenameFile(self): gist = self.g.get_gist("5339374") self.assertEqual(list(gist.files.keys()), ["bar.txt"]) - gist.edit(files={"bar.txt": github.InputFileContent(gist.files["bar.txt"].content, new_name="baz.txt")}) + gist.edit( + files={ + "bar.txt": github.InputFileContent( + gist.files["bar.txt"].content, new_name="baz.txt" + ) + } + ) self.assertEqual(list(gist.files.keys()), ["baz.txt"]) def testCreateComment(self): diff --git a/tests/GistComment.py b/tests/GistComment.py index 2d57dc38..63aba8fd 100644 --- a/tests/GistComment.py +++ b/tests/GistComment.py @@ -29,10 +29,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class GistComment(Framework.TestCase): def setUp(self): @@ -41,19 +42,30 @@ 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.assertEqual( + self.comment.created_at, datetime.datetime(2012, 5, 19, 7, 7, 57) + ) self.assertEqual(self.comment.id, 323629) - self.assertEqual(self.comment.updated_at, datetime.datetime(2012, 5, 19, 7, 7, 57)) - self.assertEqual(self.comment.url, "https://api.github.com/gists/2729810/comments/323629") + self.assertEqual( + self.comment.updated_at, datetime.datetime(2012, 5, 19, 7, 7, 57) + ) + self.assertEqual( + self.comment.url, "https://api.github.com/gists/2729810/comments/323629" + ) self.assertEqual(self.comment.user.login, "jacquev6") # test __repr__() based on this attributes - self.assertEqual(self.comment.__repr__(), 'GistComment(user=NamedUser(login="jacquev6"), id=323629)') + self.assertEqual( + self.comment.__repr__(), + 'GistComment(user=NamedUser(login="jacquev6"), id=323629)', + ) def testEdit(self): 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.assertEqual( + self.comment.updated_at, datetime.datetime(2012, 5, 19, 7, 12, 32) + ) def testDelete(self): self.comment.delete() diff --git a/tests/GitBlob.py b/tests/GitBlob.py index 69caa9b3..c2f35c99 100644 --- a/tests/GitBlob.py +++ b/tests/GitBlob.py @@ -30,23 +30,41 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class GitBlob(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.blob = self.g.get_user().get_repo("PyGithub").get_git_blob("53bce9fa919b4544e67275089b3ec5b44be20667") + self.blob = ( + self.g.get_user() + .get_repo("PyGithub") + .get_git_blob("53bce9fa919b4544e67275089b3ec5b44be20667") + ) def testAttributes(self): - self.assertTrue(self.blob.content.startswith("IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgpmcm9tIGRpc3R1dGlscy5jb3JlIGlt\ncG9ydCBzZXR1cAppbXBvcnQgdGV4dHdyYXAKCnNldHVwKAogICAgbmFtZSA9\n")) - self.assertTrue(self.blob.content.endswith("Z3JhbW1pbmcgTGFuZ3VhZ2UgOjogUHl0aG9uIiwKICAgICAgICAiVG9waWMg\nOjogU29mdHdhcmUgRGV2ZWxvcG1lbnQiLAogICAgXSwKKQo=\n")) + self.assertTrue( + self.blob.content.startswith( + "IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgpmcm9tIGRpc3R1dGlscy5jb3JlIGlt\ncG9ydCBzZXR1cAppbXBvcnQgdGV4dHdyYXAKCnNldHVwKAogICAgbmFtZSA9\n" + ) + ) + self.assertTrue( + self.blob.content.endswith( + "Z3JhbW1pbmcgTGFuZ3VhZ2UgOjogUHl0aG9uIiwKICAgICAgICAiVG9waWMg\nOjogU29mdHdhcmUgRGV2ZWxvcG1lbnQiLAogICAgXSwKKQo=\n" + ) + ) self.assertEqual(len(self.blob.content), 1757) self.assertEqual(self.blob.encoding, "base64") self.assertEqual(self.blob.size, 1295) self.assertEqual(self.blob.sha, "53bce9fa919b4544e67275089b3ec5b44be20667") - self.assertEqual(self.blob.url, "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/53bce9fa919b4544e67275089b3ec5b44be20667") + self.assertEqual( + self.blob.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/53bce9fa919b4544e67275089b3ec5b44be20667", + ) # test __repr__() based on this attributes - self.assertEqual(self.blob.__repr__(), - 'GitBlob(sha="53bce9fa919b4544e67275089b3ec5b44be20667")') + self.assertEqual( + self.blob.__repr__(), + 'GitBlob(sha="53bce9fa919b4544e67275089b3ec5b44be20667")', + ) diff --git a/tests/GitCommit.py b/tests/GitCommit.py index db7d5123..93e1382b 100644 --- a/tests/GitCommit.py +++ b/tests/GitCommit.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + import datetime from . import Framework @@ -38,23 +39,42 @@ from . import Framework class GitCommit(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.commit = self.g.get_user().get_repo("PyGithub").get_git_commit("4303c5b90e2216d927155e9609436ccb8984c495") + self.commit = ( + self.g.get_user() + .get_repo("PyGithub") + .get_git_commit("4303c5b90e2216d927155e9609436ccb8984c495") + ) def testAttributes(self): 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.assertEqual( + self.commit.author.date, datetime.datetime(2012, 4, 17, 17, 55, 16) + ) 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.assertEqual( + self.commit.committer.date, datetime.datetime(2012, 4, 17, 17, 55, 16) + ) self.assertEqual(self.commit.message, "Merge branch 'develop'\n") self.assertEqual(len(self.commit.parents), 2) - self.assertEqual(self.commit.parents[0].sha, "936f4a97f1a86392637ec002bbf89ff036a5062d") - self.assertEqual(self.commit.parents[1].sha, "2a7e80e6421c5d4d201d60619068dea6bae612cb") + self.assertEqual( + self.commit.parents[0].sha, "936f4a97f1a86392637ec002bbf89ff036a5062d" + ) + self.assertEqual( + self.commit.parents[1].sha, "2a7e80e6421c5d4d201d60619068dea6bae612cb" + ) self.assertEqual(self.commit.sha, "4303c5b90e2216d927155e9609436ccb8984c495") - self.assertEqual(self.commit.tree.sha, "f492784d8ca837779650d1fb406a1a3587a764ad") - self.assertEqual(self.commit.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/4303c5b90e2216d927155e9609436ccb8984c495") + self.assertEqual( + self.commit.tree.sha, "f492784d8ca837779650d1fb406a1a3587a764ad" + ) + self.assertEqual( + self.commit.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/commits/4303c5b90e2216d927155e9609436ccb8984c495", + ) # test __repr__() based on this attributes - self.assertEqual(self.commit.__repr__(), - 'GitCommit(sha="4303c5b90e2216d927155e9609436ccb8984c495")') + self.assertEqual( + self.commit.__repr__(), + 'GitCommit(sha="4303c5b90e2216d927155e9609436ccb8984c495")', + ) diff --git a/tests/GitMembership.py b/tests/GitMembership.py index 2659c63d..00cf2502 100644 --- a/tests/GitMembership.py +++ b/tests/GitMembership.py @@ -56,6 +56,6 @@ class GitMembership(Framework.TestCase): def testGetMembership(self): octocat = self.g.get_user("octocat") membership_data = octocat.get_organization_membership(self.org.id) - self.assertEqual('octocat', membership_data.user.login) - self.assertEqual('admin', membership_data.role) - self.assertEqual('github', membership_data.organization.login) + self.assertEqual("octocat", membership_data.user.login) + self.assertEqual("admin", membership_data.role) + self.assertEqual("github", membership_data.organization.login) diff --git a/tests/GitRef.py b/tests/GitRef.py index 84590727..2f83dbd7 100644 --- a/tests/GitRef.py +++ b/tests/GitRef.py @@ -29,24 +29,38 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class GitRef(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.ref = self.g.get_user().get_repo("PyGithub").get_git_ref("heads/BranchCreatedByPyGithub") + self.ref = ( + self.g.get_user() + .get_repo("PyGithub") + .get_git_ref("heads/BranchCreatedByPyGithub") + ) def testAttributes(self): - self.assertEqual(self.ref.object.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + self.assertEqual( + self.ref.object.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a" + ) self.assertEqual(self.ref.object.type, "commit") - self.assertEqual(self.ref.object.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a") + self.assertEqual( + self.ref.object.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", + ) self.assertEqual(self.ref.ref, "refs/heads/BranchCreatedByPyGithub") - self.assertEqual(self.ref.url, "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub") + self.assertEqual( + self.ref.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub", + ) # test __repr__() based on this attributes - self.assertEqual(self.ref.__repr__(), - 'GitRef(ref="refs/heads/BranchCreatedByPyGithub")') + self.assertEqual( + self.ref.__repr__(), 'GitRef(ref="refs/heads/BranchCreatedByPyGithub")' + ) def testEdit(self): self.ref.edit("04cde900a0775b51f762735637bd30de392a2793") diff --git a/tests/GitRelease.py b/tests/GitRelease.py index c1cb4f03..f092fbaf 100644 --- a/tests/GitRelease.py +++ b/tests/GitRelease.py @@ -35,9 +35,11 @@ ################################################################################ from __future__ import absolute_import + +import datetime import os import zipfile -import datetime + from . import Framework @@ -66,21 +68,38 @@ class Release(Framework.TestCase): self.assertEqual(self.release.id, 1210814) self.assertEqual(self.release.tag_name, "v1.25.2") self.assertEqual(self.release.target_commitish, "master") - self.assertEqual(self.release.upload_url, "https://uploads.github.com/repos/edhollandAL/PyGithub/releases/1210814/assets{?name}") + self.assertEqual( + self.release.upload_url, + "https://uploads.github.com/repos/edhollandAL/PyGithub/releases/1210814/assets{?name}", + ) self.assertEqual(self.release.body, "Body") self.assertEqual(self.release.title, "Test") self.assertEqual(self.release.draft, False) self.assertEqual(self.release.prerelease, False) - self.assertEqual(self.release.url, "https://api.github.com/repos/edhollandAL/PyGithub/releases/1210814") - self.assertEqual(self.release.author._rawData['login'], "edhollandAL") + self.assertEqual( + self.release.url, + "https://api.github.com/repos/edhollandAL/PyGithub/releases/1210814", + ) + self.assertEqual(self.release.author._rawData["login"], "edhollandAL") self.assertEqual(self.release.author.login, "edhollandAL") self.assertEqual(self.release.author.id, 11922660) self.assertEqual(self.release.author.type, "User") - self.assertEqual(self.release.html_url, "https://github.com/edhollandAL/PyGithub/releases/tag/v1.25.2") + self.assertEqual( + self.release.html_url, + "https://github.com/edhollandAL/PyGithub/releases/tag/v1.25.2", + ) self.assertEqual(self.release.created_at, datetime.datetime(2014, 10, 8, 1, 54)) - self.assertEqual(self.release.published_at, datetime.datetime(2015, 4, 24, 8, 36, 51)) - self.assertEqual(self.release.tarball_url, "https://api.github.com/repos/edhollandAL/PyGithub/tarball/v1.25.2") - self.assertEqual(self.release.zipball_url, "https://api.github.com/repos/edhollandAL/PyGithub/zipball/v1.25.2") + self.assertEqual( + self.release.published_at, datetime.datetime(2015, 4, 24, 8, 36, 51) + ) + self.assertEqual( + self.release.tarball_url, + "https://api.github.com/repos/edhollandAL/PyGithub/tarball/v1.25.2", + ) + self.assertEqual( + self.release.zipball_url, + "https://api.github.com/repos/edhollandAL/PyGithub/zipball/v1.25.2", + ) # test __repr__() based on this attributes self.assertEqual(self.release.__repr__(), 'GitRelease(title="Test")') @@ -96,21 +115,31 @@ class Release(Framework.TestCase): self.assertEqual(new_release.title, "Updated Test") def testGetRelease(self): - release_by_id = self.g.get_user().get_repo("PyGithub").get_release('v1.25.2') + release_by_id = self.g.get_user().get_repo("PyGithub").get_release("v1.25.2") release_by_tag = self.g.get_user().get_repo("PyGithub").get_release(1210837) self.assertEqual(release_by_id, release_by_tag) def testCreateGitTagAndRelease(self): self.repo = self.g.get_user().get_repo("PyGithub") - self.release = self.repo.create_git_tag_and_release('v3.0.0', 'tag message', 'release title', 'release message', '5a05a5e58f682d315acd2447c87ac5b4d4fc55e8', 'commit') + self.release = self.repo.create_git_tag_and_release( + "v3.0.0", + "tag message", + "release title", + "release message", + "5a05a5e58f682d315acd2447c87ac5b4d4fc55e8", + "commit", + ) self.assertEqual(self.release.tag_name, "v3.0.0") self.assertEqual(self.release.body, "release message") self.assertEqual(self.release.title, "release title") - self.assertEqual(self.release.author._rawData['login'], "edhollandAL") - self.assertEqual(self.release.html_url, "https://github.com/edhollandAL/PyGithub/releases/tag/v3.0.0") + self.assertEqual(self.release.author._rawData["login"], "edhollandAL") + self.assertEqual( + self.release.html_url, + "https://github.com/edhollandAL/PyGithub/releases/tag/v3.0.0", + ) def testGetLatestRelease(self): - self.repo = self.g.get_user().get_repo('PyGithub') + self.repo = self.g.get_user().get_repo("PyGithub") latest_release = self.repo.get_latest_release() self.assertEqual(latest_release.tag_name, "v1.25.2") @@ -147,9 +176,9 @@ class Release(Framework.TestCase): the_release = the_repo.get_release(release_id) self.assertEqual(the_release.id, release_id) - the_release.upload_asset(self.artifact_path, - "unit test artifact", - "application/zip") + the_release.upload_asset( + self.artifact_path, "unit test artifact", "application/zip" + ) def testUploadAssetWithName(self): release_id = 1210837 diff --git a/tests/GitReleaseAsset.py b/tests/GitReleaseAsset.py index 9a76aede..e3c074d7 100644 --- a/tests/GitReleaseAsset.py +++ b/tests/GitReleaseAsset.py @@ -25,7 +25,9 @@ ################################################################################ from __future__ import absolute_import + import datetime + from . import Framework @@ -34,6 +36,7 @@ class ReleaseAsset(Framework.TestCase): Test harness for functionality related to release assets (files attached to the github release). """ + def setUp(self): Framework.TestCase.setUp(self) # Do not get self.release here as it causes bad data to be saved in --record mode @@ -47,7 +50,10 @@ class ReleaseAsset(Framework.TestCase): asset = release.get_assets()[0] self.assertEqual(asset.id, 16) - self.assertEqual(asset.url, "https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16") + self.assertEqual( + asset.url, + "https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16", + ) self.assertEqual(asset.name, "Archive.zip") self.assertEqual(asset.label, "Installation msi & runbook zipped") self.assertEqual(asset.content_type, "application/zip") @@ -56,9 +62,15 @@ class ReleaseAsset(Framework.TestCase): self.assertEqual(asset.download_count, 2) self.assertEqual(asset.created_at, datetime.datetime(2017, 2, 1, 22, 40, 58)) self.assertEqual(asset.updated_at, datetime.datetime(2017, 2, 1, 22, 44, 58)) - self.assertEqual(asset.browser_download_url, "https://github.com/edhollandAL/PyGithub/releases/download/v1.25.2/Asset.zip") + self.assertEqual( + asset.browser_download_url, + "https://github.com/edhollandAL/PyGithub/releases/download/v1.25.2/Asset.zip", + ) self.assertEqual(asset.uploader.login, "PyGithub") - self.assertEqual(asset.__repr__(), 'GitReleaseAsset(url="https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16")') + self.assertEqual( + asset.__repr__(), + 'GitReleaseAsset(url="https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16")', + ) def testDelete(self): """ diff --git a/tests/GitTag.py b/tests/GitTag.py index a22133ab..28e22183 100644 --- a/tests/GitTag.py +++ b/tests/GitTag.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + import datetime from . import Framework @@ -38,19 +39,36 @@ from . import Framework class GitTag(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.tag = self.g.get_user().get_repo("PyGithub").get_git_tag("f5f37322407b02a80de4526ad88d5f188977bc3c") + self.tag = ( + self.g.get_user() + .get_repo("PyGithub") + .get_git_tag("f5f37322407b02a80de4526ad88d5f188977bc3c") + ) def testAttributes(self): self.assertEqual(self.tag.message, "Version 0.6\n") - self.assertEqual(self.tag.object.sha, "4303c5b90e2216d927155e9609436ccb8984c495") + self.assertEqual( + self.tag.object.sha, "4303c5b90e2216d927155e9609436ccb8984c495" + ) self.assertEqual(self.tag.object.type, "commit") - self.assertEqual(self.tag.object.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/4303c5b90e2216d927155e9609436ccb8984c495") + self.assertEqual( + self.tag.object.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/commits/4303c5b90e2216d927155e9609436ccb8984c495", + ) 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.assertEqual( + self.tag.tagger.date, datetime.datetime(2012, 5, 10, 18, 14, 15) + ) self.assertEqual(self.tag.tagger.email, "vincent@vincent-jacques.net") self.assertEqual(self.tag.tagger.name, "Vincent Jacques") - self.assertEqual(self.tag.url, "https://api.github.com/repos/jacquev6/PyGithub/git/tags/f5f37322407b02a80de4526ad88d5f188977bc3c") + self.assertEqual( + self.tag.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/tags/f5f37322407b02a80de4526ad88d5f188977bc3c", + ) # test __repr__() based on this attributes - self.assertEqual(self.tag.__repr__(), 'GitTag(tag="v0.6", sha="f5f37322407b02a80de4526ad88d5f188977bc3c")') + self.assertEqual( + self.tag.__repr__(), + 'GitTag(tag="v0.6", sha="f5f37322407b02a80de4526ad88d5f188977bc3c")', + ) diff --git a/tests/GitTree.py b/tests/GitTree.py index cd38b7f5..a0d57d3b 100644 --- a/tests/GitTree.py +++ b/tests/GitTree.py @@ -30,30 +30,51 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class GitTree(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.tree = self.g.get_user().get_repo("PyGithub").get_git_tree("f492784d8ca837779650d1fb406a1a3587a764ad") + self.tree = ( + self.g.get_user() + .get_repo("PyGithub") + .get_git_tree("f492784d8ca837779650d1fb406a1a3587a764ad") + ) def testAttributes(self): self.assertEqual(self.tree.sha, "f492784d8ca837779650d1fb406a1a3587a764ad") self.assertEqual(len(self.tree.tree), 11) self.assertEqual(self.tree.tree[0].mode, "100644") self.assertEqual(self.tree.tree[0].path, ".gitignore") - self.assertEqual(self.tree.tree[0].sha, "8a9af1462c3f4e3358315c2d2e6ef1e7334c59dd") + self.assertEqual( + self.tree.tree[0].sha, "8a9af1462c3f4e3358315c2d2e6ef1e7334c59dd" + ) self.assertEqual(self.tree.tree[0].size, 53) self.assertEqual(self.tree.tree[0].type, "blob") - self.assertEqual(self.tree.tree[0].url, "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/8a9af1462c3f4e3358315c2d2e6ef1e7334c59dd") + self.assertEqual( + self.tree.tree[0].url, + "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/8a9af1462c3f4e3358315c2d2e6ef1e7334c59dd", + ) self.assertEqual(self.tree.tree[6].mode, "040000") self.assertEqual(self.tree.tree[6].path, "ReplayDataForIntegrationTest") - self.assertEqual(self.tree.tree[6].sha, "60b4602b2c2070246c5df078fb7a5150b45815eb") + self.assertEqual( + self.tree.tree[6].sha, "60b4602b2c2070246c5df078fb7a5150b45815eb" + ) self.assertEqual(self.tree.tree[6].size, None) self.assertEqual(self.tree.tree[6].type, "tree") - self.assertEqual(self.tree.tree[6].url, "https://api.github.com/repos/jacquev6/PyGithub/git/trees/60b4602b2c2070246c5df078fb7a5150b45815eb") - self.assertEqual(self.tree.url, "https://api.github.com/repos/jacquev6/PyGithub/git/trees/f492784d8ca837779650d1fb406a1a3587a764ad") + self.assertEqual( + self.tree.tree[6].url, + "https://api.github.com/repos/jacquev6/PyGithub/git/trees/60b4602b2c2070246c5df078fb7a5150b45815eb", + ) + self.assertEqual( + self.tree.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/trees/f492784d8ca837779650d1fb406a1a3587a764ad", + ) # test __repr__() based on this attributes - self.assertEqual(self.tree.__repr__(), 'GitTree(sha="f492784d8ca837779650d1fb406a1a3587a764ad")') + self.assertEqual( + self.tree.__repr__(), + 'GitTree(sha="f492784d8ca837779650d1fb406a1a3587a764ad")', + ) diff --git a/tests/GithubIntegration.py b/tests/GithubIntegration.py index 007cc105..ff5846ad 100644 --- a/tests/GithubIntegration.py +++ b/tests/GithubIntegration.py @@ -1,13 +1,14 @@ from __future__ import absolute_import -import jwt -import json -import time # NOQA -import sys -import unittest -import requests # NOQA -import datetime -from github.GithubObject import GithubObject +import datetime +import json +import sys +import time # NOQA +import unittest + +import jwt +import requests # NOQA +from github.GithubObject import GithubObject private_key = """ -----BEGIN RSA PRIVATE KEY----- @@ -38,7 +39,6 @@ e2JtSXoAtYr6qE9maQIDAQAB class GithubIntegration(unittest.TestCase): - def setUp(self): # This flag ask requester to do some checking, # for debug and test purpose. But @@ -49,8 +49,8 @@ class GithubIntegration(unittest.TestCase): self.origin_check_after_init_flag = GithubObject.CHECK_AFTER_INIT_FLAG GithubObject.setCheckAfterInitFlag(False) - self.origin_time = sys.modules['time'].time - sys.modules['time'].time = lambda: 1550055331.7435968 + self.origin_time = sys.modules["time"].time + sys.modules["time"].time = lambda: 1550055331.7435968 class Mock(object): def __init__(self): @@ -76,9 +76,9 @@ class GithubIntegration(unittest.TestCase): self.kwargs = kwargs return self - self.origin_request_post = sys.modules['requests'].post + self.origin_request_post = sys.modules["requests"].post self.mock = Mock() - sys.modules['requests'].post = self.mock + sys.modules["requests"].post = self.mock class GetMock(object): def __init__(self): @@ -126,64 +126,60 @@ class GithubIntegration(unittest.TestCase): self.kwargs = kwargs return self - self.origin_request_get = sys.modules['requests'].get + self.origin_request_get = sys.modules["requests"].get self.get_mock = GetMock() - sys.modules['requests'].get = self.get_mock + sys.modules["requests"].get = self.get_mock def testCreateJWT(self): from github import GithubIntegration + integration = GithubIntegration(25216, private_key) token = integration.create_jwt() payload = jwt.decode( - token, - key=public_key, - algorithm="RS256", - options={'verify_exp': False}, + token, key=public_key, algorithm="RS256", options={"verify_exp": False}, ) self.assertDictEqual( - payload, - { - 'iat': 1550055331, - 'exp': 1550055391, - 'iss': 25216 - } + payload, {"iat": 1550055331, "exp": 1550055391, "iss": 25216} ) def testGetAccessToken(self): from github import GithubIntegration + integration = GithubIntegration(25216, private_key) auth_obj = integration.get_access_token(664281) self.assertEqual( self.mock.args[0], - "https://api.github.com/app/installations/664281/access_tokens" - ) - self.assertEqual( - auth_obj.token, "v1.ce63424bc55028318325caac4f4c3a5378ca0038" + "https://api.github.com/app/installations/664281/access_tokens", ) + self.assertEqual(auth_obj.token, "v1.ce63424bc55028318325caac4f4c3a5378ca0038") self.assertEqual( auth_obj.expires_at, datetime.datetime(2019, 2, 13, 11, 10, 38) ) def test_get_installation(self): from github import GithubIntegration + integr = GithubIntegration("11111", private_key) inst = integr.get_installation("foo", "bar") self.assertEqual( self.get_mock.calls[0][0], - ('https://api.github.com/repos/foo/bar/installation',)) + ("https://api.github.com/repos/foo/bar/installation",), + ) self.assertEqual(inst.id.value, 111111) def test_get_installation_custom_base_url(self): from github import GithubIntegration - integr = GithubIntegration("11111", private_key, base_url='https://corp.com/v3') + + integr = GithubIntegration("11111", private_key, base_url="https://corp.com/v3") inst = integr.get_installation("foo", "bar") self.assertEqual( self.get_mock.calls[0][0], - ('https://corp.com/v3/repos/foo/bar/installation',)) + ("https://corp.com/v3/repos/foo/bar/installation",), + ) self.assertEqual(inst.id.value, 111111) def tearDown(self): GithubObject.setCheckAfterInitFlag(self.origin_check_after_init_flag) - sys.modules['time'].time = self.origin_time - sys.modules['requests'].post = self.origin_request_post - sys.modules['requests'].get = self.origin_request_get + sys.modules["time"].time = self.origin_time + sys.modules["requests"].post = self.origin_request_post + sys.modules["requests"].get = self.origin_request_get diff --git a/tests/Github_.py b/tests/Github_.py index 5bf97f2f..199f8108 100644 --- a/tests/Github_.py +++ b/tests/Github_.py @@ -33,21 +33,139 @@ ################################################################################ from __future__ import absolute_import + import datetime -from . import Framework - -from . import Time - import github +from . import Framework, Time + class Github(Framework.TestCase): def testGetGists(self): - self.assertListKeyBegin(self.g.get_gists(), lambda g: g.id, ["2729695", "2729656", "2729597", "2729584", "2729569", "2729554", "2729543", "2729537", "2729536", "2729533", "2729525", "2729522", "2729519", "2729515", "2729506", "2729487", "2729484", "2729482", "2729441", "2729432", "2729420", "2729398", "2729372", "2729371", "2729351", "2729346", "2729316", "2729304", "2729296", "2729276", "2729272", "2729265", "2729195", "2729160", "2729143", "2729127", "2729119", "2729113", "2729103", "2729069", "2729059", "2729051", "2729029", "2729027", "2729026", "2729022", "2729002", "2728985", "2728979", "2728964", "2728937", "2728933", "2728884", "2728869", "2728866", "2728855", "2728854", "2728853", "2728846", "2728825", "2728814", "2728813", "2728812", "2728805", "2728802", "2728800", "2728798", "2728797", "2728796", "2728793", "2728758", "2728754", "2728751", "2728748", "2728721", "2728716", "2728715", "2728705", "2728701", "2728699", "2728697", "2728688", "2728683", "2728677", "2728649", "2728640", "2728625", "2728620", "2728615", "2728614", "2728565", "2728564", "2728554", "2728523", "2728519", "2728511", "2728497", "2728496", "2728495", "2728487"]) + self.assertListKeyBegin( + self.g.get_gists(), + lambda g: g.id, + [ + "2729695", + "2729656", + "2729597", + "2729584", + "2729569", + "2729554", + "2729543", + "2729537", + "2729536", + "2729533", + "2729525", + "2729522", + "2729519", + "2729515", + "2729506", + "2729487", + "2729484", + "2729482", + "2729441", + "2729432", + "2729420", + "2729398", + "2729372", + "2729371", + "2729351", + "2729346", + "2729316", + "2729304", + "2729296", + "2729276", + "2729272", + "2729265", + "2729195", + "2729160", + "2729143", + "2729127", + "2729119", + "2729113", + "2729103", + "2729069", + "2729059", + "2729051", + "2729029", + "2729027", + "2729026", + "2729022", + "2729002", + "2728985", + "2728979", + "2728964", + "2728937", + "2728933", + "2728884", + "2728869", + "2728866", + "2728855", + "2728854", + "2728853", + "2728846", + "2728825", + "2728814", + "2728813", + "2728812", + "2728805", + "2728802", + "2728800", + "2728798", + "2728797", + "2728796", + "2728793", + "2728758", + "2728754", + "2728751", + "2728748", + "2728721", + "2728716", + "2728715", + "2728705", + "2728701", + "2728699", + "2728697", + "2728688", + "2728683", + "2728677", + "2728649", + "2728640", + "2728625", + "2728620", + "2728615", + "2728614", + "2728565", + "2728564", + "2728554", + "2728523", + "2728519", + "2728511", + "2728497", + "2728496", + "2728495", + "2728487", + ], + ) def testGetGistsWithSince(self): - self.assertListKeyBegin(self.g.get_gists(since=datetime.datetime(2018, 10, 2, 10, 38, 30, 00, tzinfo=Time.UTCtzinfo())), lambda g: g.id, ["69b8a5831b74946db944c5451017fa40", "c22050a8705e93d170e0d4ca9c02e40c", "a7a95e1a194e07960364a5b32c56ac5f", "a25d9ace89b574f95bf0724f95a84fc2", "3195465"]) + self.assertListKeyBegin( + self.g.get_gists( + since=datetime.datetime( + 2018, 10, 2, 10, 38, 30, 00, tzinfo=Time.UTCtzinfo() + ) + ), + lambda g: g.id, + [ + "69b8a5831b74946db944c5451017fa40", + "c22050a8705e93d170e0d4ca9c02e40c", + "a7a95e1a194e07960364a5b32c56ac5f", + "a25d9ace89b574f95bf0724f95a84fc2", + "3195465", + ], + ) def testGetHooks(self): hooks = self.g.get_hooks() @@ -55,68 +173,345 @@ class Github(Framework.TestCase): self.assertEqual(hook.name, "activecollab") self.assertEqual(hook.supported_events, ["push"]) self.assertEqual(hook.events, ["push"]) - self.assertEqual(hook.schema, [["string", "url"], ["string", "token"], ["string", "project_id"], ["string", "milestone_id"], ["string", "category_id"]]) + self.assertEqual( + hook.schema, + [ + ["string", "url"], + ["string", "token"], + ["string", "project_id"], + ["string", "milestone_id"], + ["string", "category_id"], + ], + ) def testGetEmojis(self): emojis = self.g.get_emojis() first = emojis.get("+1") - self.assertEqual(first, "https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5") + self.assertEqual( + first, "https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5" + ) def testGetHook(self): hook = self.g.get_hook("activecollab") self.assertEqual(hook.name, "activecollab") self.assertEqual(hook.supported_events, ["push"]) self.assertEqual(hook.events, ["push"]) - self.assertEqual(hook.schema, [["string", "url"], ["string", "token"], ["string", "project_id"], ["string", "milestone_id"], ["string", "category_id"]]) + self.assertEqual( + hook.schema, + [ + ["string", "url"], + ["string", "token"], + ["string", "project_id"], + ["string", "milestone_id"], + ["string", "category_id"], + ], + ) def testGetRepoFromFullName(self): - self.assertEqual(self.g.get_repo("jacquev6/PyGithub").description, "Python library implementing the full Github API v3") + self.assertEqual( + self.g.get_repo("jacquev6/PyGithub").description, + "Python library implementing the full Github API v3", + ) def testGetRepoFromId(self): - self.assertEqual(self.g.get_repo(3544490).description, "Python library implementing the full Github API v3") + self.assertEqual( + self.g.get_repo(3544490).description, + "Python library implementing the full Github API v3", + ) def testGetGitignoreTemplates(self): - self.assertEqual(self.g.get_gitignore_templates(), ["Actionscript", "Android", "AppceleratorTitanium", "Autotools", "Bancha", "C", "C++", "CFWheels", "CMake", "CSharp", "CakePHP", "Clojure", "CodeIgniter", "Compass", "Concrete5", "Coq", "Delphi", "Django", "Drupal", "Erlang", "ExpressionEngine", "Finale", "ForceDotCom", "FuelPHP", "GWT", "Go", "Grails", "Haskell", "Java", "Jboss", "Jekyll", "Joomla", "Jython", "Kohana", "LaTeX", "Leiningen", "LemonStand", "Lilypond", "Lithium", "Magento", "Maven", "Node", "OCaml", "Objective-C", "Opa", "OracleForms", "Perl", "PlayFramework", "Python", "Qooxdoo", "Qt", "R", "Rails", "RhodesRhomobile", "Ruby", "Scala", "Sdcc", "SeamGen", "SketchUp", "SugarCRM", "Symfony", "Symfony2", "SymphonyCMS", "Target3001", "Tasm", "Textpattern", "TurboGears2", "Unity", "VB.Net", "Waf", "Wordpress", "Yii", "ZendFramework", "gcov", "nanoc", "opencart"]) + self.assertEqual( + self.g.get_gitignore_templates(), + [ + "Actionscript", + "Android", + "AppceleratorTitanium", + "Autotools", + "Bancha", + "C", + "C++", + "CFWheels", + "CMake", + "CSharp", + "CakePHP", + "Clojure", + "CodeIgniter", + "Compass", + "Concrete5", + "Coq", + "Delphi", + "Django", + "Drupal", + "Erlang", + "ExpressionEngine", + "Finale", + "ForceDotCom", + "FuelPHP", + "GWT", + "Go", + "Grails", + "Haskell", + "Java", + "Jboss", + "Jekyll", + "Joomla", + "Jython", + "Kohana", + "LaTeX", + "Leiningen", + "LemonStand", + "Lilypond", + "Lithium", + "Magento", + "Maven", + "Node", + "OCaml", + "Objective-C", + "Opa", + "OracleForms", + "Perl", + "PlayFramework", + "Python", + "Qooxdoo", + "Qt", + "R", + "Rails", + "RhodesRhomobile", + "Ruby", + "Scala", + "Sdcc", + "SeamGen", + "SketchUp", + "SugarCRM", + "Symfony", + "Symfony2", + "SymphonyCMS", + "Target3001", + "Tasm", + "Textpattern", + "TurboGears2", + "Unity", + "VB.Net", + "Waf", + "Wordpress", + "Yii", + "ZendFramework", + "gcov", + "nanoc", + "opencart", + ], + ) def testGetGitignoreTemplate(self): t = self.g.get_gitignore_template("Python") self.assertEqual(t.name, "Python") - self.assertEqual(t.source, "*.py[cod]\n\n# C extensions\n*.so\n\n# Packages\n*.egg\n*.egg-info\ndist\nbuild\neggs\nparts\nbin\nvar\nsdist\ndevelop-eggs\n.installed.cfg\nlib\nlib64\n\n# Installer logs\npip-log.txt\n\n# Unit test / coverage reports\n.coverage\n.tox\nnosetests.xml\n\n# Translations\n*.mo\n\n# Mr Developer\n.mr.developer.cfg\n.project\n.pydevproject\n") + self.assertEqual( + t.source, + "*.py[cod]\n\n# C extensions\n*.so\n\n# Packages\n*.egg\n*.egg-info\ndist\nbuild\neggs\nparts\nbin\nvar\nsdist\ndevelop-eggs\n.installed.cfg\nlib\nlib64\n\n# Installer logs\npip-log.txt\n\n# Unit test / coverage reports\n.coverage\n.tox\nnosetests.xml\n\n# Translations\n*.mo\n\n# Mr Developer\n.mr.developer.cfg\n.project\n.pydevproject\n", + ) t = self.g.get_gitignore_template("C++") self.assertEqual(t.name, "C++") - self.assertEqual(t.source, "# Compiled Object files\n*.slo\n*.lo\n*.o\n\n# Compiled Dynamic libraries\n*.so\n*.dylib\n\n# Compiled Static libraries\n*.lai\n*.la\n*.a\n") + self.assertEqual( + t.source, + "# Compiled Object files\n*.slo\n*.lo\n*.o\n\n# Compiled Dynamic libraries\n*.so\n*.dylib\n\n# Compiled Static libraries\n*.lai\n*.la\n*.a\n", + ) def testStringOfNotSet(self): self.assertEqual(str(github.GithubObject.NotSet), "NotSet") def testGetUsers(self): - self.assertListKeyBegin(self.g.get_users(), lambda u: u.login, ["mojombo", "defunkt", "pjhyett", "wycats", "ezmobius", "ivey", "evanphx", "vanpelt", "wayneeseguin", "brynary", "kevinclark", "technoweenie", "macournoyer", "takeo", "Caged", "topfunky", "anotherjesse", "roland", "lukas", "fanvsfan", "tomtt", "railsjitsu", "nitay", "kevwil", "KirinDave", "jamesgolick", "atmos", "errfree", "mojodna", "bmizerany", "jnewland", "joshknowles", "hornbeck", "jwhitmire", "elbowdonkey", "reinh", "timocratic", "bs", "rsanheim", "schacon", "uggedal", "bruce", "sam", "mmower", "abhay", "rabble", "benburkert", "indirect", "fearoffish", "ry", "engineyard", "jsierles", "tweibley", "peimei", "brixen", "tmornini", "outerim", "daksis", "sr", "lifo", "rsl", "imownbey", "dylanegan", "jm", "willcodeforfoo", "jvantuyl", "BrianTheCoder", "freeformz", "hassox", "automatthew", "queso", "lancecarlson", "drnic", "lukesutton", "danwrong", "hcatlin", "jfrost", "mattetti", "ctennis", "lawrencepit", "marcjeanson", "grempe", "peterc", "ministrycentered", "afarnham", "up_the_irons", "evilchelu", "heavysixer", "brosner", "danielmorrison", "danielharan", "kvnsmth", "collectiveidea", "canadaduane", "nate", "dstrelau", "sunny", "dkubb", "jnicklas", "richcollins", "simonjefford"]) + self.assertListKeyBegin( + self.g.get_users(), + lambda u: u.login, + [ + "mojombo", + "defunkt", + "pjhyett", + "wycats", + "ezmobius", + "ivey", + "evanphx", + "vanpelt", + "wayneeseguin", + "brynary", + "kevinclark", + "technoweenie", + "macournoyer", + "takeo", + "Caged", + "topfunky", + "anotherjesse", + "roland", + "lukas", + "fanvsfan", + "tomtt", + "railsjitsu", + "nitay", + "kevwil", + "KirinDave", + "jamesgolick", + "atmos", + "errfree", + "mojodna", + "bmizerany", + "jnewland", + "joshknowles", + "hornbeck", + "jwhitmire", + "elbowdonkey", + "reinh", + "timocratic", + "bs", + "rsanheim", + "schacon", + "uggedal", + "bruce", + "sam", + "mmower", + "abhay", + "rabble", + "benburkert", + "indirect", + "fearoffish", + "ry", + "engineyard", + "jsierles", + "tweibley", + "peimei", + "brixen", + "tmornini", + "outerim", + "daksis", + "sr", + "lifo", + "rsl", + "imownbey", + "dylanegan", + "jm", + "willcodeforfoo", + "jvantuyl", + "BrianTheCoder", + "freeformz", + "hassox", + "automatthew", + "queso", + "lancecarlson", + "drnic", + "lukesutton", + "danwrong", + "hcatlin", + "jfrost", + "mattetti", + "ctennis", + "lawrencepit", + "marcjeanson", + "grempe", + "peterc", + "ministrycentered", + "afarnham", + "up_the_irons", + "evilchelu", + "heavysixer", + "brosner", + "danielmorrison", + "danielharan", + "kvnsmth", + "collectiveidea", + "canadaduane", + "nate", + "dstrelau", + "sunny", + "dkubb", + "jnicklas", + "richcollins", + "simonjefford", + ], + ) def testGetUsersSince(self): - self.assertListKeyBegin(self.g.get_users(since=1000), lambda u: u.login, ["sbecker"]) + self.assertListKeyBegin( + self.g.get_users(since=1000), lambda u: u.login, ["sbecker"] + ) def testGetOrganizations(self): - self.assertListKeyBegin(self.g.get_organizations(), lambda u: u.login, ['errfree', 'engineyard', "ministrycentered", "collectiveidea", "ogc", "sevenwire", "entryway"]) + self.assertListKeyBegin( + self.g.get_organizations(), + lambda u: u.login, + [ + "errfree", + "engineyard", + "ministrycentered", + "collectiveidea", + "ogc", + "sevenwire", + "entryway", + ], + ) def testGetOrganizationsSince(self): - self.assertListKeyBegin(self.g.get_organizations(since=1000), lambda u: u.login, ["railslove", "railsdog", "netguru", "webhostio", "animikii", "sauspiel", "wherecloud", "triveos"]) + self.assertListKeyBegin( + self.g.get_organizations(since=1000), + lambda u: u.login, + [ + "railslove", + "railsdog", + "netguru", + "webhostio", + "animikii", + "sauspiel", + "wherecloud", + "triveos", + ], + ) def testGetRepos(self): - self.assertListKeyBegin(self.g.get_repos(), lambda r: r.name, ["grit", "merb-core", "rubinius", "god", "jsawesome", "jspec", "exception_logger", "ambition"]) + self.assertListKeyBegin( + self.g.get_repos(), + lambda r: r.name, + [ + "grit", + "merb-core", + "rubinius", + "god", + "jsawesome", + "jspec", + "exception_logger", + "ambition", + ], + ) def testGetReposSince(self): - self.assertListKeyBegin(self.g.get_repos(since=1000), lambda r: r.name, ["jquery-humanize-messages-plugin", "4slicer", "fixture-scenarios", "mongrel_proctitle", "rails-plugins"]) + self.assertListKeyBegin( + self.g.get_repos(since=1000), + lambda r: r.name, + [ + "jquery-humanize-messages-plugin", + "4slicer", + "fixture-scenarios", + "mongrel_proctitle", + "rails-plugins", + ], + ) def testGetLicenses(self): - self.assertListKeyBegin(self.g.get_licenses(), lambda r: r.name, ['GNU General Public License v3.0', - 'BSD 2-Clause "Simplified" License', - 'MIT License', - 'GNU Lesser General Public License v2.1', - 'GNU General Public License v2.0', - 'GNU Lesser General Public License v3.0', - 'Mozilla Public License 2.0', - 'BSD 3-Clause "New" or "Revised" License']) + self.assertListKeyBegin( + self.g.get_licenses(), + lambda r: r.name, + [ + "GNU General Public License v3.0", + 'BSD 2-Clause "Simplified" License', + "MIT License", + "GNU Lesser General Public License v2.1", + "GNU General Public License v2.0", + "GNU Lesser General Public License v3.0", + "Mozilla Public License 2.0", + 'BSD 3-Clause "New" or "Revised" License', + ], + ) def testGetLicense(self): - self.assertEqual(self.g.get_license("mit").description, "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.") + self.assertEqual( + self.g.get_license("mit").description, + "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.", + ) diff --git a/tests/Hook.py b/tests/Hook.py index 8631f2e0..429f375d 100644 --- a/tests/Hook.py +++ b/tests/Hook.py @@ -30,10 +30,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Hook(Framework.TestCase): def setUp(self): @@ -50,13 +51,26 @@ class Hook(Framework.TestCase): self.assertEqual(self.hook.last_response.message, "OK") 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.assertEqual(self.hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993") - self.assertEqual(self.hook.test_url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/tests") - self.assertEqual(self.hook.ping_url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/pings") + self.assertEqual( + self.hook.updated_at, datetime.datetime(2012, 5, 29, 18, 49, 47) + ) + self.assertEqual( + self.hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993" + ) + self.assertEqual( + self.hook.test_url, + "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/tests", + ) + self.assertEqual( + self.hook.ping_url, + "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/pings", + ) # test __repr__() based on this attributes - self.assertEqual(self.hook.__repr__(), 'Hook(url="https://api.github.com/repos/jacquev6/PyGithub/hooks/257993", id=257993)') + self.assertEqual( + self.hook.__repr__(), + 'Hook(url="https://api.github.com/repos/jacquev6/PyGithub/hooks/257993", id=257993)', + ) def testEditWithMinimalParameters(self): self.hook.edit("web", {"url": "http://foobar.com/hook"}) diff --git a/tests/Issue.py b/tests/Issue.py index d212607d..f21357cc 100644 --- a/tests/Issue.py +++ b/tests/Issue.py @@ -33,10 +33,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Issue(Framework.TestCase): def setUp(self): @@ -46,15 +47,27 @@ class Issue(Framework.TestCase): def testAttributes(self): self.assertEqual(self.issue.assignee.login, "jacquev6") - self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) + self.assertListKeyEqual( + self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"] + ) self.assertEqual(self.issue.body, "Body edited by PyGithub") - self.assertEqual(self.issue.closed_at, datetime.datetime(2012, 5, 26, 14, 59, 33)) + self.assertEqual( + self.issue.closed_at, datetime.datetime(2012, 5, 26, 14, 59, 33) + ) self.assertEqual(self.issue.closed_by.login, "jacquev6") self.assertEqual(self.issue.comments, 0) - self.assertEqual(self.issue.created_at, datetime.datetime(2012, 5, 19, 10, 38, 23)) - self.assertEqual(self.issue.html_url, "https://github.com/jacquev6/PyGithub/issues/28") + self.assertEqual( + self.issue.created_at, datetime.datetime(2012, 5, 19, 10, 38, 23) + ) + self.assertEqual( + self.issue.html_url, "https://github.com/jacquev6/PyGithub/issues/28" + ) self.assertEqual(self.issue.id, 4653757) - self.assertListKeyEqual(self.issue.labels, lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.labels, + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) self.assertEqual(self.issue.milestone.title, "Version 0.4") self.assertEqual(self.issue.number, 28) self.assertEqual(self.issue.pull_request.diff_url, None) @@ -62,13 +75,19 @@ class Issue(Framework.TestCase): self.assertEqual(self.issue.pull_request.html_url, None) self.assertEqual(self.issue.state, "closed") self.assertEqual(self.issue.title, "Issue created by PyGithub") - self.assertEqual(self.issue.updated_at, datetime.datetime(2012, 5, 26, 14, 59, 33)) - self.assertEqual(self.issue.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/28") + self.assertEqual( + self.issue.updated_at, datetime.datetime(2012, 5, 26, 14, 59, 33) + ) + self.assertEqual( + self.issue.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/28" + ) self.assertEqual(self.issue.user.login, "jacquev6") self.assertEqual(self.issue.repository.name, "PyGithub") # test __repr__() based on this attributes - self.assertEqual(self.issue.__repr__(), 'Issue(title="Issue created by PyGithub", number=28)') + self.assertEqual( + self.issue.__repr__(), 'Issue(title="Issue created by PyGithub", number=28)' + ) def testEditWithoutParameters(self): self.issue.edit() @@ -76,9 +95,19 @@ class Issue(Framework.TestCase): def testEditWithAllParameters(self): user = self.g.get_user("jacquev6") milestone = self.repo.get_milestone(2) - self.issue.edit("Title edited by PyGithub", "Body edited by PyGithub", user, "open", milestone, ["Bug"], ["jacquev6", "stuglaser"]) + self.issue.edit( + "Title edited by PyGithub", + "Body edited by PyGithub", + user, + "open", + milestone, + ["Bug"], + ["jacquev6", "stuglaser"], + ) self.assertEqual(self.issue.assignee.login, "jacquev6") - self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) + self.assertListKeyEqual( + self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"] + ) self.assertEqual(self.issue.body, "Body edited by PyGithub") self.assertEqual(self.issue.state, "open") self.assertEqual(self.issue.title, "Title edited by PyGithub") @@ -105,65 +134,125 @@ class Issue(Framework.TestCase): self.assertEqual(comment.id, 5808311) def testGetComments(self): - self.assertListKeyEqual(self.issue.get_comments(), lambda c: c.user.login, ["jacquev6", "roskakori"]) + self.assertListKeyEqual( + self.issue.get_comments(), lambda c: c.user.login, ["jacquev6", "roskakori"] + ) def testGetCommentsSince(self): - self.assertListKeyEqual(self.issue.get_comments(datetime.datetime(2012, 5, 26, 13, 59, 33)), lambda c: c.user.login, ["jacquev6", "roskakori"]) + self.assertListKeyEqual( + self.issue.get_comments(datetime.datetime(2012, 5, 26, 13, 59, 33)), + lambda c: c.user.login, + ["jacquev6", "roskakori"], + ) def testGetEvents(self): - self.assertListKeyEqual(self.issue.get_events(), lambda e: e.id, [15819975, 15820048]) + self.assertListKeyEqual( + self.issue.get_events(), lambda e: e.id, [15819975, 15820048] + ) def testGetLabels(self): - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) def testAddAndRemoveAssignees(self): user1 = "jayfk" user2 = self.g.get_user("jzelinskie") - self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) + self.assertListKeyEqual( + self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"] + ) self.issue.add_to_assignees(user1, user2) - self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser", "jayfk", "jzelinskie"]) + self.assertListKeyEqual( + self.issue.assignees, + lambda a: a.login, + ["jacquev6", "stuglaser", "jayfk", "jzelinskie"], + ) self.issue.remove_from_assignees(user1, user2) - self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) + self.assertListKeyEqual( + self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"] + ) def testAddAndRemoveLabels(self): bug = self.repo.get_label("Bug") question = self.repo.get_label("Question") - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) self.issue.remove_from_labels(bug) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Project management", "Question"], + ) self.issue.remove_from_labels(question) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Project management"]) + self.assertListKeyEqual( + self.issue.get_labels(), lambda l: l.name, ["Project management"] + ) self.issue.add_to_labels(bug, question) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) def testAddAndRemoveLabelsWithStringArguments(self): bug = "Bug" question = "Question" - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) self.issue.remove_from_labels(bug) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Project management", "Question"], + ) self.issue.remove_from_labels(question) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Project management"]) + self.assertListKeyEqual( + self.issue.get_labels(), lambda l: l.name, ["Project management"] + ) self.issue.add_to_labels(bug, question) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) def testDeleteAndSetLabels(self): bug = self.repo.get_label("Bug") question = self.repo.get_label("Question") - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) self.issue.delete_labels() self.assertListKeyEqual(self.issue.get_labels(), None, []) self.issue.set_labels(bug, question) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), lambda l: l.name, ["Bug", "Question"] + ) def testDeleteAndSetLabelsWithStringArguments(self): bug = "Bug" question = "Question" - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", "Project management", "Question"], + ) self.issue.delete_labels() self.assertListKeyEqual(self.issue.get_labels(), None, []) self.issue.set_labels(bug, question) - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Question"]) + self.assertListKeyEqual( + self.issue.get_labels(), lambda l: l.name, ["Bug", "Question"] + ) def testGetReactions(self): reactions = self.issue.get_reactions() diff --git a/tests/Issue131.py b/tests/Issue131.py index 76dac6ec..c74e6484 100644 --- a/tests/Issue131.py +++ b/tests/Issue131.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -37,12 +38,12 @@ class Issue131(Framework.TestCase): # https://github.com/jacquev6/PyGithub/pull def testGetPullWithOrgHeadUser(self): user = self.repo.get_pull(204).head.user - self.assertEqual(user.login, 'imcf') - self.assertEqual(user.type, 'Organization') - self.assertEqual(user.__class__.__name__, 'NamedUser') # Should be Organization + self.assertEqual(user.login, "imcf") + self.assertEqual(user.type, "Organization") + self.assertEqual(user.__class__.__name__, "NamedUser") # Should be Organization def testGetPullsWithOrgHeadUser(self): - for pull in self.repo.get_pulls('closed'): + for pull in self.repo.get_pulls("closed"): if pull.number == 204: user = pull.head.user self.assertEqual(user, None) diff --git a/tests/Issue133.py b/tests/Issue133.py index 4b92359b..85e2d8af 100644 --- a/tests/Issue133.py +++ b/tests/Issue133.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Issue134.py b/tests/Issue134.py index 3a820034..be9034d9 100644 --- a/tests/Issue134.py +++ b/tests/Issue134.py @@ -27,11 +27,15 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + import github +from . import Framework -class Issue134(Framework.BasicTestCase): # https://github.com/jacquev6/PyGithub/pull/134 + +class Issue134( + Framework.BasicTestCase +): # https://github.com/jacquev6/PyGithub/pull/134 def testGetAuthorizationsFailsWhenAutenticatedThroughOAuth(self): g = github.Github(self.oauth_token) with self.assertRaises(github.GithubException) as raisedexp: @@ -40,10 +44,14 @@ class Issue134(Framework.BasicTestCase): # https://github.com/jacquev6/PyGithub def testGetAuthorizationsSucceedsWhenAutenticatedThroughLoginPassword(self): g = github.Github(self.login, self.password) - self.assertListKeyEqual(g.get_user().get_authorizations(), lambda a: a.note, [None, None, 'cligh', None, None, 'GitHub Android App']) + self.assertListKeyEqual( + g.get_user().get_authorizations(), + lambda a: a.note, + [None, None, "cligh", None, None, "GitHub Android App"], + ) def testGetOAuthScopesFromHeader(self): g = github.Github(self.oauth_token) self.assertEqual(g.oauth_scopes, None) g.get_user().name - self.assertEqual(g.oauth_scopes, ['repo', 'user', 'gist']) + self.assertEqual(g.oauth_scopes, ["repo", "user", "gist"]) diff --git a/tests/Issue139.py b/tests/Issue139.py index 1196bdb6..b746b84b 100644 --- a/tests/Issue139.py +++ b/tests/Issue139.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Issue140.py b/tests/Issue140.py index f8c04695..8f18f7a2 100644 --- a/tests/Issue140.py +++ b/tests/Issue140.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -50,8 +51,16 @@ class Issue140(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issu def testGetFileContents(self): contents = self.repo.get_contents("js/bootstrap-affix.js") self.assertEqual(contents.encoding, "base64") - self.assertEqual(contents.url, "https://api.github.com/repos/twitter/bootstrap/contents/js/bootstrap-affix.js") + self.assertEqual( + contents.url, + "https://api.github.com/repos/twitter/bootstrap/contents/js/bootstrap-affix.js", + ) self.assertEqual(len(contents.content), 4722) def testGetDirContentsWithRef(self): - self.assertEqual(len(self.repo.get_contents("js", "8c7f9c66a7d12f47f50618ef420868fe836d0c33")), 15) + self.assertEqual( + len( + self.repo.get_contents("js", "8c7f9c66a7d12f47f50618ef420868fe836d0c33") + ), + 15, + ) diff --git a/tests/Issue142.py b/tests/Issue142.py index 5d2ae6a4..b35e6425 100644 --- a/tests/Issue142.py +++ b/tests/Issue142.py @@ -28,6 +28,7 @@ from __future__ import absolute_import import github + from . import Framework diff --git a/tests/Issue158.py b/tests/Issue158.py index e0b3ff45..04136ef1 100644 --- a/tests/Issue158.py +++ b/tests/Issue158.py @@ -26,12 +26,18 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + import github +from . import Framework + class Issue158(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issues/158 # Warning: I don't have a scret key, so the requests for this test are forged def testPaginationWithSecretKeyAuthentication(self): g = github.Github(client_id=self.client_id, client_secret=self.client_secret) - self.assertListKeyEqual(g.get_organization("BeaverSoftware").get_repos("public"), lambda r: r.name, ["FatherBeaver", "PyGithub"]) + self.assertListKeyEqual( + g.get_organization("BeaverSoftware").get_repos("public"), + lambda r: r.name, + ["FatherBeaver", "PyGithub"], + ) diff --git a/tests/Issue174.py b/tests/Issue174.py index de78a787..5f526f83 100644 --- a/tests/Issue174.py +++ b/tests/Issue174.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Issue214.py b/tests/Issue214.py index 7753357f..2c376626 100644 --- a/tests/Issue214.py +++ b/tests/Issue214.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -36,35 +37,35 @@ class Issue214(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issu self.issue = self.repo.get_issue(1) def testAssignees(self): - self.assertTrue(self.repo.has_in_assignees('farrd')) - self.assertFalse(self.repo.has_in_assignees('fake')) + self.assertTrue(self.repo.has_in_assignees("farrd")) + self.assertFalse(self.repo.has_in_assignees("fake")) def testCollaborators(self): - self.assertTrue(self.repo.has_in_collaborators('farrd')) - self.assertFalse(self.repo.has_in_collaborators('fake')) + self.assertTrue(self.repo.has_in_collaborators("farrd")) + self.assertFalse(self.repo.has_in_collaborators("fake")) - self.assertFalse(self.repo.has_in_collaborators('marcmenges')) - self.repo.add_to_collaborators('marcmenges') - self.assertTrue(self.repo.has_in_collaborators('marcmenges')) + self.assertFalse(self.repo.has_in_collaborators("marcmenges")) + self.repo.add_to_collaborators("marcmenges") + self.assertTrue(self.repo.has_in_collaborators("marcmenges")) - self.repo.remove_from_collaborators('marcmenges') - self.assertFalse(self.repo.has_in_collaborators('marcmenges')) + self.repo.remove_from_collaborators("marcmenges") + self.assertFalse(self.repo.has_in_collaborators("marcmenges")) def testEditIssue(self): self.assertEqual(self.issue.assignee, None) - self.issue.edit(assignee='farrd') - self.assertEqual(self.issue.assignee.login, 'farrd') + self.issue.edit(assignee="farrd") + self.assertEqual(self.issue.assignee.login, "farrd") self.issue.edit(assignee=None) self.assertEqual(self.issue.assignee, None) def testCreateIssue(self): - issue = self.repo.create_issue("Issue created by PyGithub", assignee='farrd') - self.assertEqual(issue.assignee.login, 'farrd') + issue = self.repo.create_issue("Issue created by PyGithub", assignee="farrd") + self.assertEqual(issue.assignee.login, "farrd") def testGetIssues(self): - issues = self.repo.get_issues(assignee='farrd') + issues = self.repo.get_issues(assignee="farrd") for issue in issues: - self.assertEqual(issue.assignee.login, 'farrd') + self.assertEqual(issue.assignee.login, "farrd") diff --git a/tests/Issue216.py b/tests/Issue216.py index 04e2d959..c1d1a5af 100644 --- a/tests/Issue216.py +++ b/tests/Issue216.py @@ -26,6 +26,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Issue278.py b/tests/Issue278.py index be3217c5..6c28a70c 100644 --- a/tests/Issue278.py +++ b/tests/Issue278.py @@ -25,6 +25,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Issue33.py b/tests/Issue33.py index 175321ed..42de4cec 100644 --- a/tests/Issue33.py +++ b/tests/Issue33.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Issue494.py b/tests/Issue494.py index 50337bd5..6905afbb 100644 --- a/tests/Issue494.py +++ b/tests/Issue494.py @@ -24,6 +24,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -34,6 +35,8 @@ class Issue494(Framework.TestCase): self.pull = self.repo.get_pull(465) def testRepr(self): - expected = u'PullRequest(title="Change SetHostnameCustomizer to check if ' \ - u'/etc/sysconfig/network exist…", number=465)' + expected = ( + u'PullRequest(title="Change SetHostnameCustomizer to check if ' + u'/etc/sysconfig/network exist…", number=465)' + ) self.assertEqual(self.pull.__repr__(), expected) diff --git a/tests/Issue50.py b/tests/Issue50.py index f9bb2894..da9d8cde 100644 --- a/tests/Issue50.py +++ b/tests/Issue50.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -47,7 +48,20 @@ class Issue50(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issue self.assertEqual(label.name, self.labelName) def testGetLabels(self): - self.assertListKeyEqual(self.repo.get_labels(), lambda l: l.name, ["Refactoring", "Public interface", "Functionalities", "Project management", "Bug", "Question", "RequestedByUser", self.labelName]) + self.assertListKeyEqual( + self.repo.get_labels(), + lambda l: l.name, + [ + "Refactoring", + "Public interface", + "Functionalities", + "Project management", + "Bug", + "Question", + "RequestedByUser", + self.labelName, + ], + ) def testAddLabelToIssue(self): self.issue.add_to_labels(self.repo.get_label(self.labelName)) @@ -56,18 +70,37 @@ class Issue50(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issue self.issue.remove_from_labels(self.repo.get_label(self.labelName)) def testSetIssueLabels(self): - self.issue.set_labels(self.repo.get_label("Bug"), self.repo.get_label("RequestedByUser"), self.repo.get_label(self.labelName)) + self.issue.set_labels( + self.repo.get_label("Bug"), + self.repo.get_label("RequestedByUser"), + self.repo.get_label(self.labelName), + ) def testIssueLabels(self): - self.assertListKeyEqual(self.issue.labels, lambda l: l.name, ["Bug", self.labelName, "RequestedByUser"]) + self.assertListKeyEqual( + self.issue.labels, + lambda l: l.name, + ["Bug", self.labelName, "RequestedByUser"], + ) def testIssueGetLabels(self): - self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", self.labelName, "RequestedByUser"]) + self.assertListKeyEqual( + self.issue.get_labels(), + lambda l: l.name, + ["Bug", self.labelName, "RequestedByUser"], + ) def testGetIssuesWithLabel(self): - self.assertListKeyEqual(self.repo.get_issues(labels=[self.repo.get_label(self.labelName)]), lambda i: i.number, [52, 50]) + self.assertListKeyEqual( + self.repo.get_issues(labels=[self.repo.get_label(self.labelName)]), + lambda i: i.number, + [52, 50], + ) def testCreateIssueWithLabel(self): - issue = self.repo.create_issue("Issue created by PyGithub to test issue #50", labels=[self.repo.get_label(self.labelName)]) + issue = self.repo.create_issue( + "Issue created by PyGithub to test issue #50", + labels=[self.repo.get_label(self.labelName)], + ) self.assertListKeyEqual(issue.labels, lambda l: l.name, [self.labelName]) self.assertEqual(issue.number, 52) diff --git a/tests/Issue54.py b/tests/Issue54.py index 89ce8651..3db5ed23 100644 --- a/tests/Issue54.py +++ b/tests/Issue54.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + import datetime from . import Framework @@ -40,5 +41,8 @@ class Issue54(Framework.TestCase): def testConversion(self): commit = self.repo.get_git_commit("73f320ae06cd565cf38faca34b6a482addfc721b") - self.assertEqual(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.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)) diff --git a/tests/Issue572.py b/tests/Issue572.py index 85bbd9ae..7ad2c4da 100644 --- a/tests/Issue572.py +++ b/tests/Issue572.py @@ -23,10 +23,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import github +from . import Framework + class Issue572(Framework.TestCase): def setUp(self): diff --git a/tests/Issue80.py b/tests/Issue80.py index f1850a6e..87099f8b 100644 --- a/tests/Issue80.py +++ b/tests/Issue80.py @@ -28,20 +28,37 @@ ################################################################################ from __future__ import absolute_import + import github from . import Framework -class Issue80(Framework.BasicTestCase): # https://github.com/jacquev6/PyGithub/issues/80 +class Issue80( + Framework.BasicTestCase +): # https://github.com/jacquev6/PyGithub/issues/80 def testIgnoreHttpsFromGithubEnterprise(self): - g = github.Github(self.login, self.password, base_url="http://my.enterprise.com/some/prefix") # http here + g = github.Github( + self.login, self.password, base_url="http://my.enterprise.com/some/prefix" + ) # http here org = g.get_organization("BeaverSoftware") - self.assertEqual(org.url, "https://my.enterprise.com/some/prefix/orgs/BeaverSoftware") # https returned - self.assertListKeyEqual(org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"]) # But still http in second request based on org.url + self.assertEqual( + org.url, "https://my.enterprise.com/some/prefix/orgs/BeaverSoftware" + ) # https returned + self.assertListKeyEqual( + org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"] + ) # But still http in second request based on org.url def testIgnoreHttpsFromGithubEnterpriseWithPort(self): - g = github.Github(self.login, self.password, base_url="http://my.enterprise.com:1234/some/prefix") # http here + g = github.Github( + self.login, + self.password, + base_url="http://my.enterprise.com:1234/some/prefix", + ) # http here org = g.get_organization("BeaverSoftware") - self.assertEqual(org.url, "https://my.enterprise.com:1234/some/prefix/orgs/BeaverSoftware") # https returned - self.assertListKeyEqual(org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"]) # But still http in second request based on org.url + self.assertEqual( + org.url, "https://my.enterprise.com:1234/some/prefix/orgs/BeaverSoftware" + ) # https returned + self.assertListKeyEqual( + org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"] + ) # But still http in second request based on org.url diff --git a/tests/Issue823.py b/tests/Issue823.py index d4145b9d..cd77fd9b 100644 --- a/tests/Issue823.py +++ b/tests/Issue823.py @@ -26,22 +26,26 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class Issue823(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.org = self.g.get_organization('p-society') + self.org = self.g.get_organization("p-society") self.team = self.org.get_team(2745783) self.pending_invitations = self.team.invitations() def testGetPendingInvitationAttributes(self): team_url = self.pending_invitations[0].invitation_teams_url - self.assertEqual(team_url, 'https://api.github.com/organizations/29895434/invitations/6080804/teams') + self.assertEqual( + team_url, + "https://api.github.com/organizations/29895434/invitations/6080804/teams", + ) inviter = self.pending_invitations[0].inviter.login - self.assertEqual(inviter, 'palash25') + self.assertEqual(inviter, "palash25") role = self.pending_invitations[0].role - self.assertEqual(role, 'direct_member') + self.assertEqual(role, "direct_member") team_count = self.pending_invitations[0].team_count self.assertEqual(team_count, 1) diff --git a/tests/Issue87.py b/tests/Issue87.py index 11b8ee0f..822c673e 100644 --- a/tests/Issue87.py +++ b/tests/Issue87.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -37,7 +38,9 @@ class Issue87(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issue self.repo = self.g.get_user().get_repo("PyGithub") def testCreateIssueWithPercentInTitle(self): - issue = self.repo.create_issue("Issue with percent % in title created by PyGithub") + issue = self.repo.create_issue( + "Issue with percent % in title created by PyGithub" + ) self.assertEqual(issue.number, 99) def testCreateIssueWithPercentInBody(self): @@ -45,9 +48,13 @@ class Issue87(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issue self.assertEqual(issue.number, 98) def testCreateIssueWithEscapedPercentInTitle(self): - issue = self.repo.create_issue("Issue with escaped percent %25 in title created by PyGithub") + issue = self.repo.create_issue( + "Issue with escaped percent %25 in title created by PyGithub" + ) self.assertEqual(issue.number, 97) def testCreateIssueWithEscapedPercentInBody(self): - issue = self.repo.create_issue("Issue created by PyGithub", "Escaped percent %25 in body") + issue = self.repo.create_issue( + "Issue created by PyGithub", "Escaped percent %25 in body" + ) self.assertEqual(issue.number, 96) diff --git a/tests/Issue937.py b/tests/Issue937.py index 88e91bc1..c4ddf068 100644 --- a/tests/Issue937.py +++ b/tests/Issue937.py @@ -17,11 +17,14 @@ # 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 __future__ import absolute_import + +# You should have received a copy of the GNU Lesser General Public License # +# along with PyGithub. If not, see . # from . import Framework @@ -32,7 +35,7 @@ class Issue937(Framework.TestCase): self.repo = self.user.get_repo("PyGithub") def testCollaboratorsAffiliation(self): - collaborators = self.repo.get_collaborators(affiliation='direct') + collaborators = self.repo.get_collaborators(affiliation="direct") self.assertListKeyEqual(collaborators, lambda u: u.login, ["hegde5"]) with self.assertRaises(AssertionError): - self.repo.get_collaborators(affiliation='invalid_option') + self.repo.get_collaborators(affiliation="invalid_option") diff --git a/tests/Issue945.py b/tests/Issue945.py index 1fd49351..59921294 100644 --- a/tests/Issue945.py +++ b/tests/Issue945.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -35,18 +36,44 @@ class Issue945(Framework.TestCase): # https://github.com/PyGithub/PyGithub/issu def testReservedPaginatedListAttributePreservation(self): r1 = self.list.reversed - self.assertEqual(self.list._PaginatedList__contentClass, r1._PaginatedList__contentClass) - self.assertEqual(self.list._PaginatedList__requester, r1._PaginatedList__requester) - self.assertEqual(self.list._PaginatedList__firstUrl, r1._PaginatedList__firstUrl) - self.assertEqual(self.list._PaginatedList__firstParams, r1._PaginatedList__firstParams) + self.assertEqual( + self.list._PaginatedList__contentClass, r1._PaginatedList__contentClass + ) + self.assertEqual( + self.list._PaginatedList__requester, r1._PaginatedList__requester + ) + self.assertEqual( + self.list._PaginatedList__firstUrl, r1._PaginatedList__firstUrl + ) + self.assertEqual( + self.list._PaginatedList__firstParams, r1._PaginatedList__firstParams + ) self.assertEqual(self.list._PaginatedList__headers, r1._PaginatedList__headers) - self.assertEqual(self.list._PaginatedList__list_item, r1._PaginatedList__list_item) + self.assertEqual( + self.list._PaginatedList__list_item, r1._PaginatedList__list_item + ) self.assertTrue(self.list_with_headers._PaginatedList__headers is not None) r2 = self.list_with_headers.reversed - self.assertEqual(self.list_with_headers._PaginatedList__contentClass, r2._PaginatedList__contentClass) - self.assertEqual(self.list_with_headers._PaginatedList__requester, r2._PaginatedList__requester) - self.assertEqual(self.list_with_headers._PaginatedList__firstUrl, r2._PaginatedList__firstUrl) - self.assertEqual(self.list_with_headers._PaginatedList__firstParams, r2._PaginatedList__firstParams) - self.assertEqual(self.list_with_headers._PaginatedList__headers, r2._PaginatedList__headers) - self.assertEqual(self.list_with_headers._PaginatedList__list_item, r2._PaginatedList__list_item) + self.assertEqual( + self.list_with_headers._PaginatedList__contentClass, + r2._PaginatedList__contentClass, + ) + self.assertEqual( + self.list_with_headers._PaginatedList__requester, + r2._PaginatedList__requester, + ) + self.assertEqual( + self.list_with_headers._PaginatedList__firstUrl, r2._PaginatedList__firstUrl + ) + self.assertEqual( + self.list_with_headers._PaginatedList__firstParams, + r2._PaginatedList__firstParams, + ) + self.assertEqual( + self.list_with_headers._PaginatedList__headers, r2._PaginatedList__headers + ) + self.assertEqual( + self.list_with_headers._PaginatedList__list_item, + r2._PaginatedList__list_item, + ) diff --git a/tests/IssueComment.py b/tests/IssueComment.py index c0059de4..3f28aaa3 100644 --- a/tests/IssueComment.py +++ b/tests/IssueComment.py @@ -30,32 +30,50 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class IssueComment(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.comment = self.g.get_user().get_repo("PyGithub").get_issue(28).get_comment(5808311) + self.comment = ( + self.g.get_user().get_repo("PyGithub").get_issue(28).get_comment(5808311) + ) 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.assertEqual( + self.comment.created_at, datetime.datetime(2012, 5, 20, 11, 46, 42) + ) self.assertEqual(self.comment.id, 5808311) - self.assertEqual(self.comment.updated_at, datetime.datetime(2012, 5, 20, 11, 46, 42)) - self.assertEqual(self.comment.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/comments/5808311") + self.assertEqual( + self.comment.updated_at, datetime.datetime(2012, 5, 20, 11, 46, 42) + ) + self.assertEqual( + self.comment.url, + "https://api.github.com/repos/jacquev6/PyGithub/issues/comments/5808311", + ) self.assertEqual(self.comment.user.login, "jacquev6") - self.assertEqual(self.comment.html_url, "https://github.com/jacquev6/PyGithub/issues/28#issuecomment-5808311") + self.assertEqual( + self.comment.html_url, + "https://github.com/jacquev6/PyGithub/issues/28#issuecomment-5808311", + ) # test __repr__() based on this attributes - self.assertEqual(self.comment.__repr__(), 'IssueComment(user=NamedUser(login="jacquev6"), id=5808311)') + self.assertEqual( + self.comment.__repr__(), + 'IssueComment(user=NamedUser(login="jacquev6"), id=5808311)', + ) def testEdit(self): 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.assertEqual( + self.comment.updated_at, datetime.datetime(2012, 5, 20, 11, 53, 59) + ) def testDelete(self): self.comment.delete() diff --git a/tests/IssueEvent.py b/tests/IssueEvent.py index ff628586..4fa262f1 100644 --- a/tests/IssueEvent.py +++ b/tests/IssueEvent.py @@ -30,10 +30,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class IssueEvent(Framework.TestCase): def setUp(self): @@ -78,12 +79,19 @@ class IssueEvent(Framework.TestCase): def testEvent_subscribed_Attributes(self): 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.assertEqual( + self.event_subscribed.created_at, datetime.datetime(2012, 5, 27, 5, 40, 15) + ) self.assertEqual(self.event_subscribed.event, "subscribed") self.assertEqual(self.event_subscribed.id, 16347479) self.assertEqual(self.event_subscribed.issue.number, 30) - self.assertEqual(self.event_subscribed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16347479") - self.assertEqual(self.event_subscribed.node_id, "MDE1OlN1YnNjcmliZWRFdmVudDE2MzQ3NDc5") + self.assertEqual( + self.event_subscribed.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16347479", + ) + self.assertEqual( + self.event_subscribed.node_id, "MDE1OlN1YnNjcmliZWRFdmVudDE2MzQ3NDc5" + ) self.assertEqual(self.event_subscribed.commit_url, None) self.assertEqual(self.event_subscribed.label, None) self.assertEqual(self.event_subscribed.assignee, None) @@ -95,17 +103,24 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_subscribed.dismissed_review, None) self.assertEqual(self.event_subscribed.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_subscribed.__repr__(), 'IssueEvent(id=16347479)') + self.assertEqual(self.event_subscribed.__repr__(), "IssueEvent(id=16347479)") def testEvent_assigned_Attributes(self): 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.assertEqual( + self.event_assigned.created_at, datetime.datetime(2012, 5, 27, 5, 40, 15) + ) self.assertEqual(self.event_assigned.event, "assigned") self.assertEqual(self.event_assigned.id, 16347480) self.assertEqual(self.event_assigned.issue.number, 30) - self.assertEqual(self.event_assigned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16347480") - self.assertEqual(self.event_assigned.node_id, "MDEzOkFzc2lnbmVkRXZlbnQxNjM0NzQ4MA==") + self.assertEqual( + self.event_assigned.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16347480", + ) + self.assertEqual( + self.event_assigned.node_id, "MDEzOkFzc2lnbmVkRXZlbnQxNjM0NzQ4MA==" + ) self.assertEqual(self.event_assigned.commit_url, None) self.assertEqual(self.event_assigned.label, None) self.assertEqual(self.event_assigned.assignee.login, "jacquev6") @@ -117,18 +132,30 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_assigned.dismissed_review, None) self.assertEqual(self.event_assigned.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_assigned.__repr__(), 'IssueEvent(id=16347480)') + self.assertEqual(self.event_assigned.__repr__(), "IssueEvent(id=16347480)") def testEvent_referenced_Attributes(self): self.assertEqual(self.event_referenced.actor.login, "jacquev6") - self.assertEqual(self.event_referenced.commit_id, "ed866fc43833802ab553e5ff8581c81bb00dd433") - self.assertEqual(self.event_referenced.created_at, datetime.datetime(2012, 5, 27, 7, 29, 25)) + self.assertEqual( + self.event_referenced.commit_id, "ed866fc43833802ab553e5ff8581c81bb00dd433" + ) + self.assertEqual( + self.event_referenced.created_at, datetime.datetime(2012, 5, 27, 7, 29, 25) + ) self.assertEqual(self.event_referenced.event, "referenced") self.assertEqual(self.event_referenced.id, 16348656) self.assertEqual(self.event_referenced.issue.number, 30) - self.assertEqual(self.event_referenced.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16348656") - self.assertEqual(self.event_referenced.node_id, "MDE1OlJlZmVyZW5jZWRFdmVudDE2MzQ4NjU2") - self.assertEqual(self.event_referenced.commit_url, "https://api.github.com/repos/PyGithub/PyGithub/commits/ed866fc43833802ab553e5ff8581c81bb00dd433") + self.assertEqual( + self.event_referenced.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16348656", + ) + self.assertEqual( + self.event_referenced.node_id, "MDE1OlJlZmVyZW5jZWRFdmVudDE2MzQ4NjU2" + ) + self.assertEqual( + self.event_referenced.commit_url, + "https://api.github.com/repos/PyGithub/PyGithub/commits/ed866fc43833802ab553e5ff8581c81bb00dd433", + ) self.assertEqual(self.event_referenced.label, None) self.assertEqual(self.event_referenced.assignee, None) self.assertEqual(self.event_referenced.assigner, None) @@ -139,16 +166,21 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_referenced.dismissed_review, None) self.assertEqual(self.event_referenced.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_referenced.__repr__(), 'IssueEvent(id=16348656)') + self.assertEqual(self.event_referenced.__repr__(), "IssueEvent(id=16348656)") def testEvent_closed_Attributes(self): 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.assertEqual( + self.event_closed.created_at, datetime.datetime(2012, 5, 27, 11, 4, 25) + ) self.assertEqual(self.event_closed.event, "closed") self.assertEqual(self.event_closed.id, 16351220) self.assertEqual(self.event_closed.issue.number, 30) - self.assertEqual(self.event_closed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16351220") + self.assertEqual( + self.event_closed.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16351220", + ) self.assertEqual(self.event_closed.node_id, "MDExOkNsb3NlZEV2ZW50MTYzNTEyMjA=") self.assertEqual(self.event_closed.commit_url, None) self.assertEqual(self.event_closed.label, None) @@ -161,16 +193,21 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_closed.dismissed_review, None) self.assertEqual(self.event_closed.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_closed.__repr__(), 'IssueEvent(id=16351220)') + self.assertEqual(self.event_closed.__repr__(), "IssueEvent(id=16351220)") def testEvent_labeled_Attributes(self): 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.assertEqual( + self.event_labeled.created_at, datetime.datetime(2014, 3, 2, 18, 55, 10) + ) self.assertEqual(self.event_labeled.event, "labeled") self.assertEqual(self.event_labeled.id, 98136337) self.assertEqual(self.event_labeled.issue.number, 30) - self.assertEqual(self.event_labeled.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/98136337") + self.assertEqual( + self.event_labeled.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/98136337", + ) self.assertEqual(self.event_labeled.node_id, "MDEyOkxhYmVsZWRFdmVudDk4MTM2MzM3") self.assertEqual(self.event_labeled.commit_url, None) self.assertEqual(self.event_labeled.label.name, "v1") @@ -183,17 +220,24 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_labeled.dismissed_review, None) self.assertEqual(self.event_labeled.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_labeled.__repr__(), 'IssueEvent(id=98136337)') + self.assertEqual(self.event_labeled.__repr__(), "IssueEvent(id=98136337)") def testEvent_mentioned_Attributes(self): 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.assertEqual( + self.event_mentioned.created_at, datetime.datetime(2017, 3, 21, 17, 30, 14) + ) self.assertEqual(self.event_mentioned.event, "mentioned") self.assertEqual(self.event_mentioned.id, 1009034767) self.assertEqual(self.event_mentioned.issue.number, 538) - self.assertEqual(self.event_mentioned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1009034767") - self.assertEqual(self.event_mentioned.node_id, "MDE0Ok1lbnRpb25lZEV2ZW50MTAwOTAzNDc2Nw==") + self.assertEqual( + self.event_mentioned.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1009034767", + ) + self.assertEqual( + self.event_mentioned.node_id, "MDE0Ok1lbnRpb25lZEV2ZW50MTAwOTAzNDc2Nw==" + ) self.assertEqual(self.event_mentioned.commit_url, None) self.assertEqual(self.event_mentioned.label, None) self.assertEqual(self.event_mentioned.assignee, None) @@ -205,18 +249,30 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_mentioned.dismissed_review, None) self.assertEqual(self.event_mentioned.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_mentioned.__repr__(), 'IssueEvent(id=1009034767)') + self.assertEqual(self.event_mentioned.__repr__(), "IssueEvent(id=1009034767)") def testEvent_merged_Attributes(self): self.assertEqual(self.event_merged.actor.login, "jzelinskie") - self.assertEqual(self.event_merged.commit_id, "2525515b094d7425f7018eb5b66171e21c5fbc10") - self.assertEqual(self.event_merged.created_at, datetime.datetime(2017, 3, 25, 16, 52, 49)) + self.assertEqual( + self.event_merged.commit_id, "2525515b094d7425f7018eb5b66171e21c5fbc10" + ) + self.assertEqual( + self.event_merged.created_at, datetime.datetime(2017, 3, 25, 16, 52, 49) + ) self.assertEqual(self.event_merged.event, "merged") self.assertEqual(self.event_merged.id, 1015402964) self.assertEqual(self.event_merged.issue.number, 538) - self.assertEqual(self.event_merged.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1015402964") - self.assertEqual(self.event_merged.node_id, "MDExOk1lcmdlZEV2ZW50MTAxNTQwMjk2NA==") - self.assertEqual(self.event_merged.commit_url, "https://api.github.com/repos/PyGithub/PyGithub/commits/2525515b094d7425f7018eb5b66171e21c5fbc10") + self.assertEqual( + self.event_merged.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1015402964", + ) + self.assertEqual( + self.event_merged.node_id, "MDExOk1lcmdlZEV2ZW50MTAxNTQwMjk2NA==" + ) + self.assertEqual( + self.event_merged.commit_url, + "https://api.github.com/repos/PyGithub/PyGithub/commits/2525515b094d7425f7018eb5b66171e21c5fbc10", + ) self.assertEqual(self.event_merged.label, None) self.assertEqual(self.event_merged.assignee, None) self.assertEqual(self.event_merged.assigner, None) @@ -227,39 +283,61 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_merged.dismissed_review, None) self.assertEqual(self.event_merged.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_merged.__repr__(), 'IssueEvent(id=1015402964)') + self.assertEqual(self.event_merged.__repr__(), "IssueEvent(id=1015402964)") def testEvent_review_requested_Attributes(self): self.assertEqual(self.event_review_requested.actor.login, "jzelinskie") 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)) + self.assertEqual( + self.event_review_requested.created_at, + datetime.datetime(2017, 3, 22, 19, 6, 44), + ) self.assertEqual(self.event_review_requested.event, "review_requested") self.assertEqual(self.event_review_requested.id, 1011101309) self.assertEqual(self.event_review_requested.issue.number, 538) - self.assertEqual(self.event_review_requested.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1011101309") - self.assertEqual(self.event_review_requested.node_id, "MDIwOlJldmlld1JlcXVlc3RlZEV2ZW50MTAxMTEwMTMwOQ==") + self.assertEqual( + self.event_review_requested.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1011101309", + ) + self.assertEqual( + self.event_review_requested.node_id, + "MDIwOlJldmlld1JlcXVlc3RlZEV2ZW50MTAxMTEwMTMwOQ==", + ) self.assertEqual(self.event_review_requested.commit_url, None) self.assertEqual(self.event_review_requested.label, None) self.assertEqual(self.event_review_requested.assignee, None) self.assertEqual(self.event_review_requested.assigner, None) - self.assertEqual(self.event_review_requested.review_requester.login, "jzelinskie") - self.assertEqual(self.event_review_requested.requested_reviewer.login, "jzelinskie") + self.assertEqual( + self.event_review_requested.review_requester.login, "jzelinskie" + ) + self.assertEqual( + self.event_review_requested.requested_reviewer.login, "jzelinskie" + ) self.assertEqual(self.event_review_requested.milestone, None) self.assertEqual(self.event_review_requested.rename, None) self.assertEqual(self.event_review_requested.dismissed_review, None) self.assertEqual(self.event_review_requested.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_review_requested.__repr__(), 'IssueEvent(id=1011101309)') + self.assertEqual( + self.event_review_requested.__repr__(), "IssueEvent(id=1011101309)" + ) def testEvent_reopened_Attributes(self): 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.assertEqual( + self.event_reopened.created_at, datetime.datetime(2018, 8, 10, 13, 10, 9) + ) self.assertEqual(self.event_reopened.event, "reopened") self.assertEqual(self.event_reopened.id, 1782463023) self.assertEqual(self.event_reopened.issue.number, 857) - self.assertEqual(self.event_reopened.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463023") - self.assertEqual(self.event_reopened.node_id, "MDEzOlJlb3BlbmVkRXZlbnQxNzgyNDYzMDIz") + self.assertEqual( + self.event_reopened.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463023", + ) + self.assertEqual( + self.event_reopened.node_id, "MDEzOlJlb3BlbmVkRXZlbnQxNzgyNDYzMDIz" + ) self.assertEqual(self.event_reopened.commit_url, None) self.assertEqual(self.event_reopened.label, None) self.assertEqual(self.event_reopened.assignee, None) @@ -271,17 +349,24 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_reopened.dismissed_review, None) self.assertEqual(self.event_reopened.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_reopened.__repr__(), 'IssueEvent(id=1782463023)') + self.assertEqual(self.event_reopened.__repr__(), "IssueEvent(id=1782463023)") def testEvent_unassigned_Attributes(self): 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.assertEqual( + self.event_unassigned.created_at, datetime.datetime(2018, 8, 10, 13, 10, 21) + ) self.assertEqual(self.event_unassigned.event, "unassigned") self.assertEqual(self.event_unassigned.id, 1782463379) self.assertEqual(self.event_unassigned.issue.number, 857) - self.assertEqual(self.event_unassigned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463379") - self.assertEqual(self.event_unassigned.node_id, "MDE1OlVuYXNzaWduZWRFdmVudDE3ODI0NjMzNzk=") + self.assertEqual( + self.event_unassigned.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463379", + ) + self.assertEqual( + self.event_unassigned.node_id, "MDE1OlVuYXNzaWduZWRFdmVudDE3ODI0NjMzNzk=" + ) self.assertEqual(self.event_unassigned.commit_url, None) self.assertEqual(self.event_unassigned.label, None) self.assertEqual(self.event_unassigned.actor.login, "sfdye") @@ -293,17 +378,24 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unassigned.dismissed_review, None) self.assertEqual(self.event_unassigned.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_unassigned.__repr__(), 'IssueEvent(id=1782463379)') + self.assertEqual(self.event_unassigned.__repr__(), "IssueEvent(id=1782463379)") def testEvent_unlabeled_Attributes(self): 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.assertEqual( + self.event_unlabeled.created_at, datetime.datetime(2018, 8, 10, 13, 10, 38) + ) self.assertEqual(self.event_unlabeled.event, "unlabeled") self.assertEqual(self.event_unlabeled.id, 1782463917) self.assertEqual(self.event_unlabeled.issue.number, 857) - self.assertEqual(self.event_unlabeled.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463917") - self.assertEqual(self.event_unlabeled.node_id, "MDE0OlVubGFiZWxlZEV2ZW50MTc4MjQ2MzkxNw==") + self.assertEqual( + self.event_unlabeled.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463917", + ) + self.assertEqual( + self.event_unlabeled.node_id, "MDE0OlVubGFiZWxlZEV2ZW50MTc4MjQ2MzkxNw==" + ) self.assertEqual(self.event_unlabeled.commit_url, None) self.assertEqual(self.event_unlabeled.label.name, "improvement") self.assertEqual(self.event_unlabeled.assignee, None) @@ -315,17 +407,24 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unlabeled.dismissed_review, None) self.assertEqual(self.event_unlabeled.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_unlabeled.__repr__(), 'IssueEvent(id=1782463917)') + self.assertEqual(self.event_unlabeled.__repr__(), "IssueEvent(id=1782463917)") def testEvent_renamed_Attributes(self): 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.assertEqual( + self.event_renamed.created_at, datetime.datetime(2018, 8, 10, 13, 15, 18) + ) self.assertEqual(self.event_renamed.event, "renamed") self.assertEqual(self.event_renamed.id, 1782472556) self.assertEqual(self.event_renamed.issue.number, 857) - self.assertEqual(self.event_renamed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782472556") - self.assertEqual(self.event_renamed.node_id, "MDE3OlJlbmFtZWRUaXRsZUV2ZW50MTc4MjQ3MjU1Ng==") + self.assertEqual( + self.event_renamed.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782472556", + ) + self.assertEqual( + self.event_renamed.node_id, "MDE3OlJlbmFtZWRUaXRsZUV2ZW50MTc4MjQ3MjU1Ng==" + ) self.assertEqual(self.event_renamed.commit_url, None) self.assertEqual(self.event_renamed.label, None) self.assertEqual(self.event_renamed.assignee, None) @@ -333,21 +432,36 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_renamed.review_requester, None) self.assertEqual(self.event_renamed.requested_reviewer, None) self.assertEqual(self.event_renamed.milestone, None) - self.assertEqual(self.event_renamed.rename, {u'to': u'Adding new attributes to IssueEvent', u'from': u'Adding new attributes to IssueEvent Object (DO NOT MERGE - SEE NOTES)'}) + self.assertEqual( + self.event_renamed.rename, + { + u"to": u"Adding new attributes to IssueEvent", + u"from": u"Adding new attributes to IssueEvent Object (DO NOT MERGE - SEE NOTES)", + }, + ) self.assertEqual(self.event_renamed.dismissed_review, None) self.assertEqual(self.event_renamed.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_renamed.__repr__(), 'IssueEvent(id=1782472556)') + self.assertEqual(self.event_renamed.__repr__(), "IssueEvent(id=1782472556)") def testEvent_base_ref_changed_Attributes(self): self.assertEqual(self.event_base_ref_changed.actor.login, "allevin") 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)) + self.assertEqual( + self.event_base_ref_changed.created_at, + datetime.datetime(2018, 8, 10, 16, 38, 22), + ) self.assertEqual(self.event_base_ref_changed.event, "base_ref_changed") self.assertEqual(self.event_base_ref_changed.id, 1782915693) self.assertEqual(self.event_base_ref_changed.issue.number, 857) - self.assertEqual(self.event_base_ref_changed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782915693") - self.assertEqual(self.event_base_ref_changed.node_id, "MDE5OkJhc2VSZWZDaGFuZ2VkRXZlbnQxNzgyOTE1Njkz") + self.assertEqual( + self.event_base_ref_changed.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782915693", + ) + self.assertEqual( + self.event_base_ref_changed.node_id, + "MDE5OkJhc2VSZWZDaGFuZ2VkRXZlbnQxNzgyOTE1Njkz", + ) self.assertEqual(self.event_base_ref_changed.commit_url, None) self.assertEqual(self.event_base_ref_changed.label, None) self.assertEqual(self.event_base_ref_changed.assignee, None) @@ -359,17 +473,28 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_base_ref_changed.dismissed_review, None) self.assertEqual(self.event_base_ref_changed.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_base_ref_changed.__repr__(), 'IssueEvent(id=1782915693)') + self.assertEqual( + self.event_base_ref_changed.__repr__(), "IssueEvent(id=1782915693)" + ) def testEvent_head_ref_deleted_Attributes(self): self.assertEqual(self.event_head_ref_deleted.actor.login, "allevin") 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)) + self.assertEqual( + self.event_head_ref_deleted.created_at, + datetime.datetime(2018, 8, 10, 16, 39, 20), + ) self.assertEqual(self.event_head_ref_deleted.event, "head_ref_deleted") self.assertEqual(self.event_head_ref_deleted.id, 1782917185) self.assertEqual(self.event_head_ref_deleted.issue.number, 857) - self.assertEqual(self.event_head_ref_deleted.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782917185") - self.assertEqual(self.event_head_ref_deleted.node_id, "MDE5OkhlYWRSZWZEZWxldGVkRXZlbnQxNzgyOTE3MTg1") + self.assertEqual( + self.event_head_ref_deleted.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782917185", + ) + self.assertEqual( + self.event_head_ref_deleted.node_id, + "MDE5OkhlYWRSZWZEZWxldGVkRXZlbnQxNzgyOTE3MTg1", + ) self.assertEqual(self.event_head_ref_deleted.commit_url, None) self.assertEqual(self.event_head_ref_deleted.label, None) self.assertEqual(self.event_head_ref_deleted.assignee, None) @@ -381,17 +506,28 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_head_ref_deleted.dismissed_review, None) self.assertEqual(self.event_head_ref_deleted.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_head_ref_deleted.__repr__(), 'IssueEvent(id=1782917185)') + self.assertEqual( + self.event_head_ref_deleted.__repr__(), "IssueEvent(id=1782917185)" + ) def testEvent_head_ref_restored_Attributes(self): self.assertEqual(self.event_head_ref_restored.actor.login, "allevin") 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)) + self.assertEqual( + self.event_head_ref_restored.created_at, + datetime.datetime(2018, 8, 10, 16, 39, 23), + ) self.assertEqual(self.event_head_ref_restored.event, "head_ref_restored") self.assertEqual(self.event_head_ref_restored.id, 1782917299) self.assertEqual(self.event_head_ref_restored.issue.number, 857) - self.assertEqual(self.event_head_ref_restored.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782917299") - self.assertEqual(self.event_head_ref_restored.node_id, "MDIwOkhlYWRSZWZSZXN0b3JlZEV2ZW50MTc4MjkxNzI5OQ==") + self.assertEqual( + self.event_head_ref_restored.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782917299", + ) + self.assertEqual( + self.event_head_ref_restored.node_id, + "MDIwOkhlYWRSZWZSZXN0b3JlZEV2ZW50MTc4MjkxNzI5OQ==", + ) self.assertEqual(self.event_head_ref_restored.commit_url, None) self.assertEqual(self.event_head_ref_restored.label, None) self.assertEqual(self.event_head_ref_restored.assignee, None) @@ -403,17 +539,26 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_head_ref_restored.dismissed_review, None) self.assertEqual(self.event_head_ref_deleted.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_head_ref_restored.__repr__(), 'IssueEvent(id=1782917299)') + self.assertEqual( + self.event_head_ref_restored.__repr__(), "IssueEvent(id=1782917299)" + ) def testEvent_milestoned_Attributes(self): 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.assertEqual( + self.event_milestoned.created_at, datetime.datetime(2018, 8, 11, 0, 46, 19) + ) self.assertEqual(self.event_milestoned.event, "milestoned") self.assertEqual(self.event_milestoned.id, 1783596418) self.assertEqual(self.event_milestoned.issue.number, 857) - self.assertEqual(self.event_milestoned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596418") - self.assertEqual(self.event_milestoned.node_id, "MDE1Ok1pbGVzdG9uZWRFdmVudDE3ODM1OTY0MTg=") + self.assertEqual( + self.event_milestoned.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596418", + ) + self.assertEqual( + self.event_milestoned.node_id, "MDE1Ok1pbGVzdG9uZWRFdmVudDE3ODM1OTY0MTg=" + ) self.assertEqual(self.event_milestoned.commit_url, None) self.assertEqual(self.event_milestoned.label, None) self.assertEqual(self.event_milestoned.assignee, None) @@ -425,17 +570,26 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_milestoned.dismissed_review, None) self.assertEqual(self.event_milestoned.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_milestoned.__repr__(), 'IssueEvent(id=1783596418)') + self.assertEqual(self.event_milestoned.__repr__(), "IssueEvent(id=1783596418)") def testEvent_demilestoned_Attributes(self): self.assertEqual(self.event_demilestoned.actor.login, "sfdye") self.assertEqual(self.event_demilestoned.commit_id, None) - self.assertEqual(self.event_demilestoned.created_at, datetime.datetime(2018, 8, 11, 0, 46, 22)) + self.assertEqual( + self.event_demilestoned.created_at, + datetime.datetime(2018, 8, 11, 0, 46, 22), + ) self.assertEqual(self.event_demilestoned.event, "demilestoned") self.assertEqual(self.event_demilestoned.id, 1783596452) self.assertEqual(self.event_demilestoned.issue.number, 857) - self.assertEqual(self.event_demilestoned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596452") - self.assertEqual(self.event_demilestoned.node_id, "MDE3OkRlbWlsZXN0b25lZEV2ZW50MTc4MzU5NjQ1Mg==") + self.assertEqual( + self.event_demilestoned.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596452", + ) + self.assertEqual( + self.event_demilestoned.node_id, + "MDE3OkRlbWlsZXN0b25lZEV2ZW50MTc4MzU5NjQ1Mg==", + ) self.assertEqual(self.event_demilestoned.commit_url, None) self.assertEqual(self.event_demilestoned.label, None) self.assertEqual(self.event_demilestoned.assignee, None) @@ -447,17 +601,26 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_demilestoned.dismissed_review, None) self.assertEqual(self.event_demilestoned.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_demilestoned.__repr__(), 'IssueEvent(id=1783596452)') + self.assertEqual( + self.event_demilestoned.__repr__(), "IssueEvent(id=1783596452)" + ) def testEvent_locked_Attributes(self): 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.assertEqual( + self.event_locked.created_at, datetime.datetime(2018, 8, 11, 0, 46, 56) + ) self.assertEqual(self.event_locked.event, "locked") self.assertEqual(self.event_locked.id, 1783596743) self.assertEqual(self.event_locked.issue.number, 857) - self.assertEqual(self.event_locked.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596743") - self.assertEqual(self.event_locked.node_id, "MDExOkxvY2tlZEV2ZW50MTc4MzU5Njc0Mw==") + self.assertEqual( + self.event_locked.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596743", + ) + self.assertEqual( + self.event_locked.node_id, "MDExOkxvY2tlZEV2ZW50MTc4MzU5Njc0Mw==" + ) self.assertEqual(self.event_locked.commit_url, None) self.assertEqual(self.event_locked.label, None) self.assertEqual(self.event_locked.assignee, None) @@ -468,18 +631,25 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_locked.rename, None) self.assertEqual(self.event_locked.dismissed_review, None) self.assertEqual(self.event_locked.lock_reason, "too heated") -### # test __repr__() based on this attributes - self.assertEqual(self.event_locked.__repr__(), 'IssueEvent(id=1783596743)') + ### # test __repr__() based on this attributes + self.assertEqual(self.event_locked.__repr__(), "IssueEvent(id=1783596743)") def testEvent_unlocked_Attributes(self): 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.assertEqual( + self.event_unlocked.created_at, datetime.datetime(2018, 8, 11, 0, 47, 7) + ) self.assertEqual(self.event_unlocked.event, "unlocked") self.assertEqual(self.event_unlocked.id, 1783596818) self.assertEqual(self.event_unlocked.issue.number, 857) - self.assertEqual(self.event_unlocked.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596818") - self.assertEqual(self.event_unlocked.node_id, "MDEzOlVubG9ja2VkRXZlbnQxNzgzNTk2ODE4") + self.assertEqual( + self.event_unlocked.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596818", + ) + self.assertEqual( + self.event_unlocked.node_id, "MDEzOlVubG9ja2VkRXZlbnQxNzgzNTk2ODE4" + ) self.assertEqual(self.event_unlocked.commit_url, None) self.assertEqual(self.event_unlocked.label, None) self.assertEqual(self.event_unlocked.assignee, None) @@ -491,17 +661,26 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unlocked.dismissed_review, None) self.assertEqual(self.event_unlocked.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_unlocked.__repr__(), 'IssueEvent(id=1783596818)') + self.assertEqual(self.event_unlocked.__repr__(), "IssueEvent(id=1783596818)") def testEvent_review_dismissed_Attributes(self): self.assertEqual(self.event_review_dismissed.actor.login, "sfdye") 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)) + self.assertEqual( + self.event_review_dismissed.created_at, + datetime.datetime(2018, 8, 11, 1, 7, 10), + ) self.assertEqual(self.event_review_dismissed.event, "review_dismissed") self.assertEqual(self.event_review_dismissed.id, 1783605084) self.assertEqual(self.event_review_dismissed.issue.number, 857) - self.assertEqual(self.event_review_dismissed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783605084") - self.assertEqual(self.event_review_dismissed.node_id, "MDIwOlJldmlld0Rpc21pc3NlZEV2ZW50MTc4MzYwNTA4NA==") + self.assertEqual( + self.event_review_dismissed.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783605084", + ) + self.assertEqual( + self.event_review_dismissed.node_id, + "MDIwOlJldmlld0Rpc21pc3NlZEV2ZW50MTc4MzYwNTA4NA==", + ) self.assertEqual(self.event_review_dismissed.commit_url, None) self.assertEqual(self.event_review_dismissed.label, None) self.assertEqual(self.event_review_dismissed.assignee, None) @@ -510,42 +689,77 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_review_dismissed.requested_reviewer, None) self.assertEqual(self.event_review_dismissed.milestone, None) self.assertEqual(self.event_review_dismissed.rename, None) - self.assertEqual(self.event_review_dismissed.dismissed_review, {u'dismissal_message': u'dismiss', u'state': u'changes_requested', u'review_id': 145431295}) + self.assertEqual( + self.event_review_dismissed.dismissed_review, + { + u"dismissal_message": u"dismiss", + u"state": u"changes_requested", + u"review_id": 145431295, + }, + ) self.assertEqual(self.event_review_dismissed.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_review_dismissed.__repr__(), 'IssueEvent(id=1783605084)') + self.assertEqual( + self.event_review_dismissed.__repr__(), "IssueEvent(id=1783605084)" + ) def testEvent_review_request_removed_Attributes(self): self.assertEqual(self.event_review_request_removed.actor.login, "sfdye") 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)) - self.assertEqual(self.event_review_request_removed.event, "review_request_removed") + self.assertEqual( + self.event_review_request_removed.created_at, + datetime.datetime(2018, 8, 11, 12, 32, 59), + ) + self.assertEqual( + self.event_review_request_removed.event, "review_request_removed" + ) self.assertEqual(self.event_review_request_removed.id, 1783779835) self.assertEqual(self.event_review_request_removed.issue.number, 857) - self.assertEqual(self.event_review_request_removed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783779835") - self.assertEqual(self.event_review_request_removed.node_id, "MDI1OlJldmlld1JlcXVlc3RSZW1vdmVkRXZlbnQxNzgzNzc5ODM1") + self.assertEqual( + self.event_review_request_removed.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783779835", + ) + self.assertEqual( + self.event_review_request_removed.node_id, + "MDI1OlJldmlld1JlcXVlc3RSZW1vdmVkRXZlbnQxNzgzNzc5ODM1", + ) self.assertEqual(self.event_review_request_removed.commit_url, None) self.assertEqual(self.event_review_request_removed.label, None) self.assertEqual(self.event_review_request_removed.assignee, None) self.assertEqual(self.event_review_request_removed.assigner, None) - self.assertEqual(self.event_review_request_removed.review_requester.login, "sfdye") - self.assertEqual(self.event_review_request_removed.requested_reviewer.login, "jasonwhite") + self.assertEqual( + self.event_review_request_removed.review_requester.login, "sfdye" + ) + self.assertEqual( + self.event_review_request_removed.requested_reviewer.login, "jasonwhite" + ) self.assertEqual(self.event_review_request_removed.milestone, None) self.assertEqual(self.event_review_request_removed.rename, None) self.assertEqual(self.event_review_request_removed.dismissed_review, None) self.assertEqual(self.event_review_request_removed.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_review_request_removed.__repr__(), 'IssueEvent(id=1783779835)') + self.assertEqual( + self.event_review_request_removed.__repr__(), "IssueEvent(id=1783779835)" + ) def testEvent_marked_as_duplicate_Attributes(self): self.assertEqual(self.event_marked_as_duplicate.actor.login, "sfdye") 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)) + self.assertEqual( + self.event_marked_as_duplicate.created_at, + datetime.datetime(2018, 8, 11, 12, 32, 35), + ) self.assertEqual(self.event_marked_as_duplicate.event, "marked_as_duplicate") self.assertEqual(self.event_marked_as_duplicate.id, 1783779725) self.assertEqual(self.event_marked_as_duplicate.issue.number, 857) - self.assertEqual(self.event_marked_as_duplicate.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783779725") - self.assertEqual(self.event_marked_as_duplicate.node_id, "MDIyOk1hcmtlZEFzRHVwbGljYXRlRXZlbnQxNzgzNzc5NzI1") + self.assertEqual( + self.event_marked_as_duplicate.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783779725", + ) + self.assertEqual( + self.event_marked_as_duplicate.node_id, + "MDIyOk1hcmtlZEFzRHVwbGljYXRlRXZlbnQxNzgzNzc5NzI1", + ) self.assertEqual(self.event_marked_as_duplicate.commit_url, None) self.assertEqual(self.event_marked_as_duplicate.label, None) self.assertEqual(self.event_marked_as_duplicate.assignee, None) @@ -557,17 +771,30 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_marked_as_duplicate.dismissed_review, None) self.assertEqual(self.event_marked_as_duplicate.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_marked_as_duplicate.__repr__(), 'IssueEvent(id=1783779725)') + self.assertEqual( + self.event_marked_as_duplicate.__repr__(), "IssueEvent(id=1783779725)" + ) def testEvent_unmarked_as_duplicate_Attributes(self): self.assertEqual(self.event_unmarked_as_duplicate.actor.login, "sfdye") 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)) - self.assertEqual(self.event_unmarked_as_duplicate.event, "unmarked_as_duplicate") + self.assertEqual( + self.event_unmarked_as_duplicate.created_at, + datetime.datetime(2018, 8, 15, 2, 57, 46), + ) + self.assertEqual( + self.event_unmarked_as_duplicate.event, "unmarked_as_duplicate" + ) self.assertEqual(self.event_unmarked_as_duplicate.id, 1789228962) self.assertEqual(self.event_unmarked_as_duplicate.issue.number, 857) - self.assertEqual(self.event_unmarked_as_duplicate.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1789228962") - self.assertEqual(self.event_unmarked_as_duplicate.node_id, "MDI0OlVubWFya2VkQXNEdXBsaWNhdGVFdmVudDE3ODkyMjg5NjI=") + self.assertEqual( + self.event_unmarked_as_duplicate.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1789228962", + ) + self.assertEqual( + self.event_unmarked_as_duplicate.node_id, + "MDI0OlVubWFya2VkQXNEdXBsaWNhdGVFdmVudDE3ODkyMjg5NjI=", + ) self.assertEqual(self.event_unmarked_as_duplicate.commit_url, None) self.assertEqual(self.event_unmarked_as_duplicate.label, None) self.assertEqual(self.event_unmarked_as_duplicate.assignee, None) @@ -579,17 +806,28 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_unmarked_as_duplicate.dismissed_review, None) self.assertEqual(self.event_unmarked_as_duplicate.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_unmarked_as_duplicate.__repr__(), 'IssueEvent(id=1789228962)') + self.assertEqual( + self.event_unmarked_as_duplicate.__repr__(), "IssueEvent(id=1789228962)" + ) def testEvent_added_to_project_Attributes(self): self.assertEqual(self.event_added_to_project.actor.login, "sfdye") 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)) + self.assertEqual( + self.event_added_to_project.created_at, + datetime.datetime(2018, 8, 16, 8, 13, 24), + ) self.assertEqual(self.event_added_to_project.event, "added_to_project") self.assertEqual(self.event_added_to_project.id, 1791766828) self.assertEqual(self.event_added_to_project.issue.number, 857) - self.assertEqual(self.event_added_to_project.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791766828") - self.assertEqual(self.event_added_to_project.node_id, "MDE5OkFkZGVkVG9Qcm9qZWN0RXZlbnQxNzkxNzY2ODI4") + self.assertEqual( + self.event_added_to_project.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791766828", + ) + self.assertEqual( + self.event_added_to_project.node_id, + "MDE5OkFkZGVkVG9Qcm9qZWN0RXZlbnQxNzkxNzY2ODI4", + ) self.assertEqual(self.event_added_to_project.commit_url, None) self.assertEqual(self.event_added_to_project.label, None) self.assertEqual(self.event_added_to_project.assignee, None) @@ -601,17 +839,30 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_added_to_project.dismissed_review, None) self.assertEqual(self.event_added_to_project.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_added_to_project.__repr__(), 'IssueEvent(id=1791766828)') + self.assertEqual( + self.event_added_to_project.__repr__(), "IssueEvent(id=1791766828)" + ) def testEvent_moved_columns_in_project_Attributes(self): self.assertEqual(self.event_moved_columns_in_project.actor.login, "sfdye") 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)) - self.assertEqual(self.event_moved_columns_in_project.event, "moved_columns_in_project") + self.assertEqual( + self.event_moved_columns_in_project.created_at, + datetime.datetime(2018, 8, 16, 8, 13, 55), + ) + self.assertEqual( + self.event_moved_columns_in_project.event, "moved_columns_in_project" + ) self.assertEqual(self.event_moved_columns_in_project.id, 1791767766) self.assertEqual(self.event_moved_columns_in_project.issue.number, 857) - self.assertEqual(self.event_moved_columns_in_project.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791767766") - self.assertEqual(self.event_moved_columns_in_project.node_id, "MDI2Ok1vdmVkQ29sdW1uc0luUHJvamVjdEV2ZW50MTc5MTc2Nzc2Ng==") + self.assertEqual( + self.event_moved_columns_in_project.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791767766", + ) + self.assertEqual( + self.event_moved_columns_in_project.node_id, + "MDI2Ok1vdmVkQ29sdW1uc0luUHJvamVjdEV2ZW50MTc5MTc2Nzc2Ng==", + ) self.assertEqual(self.event_moved_columns_in_project.commit_url, None) self.assertEqual(self.event_moved_columns_in_project.label, None) self.assertEqual(self.event_moved_columns_in_project.assignee, None) @@ -623,17 +874,28 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_moved_columns_in_project.dismissed_review, None) self.assertEqual(self.event_moved_columns_in_project.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_moved_columns_in_project.__repr__(), 'IssueEvent(id=1791767766)') + self.assertEqual( + self.event_moved_columns_in_project.__repr__(), "IssueEvent(id=1791767766)" + ) def testEvent_removed_from_project_Attributes(self): self.assertEqual(self.event_removed_from_project.actor.login, "sfdye") 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)) + self.assertEqual( + self.event_removed_from_project.created_at, + datetime.datetime(2018, 8, 16, 8, 14, 8), + ) self.assertEqual(self.event_removed_from_project.event, "removed_from_project") self.assertEqual(self.event_removed_from_project.id, 1791768212) self.assertEqual(self.event_removed_from_project.issue.number, 857) - self.assertEqual(self.event_removed_from_project.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791768212") - self.assertEqual(self.event_removed_from_project.node_id, "MDIzOlJlbW92ZWRGcm9tUHJvamVjdEV2ZW50MTc5MTc2ODIxMg==") + self.assertEqual( + self.event_removed_from_project.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791768212", + ) + self.assertEqual( + self.event_removed_from_project.node_id, + "MDIzOlJlbW92ZWRGcm9tUHJvamVjdEV2ZW50MTc5MTc2ODIxMg==", + ) self.assertEqual(self.event_removed_from_project.commit_url, None) self.assertEqual(self.event_removed_from_project.label, None) self.assertEqual(self.event_removed_from_project.assignee, None) @@ -645,17 +907,30 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_removed_from_project.dismissed_review, None) self.assertEqual(self.event_removed_from_project.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_removed_from_project.__repr__(), 'IssueEvent(id=1791768212)') + self.assertEqual( + self.event_removed_from_project.__repr__(), "IssueEvent(id=1791768212)" + ) def testEvent_converted_note_to_issue_Attributes(self): self.assertEqual(self.event_converted_note_to_issue.actor.login, "sfdye") 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)) - self.assertEqual(self.event_converted_note_to_issue.event, "converted_note_to_issue") + self.assertEqual( + self.event_converted_note_to_issue.created_at, + datetime.datetime(2018, 8, 16, 8, 14, 34), + ) + self.assertEqual( + self.event_converted_note_to_issue.event, "converted_note_to_issue" + ) self.assertEqual(self.event_converted_note_to_issue.id, 1791769149) self.assertEqual(self.event_converted_note_to_issue.issue.number, 866) - self.assertEqual(self.event_converted_note_to_issue.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791769149") - self.assertEqual(self.event_converted_note_to_issue.node_id, "MDI1OkNvbnZlcnRlZE5vdGVUb0lzc3VlRXZlbnQxNzkxNzY5MTQ5") + self.assertEqual( + self.event_converted_note_to_issue.url, + "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791769149", + ) + self.assertEqual( + self.event_converted_note_to_issue.node_id, + "MDI1OkNvbnZlcnRlZE5vdGVUb0lzc3VlRXZlbnQxNzkxNzY5MTQ5", + ) self.assertEqual(self.event_converted_note_to_issue.commit_url, None) self.assertEqual(self.event_converted_note_to_issue.label, None) self.assertEqual(self.event_converted_note_to_issue.assignee, None) @@ -667,4 +942,6 @@ class IssueEvent(Framework.TestCase): self.assertEqual(self.event_converted_note_to_issue.dismissed_review, None) self.assertEqual(self.event_converted_note_to_issue.lock_reason, None) # test __repr__() based on this attributes - self.assertEqual(self.event_converted_note_to_issue.__repr__(), 'IssueEvent(id=1791769149)') + self.assertEqual( + self.event_converted_note_to_issue.__repr__(), "IssueEvent(id=1791769149)" + ) diff --git a/tests/Label.py b/tests/Label.py index 0628c7ea..60ecd4a2 100644 --- a/tests/Label.py +++ b/tests/Label.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -42,17 +43,24 @@ class Label(Framework.TestCase): self.assertEqual(self.label.color, "e10c02") self.assertEqual(self.label.name, "Bug") self.assertIsNone(self.label.description) - self.assertEqual(self.label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Bug") + self.assertEqual( + self.label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Bug" + ) # test __repr__() based on this attributes self.assertEqual(self.label.__repr__(), 'Label(name="Bug")') def testEdit(self): - self.label.edit("LabelEditedByPyGithub", "0000ff", "Description of LabelEditedByPyGithub") + self.label.edit( + "LabelEditedByPyGithub", "0000ff", "Description of LabelEditedByPyGithub" + ) self.assertEqual(self.label.color, "0000ff") self.assertEqual(self.label.description, "Description of LabelEditedByPyGithub") self.assertEqual(self.label.name, "LabelEditedByPyGithub") - self.assertEqual(self.label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub") + self.assertEqual( + self.label.url, + "https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub", + ) def testDelete(self): self.label.delete() diff --git a/tests/License.py b/tests/License.py index 03b35390..0f51a3a1 100644 --- a/tests/License.py +++ b/tests/License.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -34,9 +35,18 @@ class License(Framework.TestCase): def testAttributes(self): self.assertEqual(self.license.key, "mit") self.assertEqual(self.license.name, "MIT License") - self.assertEqual(self.license.description, "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.") + self.assertEqual( + self.license.description, + "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.", + ) self.assertEqual(self.license.spdx_id, "MIT") - self.assertEqual(self.license.body, """MIT License\n\nCopyright (c) [year] [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n""") - self.assertEqual(self.license.permissions, ['commercial-use', 'modifications', 'distribution', 'private-use']) - self.assertEqual(self.license.conditions, ['include-copyright']) - self.assertEqual(self.license.limitations, ['liability', 'warranty']) + self.assertEqual( + self.license.body, + """MIT License\n\nCopyright (c) [year] [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n""", + ) + self.assertEqual( + self.license.permissions, + ["commercial-use", "modifications", "distribution", "private-use"], + ) + self.assertEqual(self.license.conditions, ["include-copyright"]) + self.assertEqual(self.license.limitations, ["liability", "warranty"]) diff --git a/tests/Logging_.py b/tests/Logging_.py index 7bbc6199..52c1fe80 100644 --- a/tests/Logging_.py +++ b/tests/Logging_.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + import logging import sys @@ -57,24 +58,45 @@ class Logging(Framework.BasicTestCase): logger.addHandler(self.__handler) def testLoggingWithBasicAuthentication(self): - self.assertEqual(github.Github(self.login, self.password).get_user().name, "Vincent Jacques") + self.assertEqual( + github.Github(self.login, self.password).get_user().name, "Vincent Jacques" + ) # In Python 3.4+, dicts are not output in the same order as in Python 2.7. # So, logging is not deterministic and we cannot test it. if python2: - self.assertEqual(self.__handler.handled, 'GET https://api.github.com/user {\'Authorization\': \'Basic (login and password removed)\', \'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'content-length\': \'806\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'x-ratelimit-remaining\': \'4993\', \'server\': \'nginx\', \'last-modified\': \'Fri, 14 Sep 2012 18:47:46 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"434dfe5d3f50558fe3cea087cb95c401"\', \'cache-control\': \'private, s-maxage=60, max-age=60\', \'date\': \'Mon, 17 Sep 2012 17:12:32 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"owned_private_repos":3,"disk_usage":18612,"following":28,"type":"User","public_repos":13,"location":"Paris, France","company":"Criteo","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","plan":{"space":614400,"private_repos":5,"name":"micro","collaborators":1},"blog":"http://vincent-jacques.net","login":"jacquev6","public_gists":3,"html_url":"https://github.com/jacquev6","hireable":false,"created_at":"2010-07-09T06:10:06Z","private_gists":5,"followers":13,"name":"Vincent Jacques","email":"vincent@vincent-jacques.net","bio":"","total_private_repos":3,"collaborators":0,"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"url":"https://api.github.com/users/jacquev6"}') + self.assertEqual( + self.__handler.handled, + 'GET https://api.github.com/user {\'Authorization\': \'Basic (login and password removed)\', \'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'content-length\': \'806\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'x-ratelimit-remaining\': \'4993\', \'server\': \'nginx\', \'last-modified\': \'Fri, 14 Sep 2012 18:47:46 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"434dfe5d3f50558fe3cea087cb95c401"\', \'cache-control\': \'private, s-maxage=60, max-age=60\', \'date\': \'Mon, 17 Sep 2012 17:12:32 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"owned_private_repos":3,"disk_usage":18612,"following":28,"type":"User","public_repos":13,"location":"Paris, France","company":"Criteo","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","plan":{"space":614400,"private_repos":5,"name":"micro","collaborators":1},"blog":"http://vincent-jacques.net","login":"jacquev6","public_gists":3,"html_url":"https://github.com/jacquev6","hireable":false,"created_at":"2010-07-09T06:10:06Z","private_gists":5,"followers":13,"name":"Vincent Jacques","email":"vincent@vincent-jacques.net","bio":"","total_private_repos":3,"collaborators":0,"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"url":"https://api.github.com/users/jacquev6"}', + ) def testLoggingWithOAuthAuthentication(self): - self.assertEqual(github.Github(self.oauth_token).get_user().name, "Vincent Jacques") + self.assertEqual( + github.Github(self.oauth_token).get_user().name, "Vincent Jacques" + ) if python2: - self.assertEqual(self.__handler.handled, 'GET https://api.github.com/user {\'Authorization\': \'token (oauth token removed)\', \'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'x-ratelimit-remaining\': \'4993\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'content-length\': \'628\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"c23ad6b5815fc3d6ec6341c4a47afe85"\', \'cache-control\': \'private, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:36:54 GMT\', \'x-oauth-scopes\': \'\', \'content-type\': \'application/json; charset=utf-8\', \'x-accepted-oauth-scopes\': \'user\'} {"type":"User","bio":"","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","blog":"http://vincent-jacques.net","public_repos":13,"created_at":"2010-07-09T06:10:06Z","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","email":"vincent@vincent-jacques.net","following":29,"name":"Vincent Jacques","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","hireable":false,"id":327146,"public_gists":3,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') + self.assertEqual( + self.__handler.handled, + "GET https://api.github.com/user {'Authorization': 'token (oauth token removed)', 'User-Agent': 'PyGithub/Python'} None ==> 200 {'status': '200 OK', 'x-ratelimit-remaining': '4993', 'x-github-media-type': 'github.beta; format=json', 'x-content-type-options': 'nosniff', 'vary': 'Accept, Authorization, Cookie', 'content-length': '628', 'server': 'nginx', 'last-modified': 'Tue, 25 Sep 2012 07:42:42 GMT', 'connection': 'keep-alive', 'x-ratelimit-limit': '5000', 'etag': '\"c23ad6b5815fc3d6ec6341c4a47afe85\"', 'cache-control': 'private, max-age=60, s-maxage=60', 'date': 'Tue, 25 Sep 2012 20:36:54 GMT', 'x-oauth-scopes': '', 'content-type': 'application/json; charset=utf-8', 'x-accepted-oauth-scopes': 'user'} {\"type\":\"User\",\"bio\":\"\",\"html_url\":\"https://github.com/jacquev6\",\"login\":\"jacquev6\",\"followers\":14,\"company\":\"Criteo\",\"blog\":\"http://vincent-jacques.net\",\"public_repos\":13,\"created_at\":\"2010-07-09T06:10:06Z\",\"avatar_url\":\"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png\",\"email\":\"vincent@vincent-jacques.net\",\"following\":29,\"name\":\"Vincent Jacques\",\"gravatar_id\":\"b68de5ae38616c296fa345d2b9df2225\",\"hireable\":false,\"id\":327146,\"public_gists\":3,\"location\":\"Paris, France\",\"url\":\"https://api.github.com/users/jacquev6\"}", + ) def testLoggingWithoutAuthentication(self): self.assertEqual(github.Github().get_user("jacquev6").name, "Vincent Jacques") if python2: - self.assertEqual(self.__handler.handled, 'GET https://api.github.com/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') + self.assertEqual( + self.__handler.handled, + 'GET https://api.github.com/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}', + ) def testLoggingWithBaseUrl(self): # ReplayData forged, not recorded - self.assertEqual(github.Github(base_url="http://my.enterprise.com/my/prefix").get_user("jacquev6").name, "Vincent Jacques") + self.assertEqual( + github.Github(base_url="http://my.enterprise.com/my/prefix") + .get_user("jacquev6") + .name, + "Vincent Jacques", + ) if python2: - self.assertEqual(self.__handler.handled, 'GET http://my.enterprise.com/my/prefix/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') + self.assertEqual( + self.__handler.handled, + 'GET http://my.enterprise.com/my/prefix/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} None ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}', + ) diff --git a/tests/Markdown.py b/tests/Markdown.py index 733f611c..1870928f 100644 --- a/tests/Markdown.py +++ b/tests/Markdown.py @@ -28,6 +28,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -38,7 +39,13 @@ class Markdown(Framework.TestCase): self.repo = self.g.get_user().get_repo("PyGithub") def testRenderMarkdown(self): - self.assertEqual(self.g.render_markdown(self.text), '

MyTitle

Issue #1

') + self.assertEqual( + self.g.render_markdown(self.text), + '

MyTitle

Issue #1

', + ) def testRenderGithubFlavoredMarkdown(self): - self.assertEqual(self.g.render_markdown(self.text, self.repo), '

MyTitle

Issue #1

') + self.assertEqual( + self.g.render_markdown(self.text, self.repo), + '

MyTitle

Issue #1

', + ) diff --git a/tests/Migration.py b/tests/Migration.py index 0d71507f..a05664fd 100644 --- a/tests/Migration.py +++ b/tests/Migration.py @@ -48,14 +48,15 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + +import datetime import github -import datetime + +from . import Framework class Migration(Framework.TestCase): - def setUp(self): Framework.TestCase.setUp(self) self.user = self.g.get_user() @@ -70,24 +71,37 @@ class Migration(Framework.TestCase): self.assertEqual(self.migration.exclude_attachments, False) self.assertEqual(len(self.migration.repositories), 1) self.assertEqual(self.migration.repositories[0].name, "sample-repo") - self.assertEqual(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.assertEqual(self.migration.updated_at, datetime.datetime(2018, 9, 14, 1, 35, 46)) + self.assertEqual( + 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.assertEqual( + self.migration.updated_at, datetime.datetime(2018, 9, 14, 1, 35, 46) + ) def testGetArchiveUrlWhenNotExported(self): - self.assertRaises(github.UnknownObjectException, lambda: self.migration.get_archive_url()) + self.assertRaises( + github.UnknownObjectException, lambda: self.migration.get_archive_url() + ) def testGetStatus(self): self.assertEqual(self.migration.get_status(), "exported") def testGetArchiveUrlWhenExported(self): - self.assertEqual(self.migration.get_archive_url(), "https://github-cloud.s3.amazonaws.com/migration/25320/24575?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20180913%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180913T201100Z&X-Amz-Expires=300&X-Amz-Signature=a0aeb638facd0c78c1ed3ca86022eddbee91e5fe1bb48ee830f54b8b7b305026&X-Amz-SignedHeaders=host&actor_id=41840111&response-content-disposition=filename%3D608bceae-b790-11e8-8b43-4e3cb0dd56cc.tar.gz&response-content-type=application%2Fx-gzip") + self.assertEqual( + self.migration.get_archive_url(), + "https://github-cloud.s3.amazonaws.com/migration/25320/24575?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20180913%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180913T201100Z&X-Amz-Expires=300&X-Amz-Signature=a0aeb638facd0c78c1ed3ca86022eddbee91e5fe1bb48ee830f54b8b7b305026&X-Amz-SignedHeaders=host&actor_id=41840111&response-content-disposition=filename%3D608bceae-b790-11e8-8b43-4e3cb0dd56cc.tar.gz&response-content-type=application%2Fx-gzip", + ) def testDelete(self): self.assertEqual(self.migration.delete(), None) def testGetArchiveUrlWhenDeleted(self): - self.assertRaises(github.UnknownObjectException, lambda: self.migration.get_archive_url()) + self.assertRaises( + github.UnknownObjectException, lambda: self.migration.get_archive_url() + ) def testUnlockRepo(self): self.assertEqual(self.migration.unlock_repo("sample-repo"), None) diff --git a/tests/Milestone.py b/tests/Milestone.py index 5af992a8..163a8f9e 100644 --- a/tests/Milestone.py +++ b/tests/Milestone.py @@ -29,10 +29,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Milestone(Framework.TestCase): def setUp(self): @@ -41,7 +42,9 @@ 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.assertEqual( + self.milestone.created_at, datetime.datetime(2012, 3, 8, 12, 22, 10) + ) self.assertEqual(self.milestone.description, "") self.assertEqual(self.milestone.due_on, datetime.datetime(2012, 3, 13, 7, 0, 0)) self.assertEqual(self.milestone.id, 93546) @@ -49,25 +52,39 @@ class Milestone(Framework.TestCase): self.assertEqual(self.milestone.open_issues, 0) self.assertEqual(self.milestone.state, "closed") self.assertEqual(self.milestone.title, "Version 0.4") - self.assertEqual(self.milestone.url, "https://api.github.com/repos/jacquev6/PyGithub/milestones/1") + self.assertEqual( + self.milestone.url, + "https://api.github.com/repos/jacquev6/PyGithub/milestones/1", + ) self.assertEqual(self.milestone.creator.login, "jacquev6") # test __repr__() based on this attributes - self.assertEqual(self.milestone.__repr__(), 'Milestone(title="Version 0.4", number=1)') + self.assertEqual( + self.milestone.__repr__(), 'Milestone(title="Version 0.4", number=1)' + ) def testEditWithMinimalParameters(self): self.milestone.edit("Title edited by PyGithub") self.assertEqual(self.milestone.title, "Title edited by PyGithub") def testEditWithAllParameters(self): - self.milestone.edit("Title edited twice by PyGithub", "closed", "Description edited by PyGithub", due_on=datetime.date(2012, 6, 16)) + self.milestone.edit( + "Title edited twice by PyGithub", + "closed", + "Description edited by PyGithub", + due_on=datetime.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)) def testGetLabels(self): - self.assertListKeyEqual(self.milestone.get_labels(), lambda l: l.name, ["Public interface", "Project management"]) + self.assertListKeyEqual( + self.milestone.get_labels(), + lambda l: l.name, + ["Public interface", "Project management"], + ) def testDelete(self): self.milestone.delete() diff --git a/tests/NamedUser.py b/tests/NamedUser.py index 6c53a3cf..f1e42898 100644 --- a/tests/NamedUser.py +++ b/tests/NamedUser.py @@ -32,10 +32,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class NamedUser(Framework.TestCase): def setUp(self): @@ -44,12 +45,17 @@ class NamedUser(Framework.TestCase): def testAttributesOfOtherUser(self): self.user = self.g.get_user("nvie") - self.assertEqual(self.user.avatar_url, "https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png") + self.assertEqual( + self.user.avatar_url, + "https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + ) self.assertEqual(self.user.bio, None) self.assertEqual(self.user.blog, "http://nvie.com") 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.assertEqual( + self.user.created_at, datetime.datetime(2009, 5, 12, 21, 19, 38) + ) self.assertEqual(self.user.disk_usage, None) self.assertEqual(self.user.email, "vincent@3rdcloud.com") self.assertEqual(self.user.followers, 296) @@ -76,7 +82,10 @@ class NamedUser(Framework.TestCase): self.assertEqual(self.user.__repr__(), 'NamedUser(login="nvie")') def testAttributesOfSelf(self): - self.assertEqual(self.user.avatar_url, "https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png") + self.assertEqual( + self.user.avatar_url, + "https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + ) self.assertEqual(self.user.bio, "") self.assertEqual(self.user.blog, "http://vincent-jacques.net") self.assertEqual(self.user.collaborators, 0) @@ -101,7 +110,9 @@ class NamedUser(Framework.TestCase): self.assertEqual(self.user.private_gists, 5) 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.assertEqual( + self.user.suspended_at, datetime.datetime(2013, 8, 10, 7, 11, 7) + ) self.assertEqual(self.user.total_private_repos, 5) self.assertEqual(self.user.type, "User") self.assertEqual(self.user.url, "https://api.github.com/users/jacquev6") @@ -111,21 +122,83 @@ class NamedUser(Framework.TestCase): self.assertEqual(self.user.__repr__(), 'NamedUser(login="jacquev6")') def testGetGists(self): - self.assertListKeyEqual(self.user.get_gists(), lambda g: g.description, ["Gist created by PyGithub", "FairThreadPoolPool.cpp", "How to error 500 Github API v3, as requested by Rick (GitHub Staff)", "Cadfael: order of episodes in French DVD edition"]) - self.assertListKeyEqual(self.user.get_gists(since=datetime.datetime(2012, 3, 1, 17, 0, 0)), lambda g: g.description, ["Gist created by PyGithub", "FairThreadPoolPool.cpp"]) + self.assertListKeyEqual( + self.user.get_gists(), + lambda g: g.description, + [ + "Gist created by PyGithub", + "FairThreadPoolPool.cpp", + "How to error 500 Github API v3, as requested by Rick (GitHub Staff)", + "Cadfael: order of episodes in French DVD edition", + ], + ) + self.assertListKeyEqual( + self.user.get_gists(since=datetime.datetime(2012, 3, 1, 17, 0, 0)), + lambda g: g.description, + ["Gist created by PyGithub", "FairThreadPoolPool.cpp"], + ) def testGetFollowers(self): - self.assertListKeyEqual(self.user.get_followers(), lambda f: f.login, ["jnorthrup", "brugidou", "regisb", "walidk", "afzalkhan", "sdanzan", "vineus", "gturri", "fjardon", "cjuniet", "jardon-u", "kamaradclimber", "L42y"]) + self.assertListKeyEqual( + self.user.get_followers(), + lambda f: f.login, + [ + "jnorthrup", + "brugidou", + "regisb", + "walidk", + "afzalkhan", + "sdanzan", + "vineus", + "gturri", + "fjardon", + "cjuniet", + "jardon-u", + "kamaradclimber", + "L42y", + ], + ) def testGetFollowing(self): - self.assertListKeyEqual(self.user.get_following(), lambda f: f.login, ["nvie", "schacon", "jamis", "chad", "unclebob", "dabrahams", "jnorthrup", "brugidou", "regisb", "walidk", "tanzilli", "fjardon", "r3c", "sdanzan", "vineus", "cjuniet", "gturri", "ant9000", "asquini", "claudyus", "jardon-u", "s-bernard", "kamaradclimber", "Lyloa"]) + self.assertListKeyEqual( + self.user.get_following(), + lambda f: f.login, + [ + "nvie", + "schacon", + "jamis", + "chad", + "unclebob", + "dabrahams", + "jnorthrup", + "brugidou", + "regisb", + "walidk", + "tanzilli", + "fjardon", + "r3c", + "sdanzan", + "vineus", + "cjuniet", + "gturri", + "ant9000", + "asquini", + "claudyus", + "jardon-u", + "s-bernard", + "kamaradclimber", + "Lyloa", + ], + ) def testHasInFollowing(self): nvie = self.g.get_user("nvie") self.assertTrue(self.user.has_in_following(nvie)) def testGetOrgs(self): - self.assertListKeyEqual(self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"]) + self.assertListKeyEqual( + self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"] + ) def testGetOrganizationMembership(self): o = self.user.get_orgs() @@ -136,40 +209,223 @@ class NamedUser(Framework.TestCase): def testGetOrganizationMembershipNotMember(self): from github import UnknownObjectException - self.assertRaises(UnknownObjectException, self.user.get_organization_membership, "BeaverSoftware") + + self.assertRaises( + UnknownObjectException, + self.user.get_organization_membership, + "BeaverSoftware", + ) def testGetRepo(self): - self.assertEqual(self.user.get_repo("PyGithub").description, "Python library implementing the full Github API v3") + self.assertEqual( + self.user.get_repo("PyGithub").description, + "Python library implementing the full Github API v3", + ) def testGetRepos(self): - self.assertListKeyEqual(self.user.get_repos(), lambda r: r.name, ["TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + self.assertListKeyEqual( + self.user.get_repos(), + lambda r: r.name, + [ + "TestPyGithub", + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) def testGetReposWithType(self): - self.assertListKeyEqual(self.user.get_repos("owner"), lambda r: r.name, ["django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE"]) + self.assertListKeyEqual( + self.user.get_repos("owner"), + lambda r: r.name, + [ + "django", + "PyGithub", + "developer.github.com", + "acme-public-website", + "C4Planner", + "DrawTurksHead", + "DrawSyntax", + "QuadProgMm", + "Boost.HierarchicalEnum", + "ViDE", + ], + ) def testGetWatched(self): - self.assertListKeyEqual(self.user.get_watched(), lambda r: r.name, ["git", "boost.php", "capistrano", "boost.perl", "git-subtree", "git-hg", "homebrew", "celtic_knot", "twisted-intro", "markup", "hub", "gitflow", "murder", "boto", "agit", "d3", "pygit2", "git-pulls", "django_mathlatex", "scrumblr", "developer.github.com", "python-github3", "PlantUML", "bootstrap", "drawnby", "django-socketio", "django-realtime", "playground", "BozoCrack", "FatherBeaver", "PyGithub", "django", "django", "TestPyGithub"]) + self.assertListKeyEqual( + self.user.get_watched(), + lambda r: r.name, + [ + "git", + "boost.php", + "capistrano", + "boost.perl", + "git-subtree", + "git-hg", + "homebrew", + "celtic_knot", + "twisted-intro", + "markup", + "hub", + "gitflow", + "murder", + "boto", + "agit", + "d3", + "pygit2", + "git-pulls", + "django_mathlatex", + "scrumblr", + "developer.github.com", + "python-github3", + "PlantUML", + "bootstrap", + "drawnby", + "django-socketio", + "django-realtime", + "playground", + "BozoCrack", + "FatherBeaver", + "PyGithub", + "django", + "django", + "TestPyGithub", + ], + ) def testGetStarred(self): - self.assertListKeyEqual(self.user.get_starred(), lambda r: r.name, ["git", "boost.php", "capistrano", "boost.perl", "git-subtree", "git-hg", "homebrew", "celtic_knot", "twisted-intro", "markup", "hub", "gitflow", "murder", "boto", "agit", "d3", "pygit2", "git-pulls", "django_mathlatex", "scrumblr", "developer.github.com", "python-github3", "PlantUML", "bootstrap", "drawnby", "django-socketio", "django-realtime", "playground", "BozoCrack", "FatherBeaver", "amaunet", "django", "django", "moviePlanning", "folly"]) + self.assertListKeyEqual( + self.user.get_starred(), + lambda r: r.name, + [ + "git", + "boost.php", + "capistrano", + "boost.perl", + "git-subtree", + "git-hg", + "homebrew", + "celtic_knot", + "twisted-intro", + "markup", + "hub", + "gitflow", + "murder", + "boto", + "agit", + "d3", + "pygit2", + "git-pulls", + "django_mathlatex", + "scrumblr", + "developer.github.com", + "python-github3", + "PlantUML", + "bootstrap", + "drawnby", + "django-socketio", + "django-realtime", + "playground", + "BozoCrack", + "FatherBeaver", + "amaunet", + "django", + "django", + "moviePlanning", + "folly", + ], + ) def testGetSubscriptions(self): - self.assertListKeyEqual(self.user.get_subscriptions(), lambda r: r.name, ["ViDE", "Boost.HierarchicalEnum", "QuadProgMm", "DrawSyntax", "DrawTurksHead", "PrivateStuff", "vincent-jacques.net", "Hacking", "C4Planner", "developer.github.com", "PyGithub", "PyGithub", "django", "CinePlanning", "PyGithub", "PyGithub", "PyGithub", "IpMap", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub"]) + self.assertListKeyEqual( + self.user.get_subscriptions(), + lambda r: r.name, + [ + "ViDE", + "Boost.HierarchicalEnum", + "QuadProgMm", + "DrawSyntax", + "DrawTurksHead", + "PrivateStuff", + "vincent-jacques.net", + "Hacking", + "C4Planner", + "developer.github.com", + "PyGithub", + "PyGithub", + "django", + "CinePlanning", + "PyGithub", + "PyGithub", + "PyGithub", + "IpMap", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + "PyGithub", + ], + ) def testGetEvents(self): - self.assertListKeyBegin(self.user.get_events(), lambda e: e.type, ["GistEvent", "IssueCommentEvent", "PushEvent", "IssuesEvent"]) + self.assertListKeyBegin( + self.user.get_events(), + lambda e: e.type, + ["GistEvent", "IssueCommentEvent", "PushEvent", "IssuesEvent"], + ) def testGetPublicEvents(self): - self.assertListKeyBegin(self.user.get_public_events(), lambda e: e.type, ["PushEvent", "CreateEvent", "GistEvent", "IssuesEvent"]) + self.assertListKeyBegin( + self.user.get_public_events(), + lambda e: e.type, + ["PushEvent", "CreateEvent", "GistEvent", "IssuesEvent"], + ) def testGetPublicReceivedEvents(self): - self.assertListKeyBegin(self.user.get_public_received_events(), lambda e: e.type, ["IssueCommentEvent", "IssueCommentEvent", "IssueCommentEvent", "IssueCommentEvent"]) + self.assertListKeyBegin( + self.user.get_public_received_events(), + lambda e: e.type, + [ + "IssueCommentEvent", + "IssueCommentEvent", + "IssueCommentEvent", + "IssueCommentEvent", + ], + ) def testGetReceivedEvents(self): - self.assertListKeyBegin(self.user.get_received_events(), lambda e: e.type, ["IssueCommentEvent", "IssueCommentEvent", "IssueCommentEvent", "IssueCommentEvent"]) + self.assertListKeyBegin( + self.user.get_received_events(), + lambda e: e.type, + [ + "IssueCommentEvent", + "IssueCommentEvent", + "IssueCommentEvent", + "IssueCommentEvent", + ], + ) def testGetKeys(self): - self.assertListKeyEqual(self.user.get_keys(), lambda k: k.id, [3557894, 3791954, 3937333, 4051357, 4051492]) + self.assertListKeyEqual( + self.user.get_keys(), + lambda k: k.id, + [3557894, 3791954, 3937333, 4051357, 4051492], + ) def testUserEquality(self): u1 = self.g.get_user("nvie") diff --git a/tests/Notification.py b/tests/Notification.py index 103b7c75..5880dd96 100644 --- a/tests/Notification.py +++ b/tests/Notification.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/Organization.py b/tests/Organization.py index be8bf2ac..71626edb 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -35,12 +35,13 @@ ################################################################################ from __future__ import absolute_import + +import datetime + import github from . import Framework -import datetime - class Organization(Framework.TestCase): def setUp(self): @@ -48,15 +49,17 @@ class Organization(Framework.TestCase): self.org = self.g.get_organization("BeaverSoftware") def testAttributes(self): - self.assertEqual(self.org.avatar_url, "https://avatars1.githubusercontent.com/u/1?v=4") + self.assertEqual( + self.org.avatar_url, "https://avatars1.githubusercontent.com/u/1?v=4" + ) self.assertEqual(self.org.billing_email, "foo@example.com") 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.description, 'BeaverSoftware writes software.') + self.assertEqual(self.org.description, "BeaverSoftware writes software.") self.assertEqual(self.org.disk_usage, 2) - self.assertEqual(self.org.email, '') + self.assertEqual(self.org.email, "") self.assertEqual(self.org.followers, 0) self.assertEqual(self.org.following, 0) self.assertEqual(self.org.gravatar_id, None) @@ -83,7 +86,7 @@ class Organization(Framework.TestCase): def testAddMembersDefaultRole(self): lyloa = self.g.get_user("lyloa") self.assertFalse(self.org.has_in_members(lyloa)) - self.org.add_to_members(lyloa, role='member') + self.org.add_to_members(lyloa, role="member") # 'Pending' members won't be in /orgs/:org/members/:user self.assertFalse(self.org.has_in_members(lyloa)) self.org.remove_from_membership(lyloa) @@ -92,7 +95,7 @@ class Organization(Framework.TestCase): def testAddMembersAdminRole(self): lyloa = self.g.get_user("lyloa") self.assertFalse(self.org.has_in_members(lyloa)) - self.org.add_to_members(lyloa, role='admin') + self.org.add_to_members(lyloa, role="admin") # 'Pending' members won't be in /orgs/:org/members/:user self.assertFalse(self.org.has_in_members(lyloa)) self.org.remove_from_membership(lyloa) @@ -102,7 +105,15 @@ class Organization(Framework.TestCase): self.org.edit() def testEditWithAllArguments(self): - self.org.edit("BeaverSoftware2@vincent-jacques.net", "http://vincent-jacques.net", "Company edited by PyGithub", "Description edited by PyGithub", "BeaverSoftware2@vincent-jacques.net", "Location edited by PyGithub", "Name edited by PyGithub") + self.org.edit( + "BeaverSoftware2@vincent-jacques.net", + "http://vincent-jacques.net", + "Company edited by PyGithub", + "Description edited by PyGithub", + "BeaverSoftware2@vincent-jacques.net", + "Location edited by PyGithub", + "Name edited by PyGithub", + ) self.assertEqual(self.org.billing_email, "BeaverSoftware2@vincent-jacques.net") self.assertEqual(self.org.blog, "http://vincent-jacques.net") self.assertEqual(self.org.company, "Company edited by PyGithub") @@ -117,8 +128,12 @@ class Organization(Framework.TestCase): self.assertEqual(hook.name, "mobile") def testEditHookWithAllParameters(self): - hook = self.org.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False) - hook = self.org.edit_hook(hook.id, "mobile", {"url": "http://barfoo.com"}, ["spoon"], True) + hook = self.org.create_hook( + "web", {"url": "http://foobar.com"}, ["fork"], False + ) + hook = self.org.edit_hook( + hook.id, "mobile", {"url": "http://barfoo.com"}, ["spoon"], True + ) self.assertEqual(hook.name, "mobile") self.assertEqual(hook.events, ["spoon"]) self.assertEqual(hook.active, True) @@ -129,7 +144,13 @@ class Organization(Framework.TestCase): def testCreateTeamWithAllArguments(self): repo = self.org.get_repo("FatherBeaver") - team = self.org.create_team("Team also created by PyGithub", [repo], "push", "secret", "Description also created by PyGithub") + team = self.org.create_team( + "Team also created by PyGithub", + [repo], + "push", + "secret", + "Description also created by PyGithub", + ) self.assertEqual(team.id, 189852) self.assertEqual(team.description, "Description also created by PyGithub") @@ -146,7 +167,9 @@ class Organization(Framework.TestCase): self.assertFalse(self.org.has_in_public_members(lyloa)) def testGetPublicMembers(self): - self.assertListKeyEqual(self.org.get_public_members(), lambda u: u.login, ["jacquev6"]) + self.assertListKeyEqual( + self.org.get_public_members(), lambda u: u.login, ["jacquev6"] + ) def testGetHooks(self): self.assertListKeyEqual(self.org.get_hooks(), lambda h: h.id, [257993]) @@ -155,20 +178,35 @@ class Organization(Framework.TestCase): self.assertListKeyEqual(self.org.get_issues(), lambda i: i.id, []) def testGetIssuesWithAllArguments(self): - requestedByUser = self.g.get_user().get_repo("PyGithub").get_label("Requested by user") - issues = self.org.get_issues("assigned", "closed", [requestedByUser], "comments", "asc", datetime.datetime(2012, 5, 28, 23, 0, 0)) + requestedByUser = ( + self.g.get_user().get_repo("PyGithub").get_label("Requested by user") + ) + issues = self.org.get_issues( + "assigned", + "closed", + [requestedByUser], + "comments", + "asc", + datetime.datetime(2012, 5, 28, 23, 0, 0), + ) self.assertListKeyEqual(issues, lambda i: i.id, []) def testGetMembers(self): - self.assertListKeyEqual(self.org.get_members(), lambda u: u.login, ["cjuniet", "jacquev6", "Lyloa"]) + self.assertListKeyEqual( + self.org.get_members(), lambda u: u.login, ["cjuniet", "jacquev6", "Lyloa"] + ) def testGetOutsideCollaborators(self): - self.assertListKeyEqual(self.org.get_outside_collaborators(), lambda u: u.login, ["octocat"]) + self.assertListKeyEqual( + self.org.get_outside_collaborators(), lambda u: u.login, ["octocat"] + ) def testOutsideCollaborators(self): octocat = self.g.get_user("octocat") self.org.convert_to_outside_collaborator(octocat) - self.assertListKeyEqual(self.org.get_outside_collaborators(), lambda u: u.login, ["octocat"]) + self.assertListKeyEqual( + self.org.get_outside_collaborators(), lambda u: u.login, ["octocat"] + ) self.org.remove_outside_collaborator(octocat) self.assertEqual(list(self.org.get_outside_collaborators()), []) @@ -179,19 +217,60 @@ class Organization(Framework.TestCase): self.assertFalse(self.org.has_in_members(lyloa)) def testGetRepos(self): - self.assertListKeyEqual(self.org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"]) + self.assertListKeyEqual( + self.org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"] + ) def testGetReposSorted(self): - self.assertListKeyEqual(self.org.get_repos(sort="updated", direction="desc"), lambda r: r.name, ["TestPyGithub", "FatherBeaver"]) + self.assertListKeyEqual( + self.org.get_repos(sort="updated", direction="desc"), + lambda r: r.name, + ["TestPyGithub", "FatherBeaver"], + ) def testGetReposWithType(self): - self.assertListKeyEqual(self.org.get_repos("public"), lambda r: r.name, ["FatherBeaver", "PyGithub"]) + self.assertListKeyEqual( + self.org.get_repos("public"), lambda r: r.name, ["FatherBeaver", "PyGithub"] + ) def testGetEvents(self): - self.assertListKeyEqual(self.org.get_events(), lambda e: e.type, ["CreateEvent", "CreateEvent", "PushEvent", "PushEvent", "DeleteEvent", "DeleteEvent", "PushEvent", "PushEvent", "DeleteEvent", "DeleteEvent", "PushEvent", "PushEvent", "PushEvent", "CreateEvent", "CreateEvent", "CreateEvent", "CreateEvent", "CreateEvent", "PushEvent", "PushEvent", "PushEvent", "PushEvent", "PushEvent", "PushEvent", "ForkEvent", "CreateEvent"]) + self.assertListKeyEqual( + self.org.get_events(), + lambda e: e.type, + [ + "CreateEvent", + "CreateEvent", + "PushEvent", + "PushEvent", + "DeleteEvent", + "DeleteEvent", + "PushEvent", + "PushEvent", + "DeleteEvent", + "DeleteEvent", + "PushEvent", + "PushEvent", + "PushEvent", + "CreateEvent", + "CreateEvent", + "CreateEvent", + "CreateEvent", + "CreateEvent", + "PushEvent", + "PushEvent", + "PushEvent", + "PushEvent", + "PushEvent", + "PushEvent", + "ForkEvent", + "CreateEvent", + ], + ) def testGetTeams(self): - self.assertListKeyEqual(self.org.get_teams(), lambda t: t.name, ["Members", "Owners"]) + self.assertListKeyEqual( + self.org.get_teams(), lambda t: t.name, ["Members", "Owners"] + ) def testGetTeamBySlug(self): team = self.org.get_team_by_slug("Members") @@ -202,29 +281,52 @@ class Organization(Framework.TestCase): self.assertEqual(hook.id, 257967) def testCreateHookWithAllParameters(self): - hook = self.org.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False) + hook = self.org.create_hook( + "web", {"url": "http://foobar.com"}, ["fork"], False + ) self.assertTrue(hook.active) self.assertEqual(hook.id, 257993) def testCreateRepoWithMinimalArguments(self): repo = self.org.create_repo(name="TestPyGithub") - self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub") + self.assertEqual( + repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub" + ) def testCreateRepoWithAllArguments(self): team = self.org.get_team(141496) - repo = self.org.create_repo(name="TestPyGithub2", description="Repo created by PyGithub", homepage="http://foobar.com", - private=False, has_issues=False, has_projects=False, has_wiki=False, has_downloads=False, - team_id=team.id, allow_squash_merge=False, allow_merge_commit=False, allow_rebase_merge=True) - self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub2") + repo = self.org.create_repo( + name="TestPyGithub2", + description="Repo created by PyGithub", + homepage="http://foobar.com", + private=False, + has_issues=False, + has_projects=False, + has_wiki=False, + has_downloads=False, + team_id=team.id, + allow_squash_merge=False, + allow_merge_commit=False, + allow_rebase_merge=True, + ) + self.assertEqual( + repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub2" + ) def testCreateRepositoryWithAutoInit(self): - repo = self.org.create_repo(name="TestPyGithub", auto_init=True, gitignore_template="Python") - self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub") + repo = self.org.create_repo( + name="TestPyGithub", auto_init=True, gitignore_template="Python" + ) + self.assertEqual( + repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub" + ) def testCreateFork(self): pygithub = self.g.get_user("jacquev6").get_repo("PyGithub") repo = self.org.create_fork(pygithub) - self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/PyGithub") + self.assertEqual( + repo.url, "https://api.github.com/repos/BeaverSoftware/PyGithub" + ) def testInviteUserWithNeither(self): with self.assertRaises(AssertionError) as raisedexp: @@ -232,34 +334,43 @@ class Organization(Framework.TestCase): self.assertEqual("specify only one of email or user", str(raisedexp.exception)) def testInviteUserWithBoth(self): - jacquev6 = self.g.get_user('jacquev6') + jacquev6 = self.g.get_user("jacquev6") with self.assertRaises(AssertionError) as raisedexp: - self.org.invite_user(email='foo', user=jacquev6) + self.org.invite_user(email="foo", user=jacquev6) self.assertEqual("specify only one of email or user", str(raisedexp.exception)) def testInviteUserByName(self): - jacquev6 = self.g.get_user('jacquev6') + jacquev6 = self.g.get_user("jacquev6") self.org.invite_user(user=jacquev6) def testInviteUserByEmail(self): - self.org.invite_user(email='foo@example.com') + self.org.invite_user(email="foo@example.com") def testInviteUserWithRoleAndTeam(self): team = self.org.create_team("Team created by PyGithub") - self.org.invite_user(email='foo@example.com', role='billing_manager', teams=[team]) + self.org.invite_user( + email="foo@example.com", role="billing_manager", teams=[team] + ) def testInviteUserAsNonOwner(self): with self.assertRaises(github.GithubException) as raisedexp: - self.org.invite_user(email='bar@example.com') + self.org.invite_user(email="bar@example.com") self.assertEqual(raisedexp.exception.status, 403) - self.assertEqual(raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/orgs/members/#create-organization-invitation', - u'message': u'You must be an admin to create an invitation to an organization.' - }) + self.assertEqual( + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/orgs/members/#create-organization-invitation", + u"message": u"You must be an admin to create an invitation to an organization.", + }, + ) def testCreateMigration(self): self.org = self.g.get_organization("sample-test-organisation") - self.assertTrue(isinstance(self.org.create_migration(["sample-repo"]), github.Migration.Migration)) + self.assertTrue( + isinstance( + self.org.create_migration(["sample-repo"]), github.Migration.Migration + ) + ) def testGetMigrations(self): self.org = self.g.get_organization("sample-test-organisation") diff --git a/tests/OrganizationHasInMembers.py b/tests/OrganizationHasInMembers.py index 270d36c8..6b52ad46 100644 --- a/tests/OrganizationHasInMembers.py +++ b/tests/OrganizationHasInMembers.py @@ -24,6 +24,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/PaginatedList.py b/tests/PaginatedList.py index 4c66f559..45dd9764 100644 --- a/tests/PaginatedList.py +++ b/tests/PaginatedList.py @@ -30,9 +30,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + from github.PaginatedList import PaginatedList as PaginatedListImpl +from . import Framework + class PaginatedList(Framework.TestCase): def setUp(self): @@ -87,10 +89,70 @@ class PaginatedList(Framework.TestCase): self.assertEqual(self.list[74].id, 3605277) def testGetFirstPage(self): - self.assertListKeyEqual(self.list.get_page(0), lambda i: i.id, [4772349, 4767675, 4758608, 4700182, 4662873, 4608132, 4604661, 4588997, 4557803, 4554058, 4539985, 4507572, 4507492, 4507416, 4447561, 4406584, 4384548, 4383465, 4373361, 4373201, 4370619, 4356530, 4352401, 4317009, 4286936]) + self.assertListKeyEqual( + self.list.get_page(0), + lambda i: i.id, + [ + 4772349, + 4767675, + 4758608, + 4700182, + 4662873, + 4608132, + 4604661, + 4588997, + 4557803, + 4554058, + 4539985, + 4507572, + 4507492, + 4507416, + 4447561, + 4406584, + 4384548, + 4383465, + 4373361, + 4373201, + 4370619, + 4356530, + 4352401, + 4317009, + 4286936, + ], + ) def testGetThirdPage(self): - self.assertListKeyEqual(self.list.get_page(2), lambda i: i.id, [3911629, 3911537, 3910580, 3910555, 3910549, 3897090, 3883598, 3856005, 3850655, 3825582, 3813852, 3812318, 3812275, 3807459, 3799872, 3799653, 3795495, 3754055, 3710293, 3662214, 3647640, 3631618, 3627067, 3614231, 3605277]) + self.assertListKeyEqual( + self.list.get_page(2), + lambda i: i.id, + [ + 3911629, + 3911537, + 3910580, + 3910555, + 3910549, + 3897090, + 3883598, + 3856005, + 3850655, + 3825582, + 3813852, + 3812318, + 3812275, + 3807459, + 3799872, + 3799653, + 3795495, + 3754055, + 3710293, + 3662214, + 3647640, + 3631618, + 3627067, + 3614231, + 3605277, + ], + ) def testIntIndexingAfterIteration(self): self.assertEqual(len(list(self.list)), 333) @@ -99,19 +161,100 @@ class PaginatedList(Framework.TestCase): self.assertEqual(self.list[332].id, 94898) def testSliceIndexingInFirstPage(self): - self.assertListKeyEqual(self.list[:13], lambda i: i.id, [4772349, 4767675, 4758608, 4700182, 4662873, 4608132, 4604661, 4588997, 4557803, 4554058, 4539985, 4507572, 4507492]) - self.assertListKeyEqual(self.list[:13:3], lambda i: i.id, [4772349, 4700182, 4604661, 4554058, 4507492]) - self.assertListKeyEqual(self.list[10:13], lambda i: i.id, [4539985, 4507572, 4507492]) - self.assertListKeyEqual(self.list[5:13:3], lambda i: i.id, [4608132, 4557803, 4507572]) + self.assertListKeyEqual( + self.list[:13], + lambda i: i.id, + [ + 4772349, + 4767675, + 4758608, + 4700182, + 4662873, + 4608132, + 4604661, + 4588997, + 4557803, + 4554058, + 4539985, + 4507572, + 4507492, + ], + ) + self.assertListKeyEqual( + self.list[:13:3], + lambda i: i.id, + [4772349, 4700182, 4604661, 4554058, 4507492], + ) + self.assertListKeyEqual( + self.list[10:13], lambda i: i.id, [4539985, 4507572, 4507492] + ) + self.assertListKeyEqual( + self.list[5:13:3], lambda i: i.id, [4608132, 4557803, 4507572] + ) def testSliceIndexingUntilFourthPage(self): - self.assertListKeyEqual(self.list[:99:10], lambda i: i.id, [4772349, 4539985, 4370619, 4207350, 4063366, 3911629, 3813852, 3647640, 3528378, 3438233]) - self.assertListKeyEqual(self.list[73:78], lambda i: i.id, [3614231, 3605277, 3596240, 3594731, 3593619]) - self.assertListKeyEqual(self.list[70:80:2], lambda i: i.id, [3647640, 3627067, 3605277, 3594731, 3593430]) + self.assertListKeyEqual( + self.list[:99:10], + lambda i: i.id, + [ + 4772349, + 4539985, + 4370619, + 4207350, + 4063366, + 3911629, + 3813852, + 3647640, + 3528378, + 3438233, + ], + ) + self.assertListKeyEqual( + self.list[73:78], + lambda i: i.id, + [3614231, 3605277, 3596240, 3594731, 3593619], + ) + self.assertListKeyEqual( + self.list[70:80:2], + lambda i: i.id, + [3647640, 3627067, 3605277, 3594731, 3593430], + ) def testSliceIndexingUntilEnd(self): - self.assertListKeyEqual(self.list[310::3], lambda i: i.id, [268332, 204247, 169176, 166211, 165898, 163959, 132373, 104702]) - self.assertListKeyEqual(self.list[310:], lambda i: i.id, [268332, 211418, 205935, 204247, 172424, 171615, 169176, 166214, 166212, 166211, 166209, 166208, 165898, 165537, 165409, 163959, 132671, 132377, 132373, 130269, 111018, 104702, 94898]) + self.assertListKeyEqual( + self.list[310::3], + lambda i: i.id, + [268332, 204247, 169176, 166211, 165898, 163959, 132373, 104702], + ) + self.assertListKeyEqual( + self.list[310:], + lambda i: i.id, + [ + 268332, + 211418, + 205935, + 204247, + 172424, + 171615, + 169176, + 166214, + 166212, + 166211, + 166209, + 166208, + 165898, + 165537, + 165409, + 163959, + 132671, + 132377, + 132373, + 130269, + 111018, + 104702, + 94898, + ], + ) def testInterruptedIteration(self): # No asserts, but checks that only three pages are fetched @@ -136,13 +279,16 @@ class PaginatedList(Framework.TestCase): self.assertEqual(len(list(self.repo.get_issues())), 456) def testCustomPerPageWithNoUrlParams(self): - from . import CommitComment # Don't polute github.tests namespace, it would conflict with github.tests.CommitComment + from . import ( + CommitComment, + ) # Don't polute github.tests namespace, it would conflict with github.tests.CommitComment + self.g.per_page = 100 PaginatedListImpl( CommitComment.CommitComment, self.repo._requester, self.repo.url + "/comments", - None + None, ) def testCustomPerPageWithNoUrlParams2(self): diff --git a/tests/Persistence.py b/tests/Persistence.py index 4a9d8bfc..716d4671 100644 --- a/tests/Persistence.py +++ b/tests/Persistence.py @@ -27,11 +27,13 @@ ################################################################################ from __future__ import absolute_import -from . import Framework -import github from io import BytesIO as IO +import github + +from . import Framework + class Persistence(Framework.TestCase): def setUp(self): diff --git a/tests/Project.py b/tests/Project.py index a7c5e629..52d121c4 100644 --- a/tests/Project.py +++ b/tests/Project.py @@ -23,31 +23,33 @@ # ############################################################################## from __future__ import absolute_import -from . import Framework + import github +from . import Framework + class Project(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.repo = self.g.get_user().get_repo('PyGithub') + self.repo = self.g.get_user().get_repo("PyGithub") def testGetProject(self): pid = 1682941 proj = self.g.get_project(pid) self.assertEqual(proj.id, pid) - self.assertEqual(proj.name, 'TestProject') + self.assertEqual(proj.name, "TestProject") def testGetOrganizationProjects(self): - expectedProjects = ['Project1', 'Project2', 'Project3'] - org = self.g.get_organization('PyGithubTestOrg') + expectedProjects = ["Project1", "Project2", "Project3"] + org = self.g.get_organization("PyGithubTestOrg") projects = [] for proj in org.get_projects("open"): projects.append(proj.name) self.assertEqual(projects, expectedProjects) def testGetRepositoryProjects(self): - expectedProjects = ['TestProject', 'TestProjectClosed'] + expectedProjects = ["TestProject", "TestProjectClosed"] projects = [] for proj in self.repo.get_projects("all"): projects.append(proj.name) @@ -57,14 +59,22 @@ class Project(Framework.TestCase): def testProjectAttributes(self): pid = 1682941 proj = self.g.get_project(pid) - self.assertEqual(proj.owner_url, "https://api.github.com/repos/bbi-yggy/PyGithub") + self.assertEqual( + proj.owner_url, "https://api.github.com/repos/bbi-yggy/PyGithub" + ) self.assertEqual(proj.url, "https://api.github.com/projects/1682941") - self.assertEqual(proj.html_url, "https://github.com/bbi-yggy/PyGithub/projects/1") - self.assertEqual(proj.columns_url, "https://api.github.com/projects/1682941/columns") + self.assertEqual( + proj.html_url, "https://github.com/bbi-yggy/PyGithub/projects/1" + ) + self.assertEqual( + proj.columns_url, "https://api.github.com/projects/1682941/columns" + ) self.assertEqual(proj.id, pid) self.assertEqual(proj.node_id, "MDc6UHJvamVjdDE2ODI5NDE=") - self.assertEqual(proj.name, 'TestProject') - self.assertEqual(proj.body, "To be used for testing project access API for PyGithub.") + self.assertEqual(proj.name, "TestProject") + self.assertEqual( + proj.body, "To be used for testing project access API for PyGithub." + ) self.assertEqual(proj.number, 1) self.assertEqual(proj.state, "open") self.assertEqual(proj.creator, self.repo.owner) @@ -80,7 +90,9 @@ class Project(Framework.TestCase): self.assertEqual(col.name, "To Do") self.assertEqual(col.url, "https://api.github.com/projects/columns/3138830") self.assertEqual(col.project_url, "https://api.github.com/projects/1682941") - self.assertEqual(col.cards_url, "https://api.github.com/projects/columns/3138830/cards") + self.assertEqual( + col.cards_url, "https://api.github.com/projects/columns/3138830/cards" + ) self.assertEqual(col.created_at.year, 2018) self.assertTrue(col.updated_at >= col.created_at) @@ -89,12 +101,18 @@ class Project(Framework.TestCase): proj = self.g.get_project(1682941) col = proj.get_columns()[1] card = col.get_cards()[0] - self.assertEqual(card.url, "https://api.github.com/projects/columns/cards/11780055") - self.assertEqual(card.column_url, "https://api.github.com/projects/columns/3138831") - self.assertEqual(card.content_url, "https://api.github.com/repos/bbi-yggy/PyGithub/issues/1") + self.assertEqual( + card.url, "https://api.github.com/projects/columns/cards/11780055" + ) + self.assertEqual( + card.column_url, "https://api.github.com/projects/columns/3138831" + ) + self.assertEqual( + card.content_url, "https://api.github.com/repos/bbi-yggy/PyGithub/issues/1" + ) self.assertEqual(card.id, 11780055) self.assertEqual(card.node_id, "MDExOlByb2plY3RDYXJkMTE3ODAwNTU=") - self.assertEqual(card.note, None) # No notes for cards with content. + self.assertEqual(card.note, None) # No notes for cards with content. self.assertEqual(card.creator, self.repo.owner) self.assertEqual(card.created_at.year, 2018) self.assertTrue(card.updated_at >= card.created_at) @@ -108,7 +126,9 @@ class Project(Framework.TestCase): pull_card = cards[0] pull = pull_card.get_content("PullRequest") self.assertIsInstance(pull, github.PullRequest.PullRequest) - self.assertEqual(pull.title, "Work in progress on support for GitHub projects API.") + self.assertEqual( + pull.title, "Work in progress on support for GitHub projects API." + ) issue_card = cards[1] issue = issue_card.get_content() @@ -120,7 +140,7 @@ class Project(Framework.TestCase): self.assertEqual(note_content, None) def testGetAllProjectCards(self): - expectedProjects = ['TestProject'] + expectedProjects = ["TestProject"] expectedCards = 5 projects = [] cards = 0 @@ -133,22 +153,25 @@ class Project(Framework.TestCase): self.assertEqual(cards, expectedCards) def testCreateColumn(self): - project = self.repo.create_project("Project created by PyGithub", "Project Body") + project = self.repo.create_project( + "Project created by PyGithub", "Project Body" + ) column = project.create_column("Project Column created by PyGithub",) self.assertEqual(column.id, 3999333) def testCreateCardWithNote(self): - project = self.repo.create_project("Project created by PyGithub", - "Project Body") + project = self.repo.create_project( + "Project created by PyGithub", "Project Body" + ) column = project.create_column("Project Column created by PyGithub",) card1 = column.create_card(note="Project Card") self.assertEqual(card1.id, 16039019) def testCreateCardFromIssue(self): - project = self.repo.create_project("Project created by PyGithub", - "Project Body") + project = self.repo.create_project( + "Project created by PyGithub", "Project Body" + ) column = project.create_column("Project Column created by PyGithub",) issue = self.repo.create_issue(title="Issue created by PyGithub") - card2 = column.create_card(content_id=issue.id, - content_type="Issue") + card2 = column.create_card(content_id=issue.id, content_type="Issue") self.assertEqual(card2.id, 16039106) diff --git a/tests/PullRequest.py b/tests/PullRequest.py index 48cecec5..2cd3f0e0 100644 --- a/tests/PullRequest.py +++ b/tests/PullRequest.py @@ -32,10 +32,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class PullRequest(Framework.TestCase): def setUp(self): @@ -50,15 +51,21 @@ class PullRequest(Framework.TestCase): self.pullIssue256Uncached = marco_repo.get_pull(4) def testAttributesIssue256(self): - self.assertEqual(self.pullIssue256Closed.closed_at, datetime.datetime(2018, 5, 22, 14, 50, 43)) - self.assertEqual(self.pullIssue256Merged.closed_at, datetime.datetime(2018, 5, 22, 14, 53, 13)) + self.assertEqual( + self.pullIssue256Closed.closed_at, + datetime.datetime(2018, 5, 22, 14, 50, 43), + ) + self.assertEqual( + self.pullIssue256Merged.closed_at, + datetime.datetime(2018, 5, 22, 14, 53, 13), + ) self.assertEqual(self.pullIssue256Conflict.closed_at, None) self.assertEqual(self.pullIssue256Uncached.closed_at, None) - self.assertEqual(self.pullIssue256Closed.state, 'closed') - self.assertEqual(self.pullIssue256Merged.state, 'closed') - self.assertEqual(self.pullIssue256Conflict.state, 'open') - self.assertEqual(self.pullIssue256Uncached.state, 'open') + self.assertEqual(self.pullIssue256Closed.state, "closed") + self.assertEqual(self.pullIssue256Merged.state, "closed") + self.assertEqual(self.pullIssue256Conflict.state, "open") + self.assertEqual(self.pullIssue256Uncached.state, "open") self.assertFalse(self.pullIssue256Closed.merged) self.assertTrue(self.pullIssue256Merged.merged) @@ -70,16 +77,20 @@ class PullRequest(Framework.TestCase): self.assertTrue(self.pullIssue256Conflict.mergeable) self.assertEqual(self.pullIssue256Uncached.mergeable, None) - self.assertEqual(self.pullIssue256Closed.mergeable_state, 'unknown') - self.assertEqual(self.pullIssue256Merged.mergeable_state, 'unknown') - self.assertEqual(self.pullIssue256Conflict.mergeable_state, 'clean') - self.assertEqual(self.pullIssue256Uncached.mergeable_state, 'unknown') + self.assertEqual(self.pullIssue256Closed.mergeable_state, "unknown") + self.assertEqual(self.pullIssue256Merged.mergeable_state, "unknown") + self.assertEqual(self.pullIssue256Conflict.mergeable_state, "clean") + self.assertEqual(self.pullIssue256Uncached.mergeable_state, "unknown") def testAttributes(self): self.assertEqual(self.pull.additions, 511) self.assertEqual(self.pull.assignee.login, "jacquev6") - self.assertListKeyEqual(self.pull.assignees, lambda a: a.login, ["stuglaser", "jacquev6"]) - self.assertEqual(self.pull.base.label, "jacquev6:topic/RewriteWithGeneratedCode") + self.assertListKeyEqual( + self.pull.assignees, lambda a: a.login, ["stuglaser", "jacquev6"] + ) + self.assertEqual( + self.pull.base.label, "jacquev6:topic/RewriteWithGeneratedCode" + ) self.assertEqual(self.pull.base.sha, "ed866fc43833802ab553e5ff8581c81bb00dd433") self.assertEqual(self.pull.base.user.login, "jacquev6") self.assertEqual(self.pull.base.ref, "topic/RewriteWithGeneratedCode") @@ -89,33 +100,53 @@ class PullRequest(Framework.TestCase): self.assertEqual(self.pull.closed_at, datetime.datetime(2012, 5, 27, 10, 29, 7)) 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.assertEqual( + self.pull.created_at, datetime.datetime(2012, 5, 27, 9, 25, 36) + ) self.assertEqual(self.pull.deletions, 384) - self.assertEqual(self.pull.diff_url, "https://github.com/jacquev6/PyGithub/pull/31.diff") + self.assertEqual( + self.pull.diff_url, "https://github.com/jacquev6/PyGithub/pull/31.diff" + ) self.assertEqual(self.pull.head.label, "BeaverSoftware:master") - self.assertEqual(self.pull.html_url, "https://github.com/jacquev6/PyGithub/pull/31") + self.assertEqual( + self.pull.html_url, "https://github.com/jacquev6/PyGithub/pull/31" + ) self.assertEqual(self.pull.id, 1436215) - self.assertEqual(self.pull.issue_url, "https://api.github.com/repos/jacquev6/PyGithub/issues/31") + self.assertEqual( + self.pull.issue_url, + "https://api.github.com/repos/jacquev6/PyGithub/issues/31", + ) self.assertListKeyEqual(self.pull.labels, lambda a: a.name, ["refactoring"]) self.assertFalse(self.pull.mergeable) self.assertTrue(self.pull.merged) self.assertEqual(self.pull.merged_at, datetime.datetime(2012, 5, 27, 10, 29, 7)) self.assertEqual(self.pull.merged_by.login, "jacquev6") self.assertEqual(self.pull.number, 31) - self.assertEqual(self.pull.patch_url, "https://github.com/jacquev6/PyGithub/pull/31.patch") + self.assertEqual( + self.pull.patch_url, "https://github.com/jacquev6/PyGithub/pull/31.patch" + ) self.assertEqual(self.pull.review_comments, 1) self.assertEqual(self.pull.state, "closed") self.assertEqual(self.pull.title, "Title edited by PyGithub") - self.assertEqual(self.pull.updated_at, datetime.datetime(2012, 11, 3, 8, 19, 40)) - self.assertEqual(self.pull.url, "https://api.github.com/repos/jacquev6/PyGithub/pulls/31") + self.assertEqual( + self.pull.updated_at, datetime.datetime(2012, 11, 3, 8, 19, 40) + ) + self.assertEqual( + self.pull.url, "https://api.github.com/repos/jacquev6/PyGithub/pulls/31" + ) self.assertEqual(self.pull.user.login, "jacquev6") # test __repr__() based on this attributes - self.assertEqual(self.pull.__repr__(), 'PullRequest(title="Title edited by PyGithub", number=31)') + self.assertEqual( + self.pull.__repr__(), + 'PullRequest(title="Title edited by PyGithub", number=31)', + ) def testCreateComment(self): commit = self.repo.get_commit("8a4f306d4b223682dd19410d4a9150636ebe4206") - comment = self.pull.create_comment("Comment created by PyGithub", commit, "src/github/Issue.py", 5) + comment = self.pull.create_comment( + "Comment created by PyGithub", commit, "src/github/Issue.py", 5 + ) self.assertEqual(comment.id, 886298) def testGetComments(self): @@ -126,14 +157,20 @@ class PullRequest(Framework.TestCase): self.assertEqual(comment.id, 8387331) def testGetIssueComments(self): - self.assertListKeyEqual(self.pull.get_issue_comments(), lambda c: c.id, [8387331]) + self.assertListKeyEqual( + self.pull.get_issue_comments(), lambda c: c.id, [8387331] + ) def testGetIssueComment(self): comment = self.pull.get_issue_comment(8387331) self.assertEqual(comment.body, "Issue comment created by PyGithub") def testGetIssueEvents(self): - self.assertListKeyEqual(self.pull.get_issue_events(), lambda e: e.id, [16349963, 16350729, 16350730, 16350731, 28469043, 98136335]) + self.assertListKeyEqual( + self.pull.get_issue_events(), + lambda e: e.id, + [16349963, 16350729, 16350730, 16350731, 28469043, 98136335], + ) def testGetReviewComments(self): epoch = datetime.datetime(1970, 1, 1, 0, 0) @@ -141,14 +178,20 @@ class PullRequest(Framework.TestCase): self.assertListKeyEqual(comments, lambda c: c.id, [238127783]) def testReviewRequests(self): - self.pull.create_review_request(reviewers="sfdye", team_reviewers="pygithub-owners") + self.pull.create_review_request( + reviewers="sfdye", team_reviewers="pygithub-owners" + ) review_requests = self.pull.get_review_requests() self.assertListKeyEqual(review_requests[0], lambda c: c.login, ["sfdye"]) - self.assertListKeyEqual(review_requests[1], lambda c: c.slug, ["pygithub-owners"]) + self.assertListKeyEqual( + review_requests[1], lambda c: c.slug, ["pygithub-owners"] + ) self.pull.delete_review_request(reviewers="sfdye") review_requests = self.pull.get_review_requests() self.assertEqual(list(review_requests[0]), []) - self.assertListKeyEqual(review_requests[1], lambda c: c.slug, ["pygithub-owners"]) + self.assertListKeyEqual( + review_requests[1], lambda c: c.slug, ["pygithub-owners"] + ) def testEditWithoutArguments(self): self.pull.edit() @@ -160,53 +203,149 @@ class PullRequest(Framework.TestCase): self.assertEqual(self.pull.state, "open") def testGetCommits(self): - self.assertListKeyEqual(self.pull.get_commits(), lambda c: c.sha, ["4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23", "93dcae5cf207de376c91d0599226e7c7563e1d16", "8a4f306d4b223682dd19410d4a9150636ebe4206"]) + self.assertListKeyEqual( + self.pull.get_commits(), + lambda c: c.sha, + [ + "4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23", + "93dcae5cf207de376c91d0599226e7c7563e1d16", + "8a4f306d4b223682dd19410d4a9150636ebe4206", + ], + ) def testGetFiles(self): - self.assertListKeyEqual(self.pull.get_files(), lambda f: f.filename, ["codegen/templates/GithubObject.py", "src/github/AuthenticatedUser.py", "src/github/Authorization.py", "src/github/Branch.py", "src/github/Commit.py", "src/github/CommitComment.py", "src/github/CommitFile.py", "src/github/CommitStats.py", "src/github/Download.py", "src/github/Event.py", "src/github/Gist.py", "src/github/GistComment.py", "src/github/GistHistoryState.py", "src/github/GitAuthor.py", "src/github/GitBlob.py", "src/github/GitCommit.py", "src/github/GitObject.py", "src/github/GitRef.py", "src/github/GitTag.py", "src/github/GitTree.py", "src/github/GitTreeElement.py", "src/github/Hook.py", "src/github/Issue.py", "src/github/IssueComment.py", "src/github/IssueEvent.py", "src/github/Label.py", "src/github/Milestone.py", "src/github/NamedUser.py", "src/github/Organization.py", "src/github/Permissions.py", "src/github/Plan.py", "src/github/PullRequest.py", "src/github/PullRequestComment.py", "src/github/PullRequestFile.py", "src/github/Repository.py", "src/github/RepositoryKey.py", "src/github/Tag.py", "src/github/Team.py", "src/github/UserKey.py", "test/Issue.py", "test/IssueEvent.py", "test/ReplayData/Issue.testAddAndRemoveLabels.txt", "test/ReplayData/Issue.testDeleteAndSetLabels.txt", "test/ReplayData/Issue.testGetLabels.txt", "test/ReplayData/IssueEvent.setUp.txt"]) + self.assertListKeyEqual( + self.pull.get_files(), + lambda f: f.filename, + [ + "codegen/templates/GithubObject.py", + "src/github/AuthenticatedUser.py", + "src/github/Authorization.py", + "src/github/Branch.py", + "src/github/Commit.py", + "src/github/CommitComment.py", + "src/github/CommitFile.py", + "src/github/CommitStats.py", + "src/github/Download.py", + "src/github/Event.py", + "src/github/Gist.py", + "src/github/GistComment.py", + "src/github/GistHistoryState.py", + "src/github/GitAuthor.py", + "src/github/GitBlob.py", + "src/github/GitCommit.py", + "src/github/GitObject.py", + "src/github/GitRef.py", + "src/github/GitTag.py", + "src/github/GitTree.py", + "src/github/GitTreeElement.py", + "src/github/Hook.py", + "src/github/Issue.py", + "src/github/IssueComment.py", + "src/github/IssueEvent.py", + "src/github/Label.py", + "src/github/Milestone.py", + "src/github/NamedUser.py", + "src/github/Organization.py", + "src/github/Permissions.py", + "src/github/Plan.py", + "src/github/PullRequest.py", + "src/github/PullRequestComment.py", + "src/github/PullRequestFile.py", + "src/github/Repository.py", + "src/github/RepositoryKey.py", + "src/github/Tag.py", + "src/github/Team.py", + "src/github/UserKey.py", + "test/Issue.py", + "test/IssueEvent.py", + "test/ReplayData/Issue.testAddAndRemoveLabels.txt", + "test/ReplayData/Issue.testDeleteAndSetLabels.txt", + "test/ReplayData/Issue.testGetLabels.txt", + "test/ReplayData/IssueEvent.setUp.txt", + ], + ) def testGetLabels(self): - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring"] + ) def testAddAndRemoveLabels(self): wip = self.repo.get_label("wip") refactoring = self.repo.get_label("refactoring") - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), + lambda l: l.name, + ["wip", "refactoring", "improvement"], + ) self.pull.remove_from_labels(wip) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["refactoring", "improvement"] + ) self.pull.remove_from_labels(refactoring) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["improvement"] + ) self.pull.add_to_labels(wip, refactoring) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), + lambda l: l.name, + ["wip", "refactoring", "improvement"], + ) def testAddAndRemoveLabelsWithStringArguments(self): wip = "wip" refactoring = "refactoring" - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), + lambda l: l.name, + ["wip", "refactoring", "improvement"], + ) self.pull.remove_from_labels(wip) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["refactoring", "improvement"] + ) self.pull.remove_from_labels(refactoring) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["improvement"] + ) self.pull.add_to_labels(wip, refactoring) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), + lambda l: l.name, + ["wip", "refactoring", "improvement"], + ) def testDeleteAndSetLabels(self): wip = self.repo.get_label("wip") refactoring = self.repo.get_label("refactoring") - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), + lambda l: l.name, + ["wip", "refactoring", "improvement"], + ) self.pull.delete_labels() self.assertListKeyEqual(self.pull.get_labels(), None, []) self.pull.set_labels(wip, refactoring) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring"] + ) def testDeleteAndSetLabelsWithStringArguments(self): wip = "wip" refactoring = "refactoring" - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring", "improvement"]) + self.assertListKeyEqual( + self.pull.get_labels(), + lambda l: l.name, + ["wip", "refactoring", "improvement"], + ) self.pull.delete_labels() self.assertListKeyEqual(self.pull.get_labels(), None, []) self.pull.set_labels(wip, refactoring) - self.assertListKeyEqual(self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring"]) + self.assertListKeyEqual( + self.pull.get_labels(), lambda l: l.name, ["wip", "refactoring"] + ) def testMerge(self): self.assertFalse(self.pull.is_merged()) @@ -217,14 +356,23 @@ class PullRequest(Framework.TestCase): self.assertTrue(self.pull.is_merged()) def testMergeWithCommitMessage(self): - self.g.get_user().get_repo("PyGithub").get_pull(39).merge("Custom commit message created by PyGithub") + self.g.get_user().get_repo("PyGithub").get_pull(39).merge( + "Custom commit message created by PyGithub" + ) def testAddAndRemoveAssignees(self): user1 = "jayfk" user2 = self.g.get_user("jzelinskie") - self.assertListKeyEqual(self.pull.assignees, lambda a: a.login, ["stuglaser", "jacquev6"]) + self.assertListKeyEqual( + self.pull.assignees, lambda a: a.login, ["stuglaser", "jacquev6"] + ) self.pull.add_to_assignees(user1, user2) - self.assertListKeyEqual(self.pull.assignees, lambda a: a.login, - ["jacquev6", "stuglaser", "jayfk", "jzelinskie"]) + self.assertListKeyEqual( + self.pull.assignees, + lambda a: a.login, + ["jacquev6", "stuglaser", "jayfk", "jzelinskie"], + ) self.pull.remove_from_assignees(user1, user2) - self.assertListKeyEqual(self.pull.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) + self.assertListKeyEqual( + self.pull.assignees, lambda a: a.login, ["jacquev6", "stuglaser"] + ) diff --git a/tests/PullRequest1168.py b/tests/PullRequest1168.py index 432edbbe..277895cd 100644 --- a/tests/PullRequest1168.py +++ b/tests/PullRequest1168.py @@ -23,13 +23,16 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class PullRequest1168(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.notifications = self.g.get_repo("PyGithub/PyGithub").get_notifications(all=True) + self.notifications = self.g.get_repo("PyGithub/PyGithub").get_notifications( + all=True + ) def testGetPullRequest(self): p = self.notifications[0].get_pull_request() diff --git a/tests/PullRequest1169.py b/tests/PullRequest1169.py index a2e22e28..112e646d 100644 --- a/tests/PullRequest1169.py +++ b/tests/PullRequest1169.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework diff --git a/tests/PullRequestComment.py b/tests/PullRequestComment.py index ea74ea94..a215aeee 100644 --- a/tests/PullRequestComment.py +++ b/tests/PullRequestComment.py @@ -30,32 +30,52 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class PullRequestComment(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.comment = self.g.get_user().get_repo("PyGithub").get_pull(31).get_comment(886298) + self.comment = ( + self.g.get_user().get_repo("PyGithub").get_pull(31).get_comment(886298) + ) def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") - self.assertEqual(self.comment.commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206") - self.assertEqual(self.comment.created_at, datetime.datetime(2012, 5, 27, 9, 40, 12)) + self.assertEqual( + self.comment.commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206" + ) + self.assertEqual( + self.comment.created_at, datetime.datetime(2012, 5, 27, 9, 40, 12) + ) self.assertEqual(self.comment.id, 886298) - self.assertEqual(self.comment.original_commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206") + self.assertEqual( + self.comment.original_commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206" + ) self.assertEqual(self.comment.original_position, 5) 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.assertEqual(self.comment.url, "https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298") + self.assertEqual( + self.comment.updated_at, datetime.datetime(2012, 5, 27, 9, 40, 12) + ) + self.assertEqual( + self.comment.url, + "https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298", + ) self.assertEqual(self.comment.user.login, "jacquev6") - self.assertEqual(self.comment.html_url, "https://github.com/jacquev6/PyGithub/pull/170#issuecomment-18637907") + self.assertEqual( + self.comment.html_url, + "https://github.com/jacquev6/PyGithub/pull/170#issuecomment-18637907", + ) # test __repr__() based on this attributes - self.assertEqual(self.comment.__repr__(), 'PullRequestComment(user=NamedUser(login="jacquev6"), id=886298)') + self.assertEqual( + self.comment.__repr__(), + 'PullRequestComment(user=NamedUser(login="jacquev6"), id=886298)', + ) def testEdit(self): self.comment.edit("Comment edited by PyGithub") diff --git a/tests/PullRequestFile.py b/tests/PullRequestFile.py index 92cc090e..64c092ae 100644 --- a/tests/PullRequestFile.py +++ b/tests/PullRequestFile.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -39,14 +40,26 @@ class PullRequestFile(Framework.TestCase): def testAttributes(self): self.assertEqual(self.file.additions, 1) - self.assertEqual(self.file.blob_url, "https://github.com/jacquev6/PyGithub/blob/8a4f306d4b223682dd19410d4a9150636ebe4206/codegen/templates/GithubObject.py") + self.assertEqual( + self.file.blob_url, + "https://github.com/jacquev6/PyGithub/blob/8a4f306d4b223682dd19410d4a9150636ebe4206/codegen/templates/GithubObject.py", + ) self.assertEqual(self.file.changes, 2) self.assertEqual(self.file.deletions, 1) self.assertEqual(self.file.filename, "codegen/templates/GithubObject.py") - self.assertEqual(self.file.patch, '@@ -70,7 +70,7 @@ def __useAttributes( self, attributes ):\n \n # @toto No need to check if attribute is in attributes when attribute is mandatory\n {% for attribute in class.attributes|dictsort:"name" %}\n- if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None:\n+ if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None: # pragma no branch\n \n {% if attribute.type.cardinality == "scalar" %}\n {% if attribute.type.simple %}') - self.assertEqual(self.file.raw_url, "https://github.com/jacquev6/PyGithub/raw/8a4f306d4b223682dd19410d4a9150636ebe4206/codegen/templates/GithubObject.py") + self.assertEqual( + self.file.patch, + '@@ -70,7 +70,7 @@ def __useAttributes( self, attributes ):\n \n # @toto No need to check if attribute is in attributes when attribute is mandatory\n {% for attribute in class.attributes|dictsort:"name" %}\n- if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None:\n+ if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None: # pragma no branch\n \n {% if attribute.type.cardinality == "scalar" %}\n {% if attribute.type.simple %}', + ) + self.assertEqual( + self.file.raw_url, + "https://github.com/jacquev6/PyGithub/raw/8a4f306d4b223682dd19410d4a9150636ebe4206/codegen/templates/GithubObject.py", + ) self.assertEqual(self.file.sha, "8a4f306d4b223682dd19410d4a9150636ebe4206") self.assertEqual(self.file.status, "modified") # test __repr__() based on this attributes - self.assertEqual(self.file.__repr__(), 'File(sha="8a4f306d4b223682dd19410d4a9150636ebe4206", filename="codegen/templates/GithubObject.py")') + self.assertEqual( + self.file.__repr__(), + 'File(sha="8a4f306d4b223682dd19410d4a9150636ebe4206", filename="codegen/templates/GithubObject.py")', + ) diff --git a/tests/PullRequestReview.py b/tests/PullRequestReview.py index 7e22138f..8a024c2e 100644 --- a/tests/PullRequestReview.py +++ b/tests/PullRequestReview.py @@ -27,10 +27,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class PullRequestReview(Framework.TestCase): def setUp(self): @@ -40,8 +41,8 @@ class PullRequestReview(Framework.TestCase): # Test ability to create a review self.created_pullreview = self.pull.create_review( - self.repo.get_commit('2f0e4e55fe87e38d26efc9aa1346f56abfbd6c52'), - 'Some review created by PyGithub' + self.repo.get_commit("2f0e4e55fe87e38d26efc9aa1346f56abfbd6c52"), + "Some review created by PyGithub", ) # Test ability to get all reviews @@ -62,12 +63,25 @@ class PullRequestReview(Framework.TestCase): self.assertEqual(self.pullreview.id, 28482091) self.assertEqual(self.pullreview.user.login, "jzelinskie") self.assertEqual(self.pullreview.body, "") - self.assertEqual(self.pullreview.commit_id, "7a0fcb27b7cd6c346fc3f76216ccb6e0f4ca3bcc") + self.assertEqual( + self.pullreview.commit_id, "7a0fcb27b7cd6c346fc3f76216ccb6e0f4ca3bcc" + ) self.assertEqual(self.pullreview.state, "APPROVED") - self.assertEqual(self.pullreview.html_url, "https://github.com/PyGithub/PyGithub/pull/538#pullrequestreview-28482091") - self.assertEqual(self.pullreview.pull_request_url, "https://api.github.com/repos/PyGithub/PyGithub/pulls/538") - self.assertEqual(self.pullreview.submitted_at, datetime.datetime(2017, 3, 22, 19, 6, 59)) + self.assertEqual( + self.pullreview.html_url, + "https://github.com/PyGithub/PyGithub/pull/538#pullrequestreview-28482091", + ) + self.assertEqual( + self.pullreview.pull_request_url, + "https://api.github.com/repos/PyGithub/PyGithub/pulls/538", + ) + self.assertEqual( + self.pullreview.submitted_at, datetime.datetime(2017, 3, 22, 19, 6, 59) + ) self.assertIn(self.created_pullreview, self.pullreviews) # test __repr__() based on this attributes - self.assertEqual(self.pullreview.__repr__(), 'PullRequestReview(user=NamedUser(login="jzelinskie"), id=28482091)') + self.assertEqual( + self.pullreview.__repr__(), + 'PullRequestReview(user=NamedUser(login="jzelinskie"), id=28482091)', + ) diff --git a/tests/RateLimiting.py b/tests/RateLimiting.py index 958c6aad..f2b1ebbc 100644 --- a/tests/RateLimiting.py +++ b/tests/RateLimiting.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + import datetime from . import Framework diff --git a/tests/RawData.py b/tests/RawData.py index 6e578d2b..690e1a22 100644 --- a/tests/RawData.py +++ b/tests/RawData.py @@ -26,60 +26,61 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import github.NamedUser +from . import Framework + class RawData(Framework.TestCase): jacquev6RawData = { - 'disk_usage': 13812, - 'private_gists': 5, - 'public_repos': 21, - 'subscriptions_url': 'https://api.github.com/users/jacquev6/subscriptions', - 'gravatar_id': 'b68de5ae38616c296fa345d2b9df2225', - 'hireable': False, - 'id': 327146, - 'followers_url': 'https://api.github.com/users/jacquev6/followers', - 'following_url': 'https://api.github.com/users/jacquev6/following', - 'collaborators': 1, - 'total_private_repos': 4, - 'blog': 'http://vincent-jacques.net', - 'followers': 22, - 'location': 'Paris, France', - 'type': 'User', - 'email': 'vincent@vincent-jacques.net', - 'bio': '', - 'gists_url': 'https://api.github.com/users/jacquev6/gists{/gist_id}', - 'owned_private_repos': 4, - 'company': 'Criteo', - 'events_url': 'https://api.github.com/users/jacquev6/events{/privacy}', - 'html_url': 'https://github.com/jacquev6', - 'updated_at': '2013-03-12T22:13:32Z', - 'plan': { - 'collaborators': 1, - 'name': 'micro', - 'private_repos': 5, - 'space': 614400, + "disk_usage": 13812, + "private_gists": 5, + "public_repos": 21, + "subscriptions_url": "https://api.github.com/users/jacquev6/subscriptions", + "gravatar_id": "b68de5ae38616c296fa345d2b9df2225", + "hireable": False, + "id": 327146, + "followers_url": "https://api.github.com/users/jacquev6/followers", + "following_url": "https://api.github.com/users/jacquev6/following", + "collaborators": 1, + "total_private_repos": 4, + "blog": "http://vincent-jacques.net", + "followers": 22, + "location": "Paris, France", + "type": "User", + "email": "vincent@vincent-jacques.net", + "bio": "", + "gists_url": "https://api.github.com/users/jacquev6/gists{/gist_id}", + "owned_private_repos": 4, + "company": "Criteo", + "events_url": "https://api.github.com/users/jacquev6/events{/privacy}", + "html_url": "https://github.com/jacquev6", + "updated_at": "2013-03-12T22:13:32Z", + "plan": { + "collaborators": 1, + "name": "micro", + "private_repos": 5, + "space": 614400, }, - 'received_events_url': 'https://api.github.com/users/jacquev6/received_events', - 'starred_url': 'https://api.github.com/users/jacquev6/starred{/owner}{/repo}', - 'public_gists': 2, - 'name': 'Vincent Jacques', - 'organizations_url': 'https://api.github.com/users/jacquev6/orgs', - 'url': 'https://api.github.com/users/jacquev6', - 'created_at': '2010-07-09T06:10:06Z', - 'avatar_url': 'https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png', - 'repos_url': 'https://api.github.com/users/jacquev6/repos', - 'following': 38, - 'login': 'jacquev6', + "received_events_url": "https://api.github.com/users/jacquev6/received_events", + "starred_url": "https://api.github.com/users/jacquev6/starred{/owner}{/repo}", + "public_gists": 2, + "name": "Vincent Jacques", + "organizations_url": "https://api.github.com/users/jacquev6/orgs", + "url": "https://api.github.com/users/jacquev6", + "created_at": "2010-07-09T06:10:06Z", + "avatar_url": "https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", + "repos_url": "https://api.github.com/users/jacquev6/repos", + "following": 38, + "login": "jacquev6", } planRawData = { - 'collaborators': 1, - 'name': 'micro', - 'private_repos': 5, - 'space': 614400, + "collaborators": 1, + "name": "micro", + "private_repos": 5, + "space": 614400, } def testCompletedObject(self): @@ -98,6 +99,8 @@ class RawData(Framework.TestCase): self.assertEqual(plan.raw_data, RawData.planRawData) def testCreateObjectFromRawData(self): - user = self.g.create_from_raw_data(github.NamedUser.NamedUser, RawData.jacquev6RawData) + user = self.g.create_from_raw_data( + github.NamedUser.NamedUser, RawData.jacquev6RawData + ) self.assertEqual(user._CompletableGithubObject__completed, True) self.assertEqual(user.name, "Vincent Jacques") diff --git a/tests/Reaction.py b/tests/Reaction.py index e7244e5a..9a0aa462 100644 --- a/tests/Reaction.py +++ b/tests/Reaction.py @@ -24,23 +24,34 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Reaction(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.reactions = self.g.get_user('PyGithub').get_repo("PyGithub").get_issue(28).get_reactions() + self.reactions = ( + self.g.get_user("PyGithub") + .get_repo("PyGithub") + .get_issue(28) + .get_reactions() + ) 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.assertEqual( + self.reactions[0].created_at, datetime.datetime(2017, 12, 5, 1, 59, 33) + ) self.assertEqual(self.reactions[0].id, 16916340) self.assertEqual(self.reactions[0].user.login, "nicolastrres") - self.assertEqual(self.reactions[0].__repr__(), 'Reaction(user=NamedUser(login="nicolastrres"), id=16916340)') + self.assertEqual( + self.reactions[0].__repr__(), + 'Reaction(user=NamedUser(login="nicolastrres"), id=16916340)', + ) def testDelete(self): self.reactions[0].delete() diff --git a/tests/Repository.py b/tests/Repository.py index a37d938c..aac6ce5d 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -48,10 +48,12 @@ ################################################################################ from __future__ import absolute_import -from . import Framework + +import datetime import github -import datetime + +from . import Framework class Repository(Framework.TestCase): @@ -61,9 +63,15 @@ class Repository(Framework.TestCase): self.repo = self.user.get_repo("PyGithub") def testAttributes(self): - self.assertEqual(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.assertEqual(self.repo.description, "Python library implementing the full Github API v3") + self.assertEqual( + 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.assertEqual( + self.repo.description, "Python library implementing the full Github API v3" + ) self.assertFalse(self.repo.fork) self.assertEqual(self.repo.forks, 3) self.assertEqual(self.repo.full_name, "jacquev6/PyGithub") @@ -91,21 +99,41 @@ class Repository(Framework.TestCase): 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.topics, None) - self.assertEqual(self.repo.updated_at, datetime.datetime(2012, 5, 27, 6, 55, 28)) - self.assertEqual(self.repo.url, "https://api.github.com/repos/jacquev6/PyGithub") + self.assertEqual( + self.repo.updated_at, datetime.datetime(2012, 5, 27, 6, 55, 28) + ) + self.assertEqual( + self.repo.url, "https://api.github.com/repos/jacquev6/PyGithub" + ) self.assertEqual(self.repo.watchers, 15) # test __repr__() based on this attributes - self.assertEqual(self.repo.__repr__(), 'Repository(full_name="jacquev6/PyGithub")') + self.assertEqual( + self.repo.__repr__(), 'Repository(full_name="jacquev6/PyGithub")' + ) def testEditWithoutArguments(self): self.repo.edit("PyGithub") def testEditWithAllArguments(self): - self.repo.edit("PyGithub", "Description edited by PyGithub", "http://vincent-jacques.net/PyGithub", private=True, has_issues=True, has_projects=False, has_wiki=False, has_downloads=True, allow_squash_merge=True, allow_merge_commit=True, allow_rebase_merge=True) + self.repo.edit( + "PyGithub", + "Description edited by PyGithub", + "http://vincent-jacques.net/PyGithub", + private=True, + has_issues=True, + has_projects=False, + has_wiki=False, + has_downloads=True, + allow_squash_merge=True, + allow_merge_commit=True, + allow_rebase_merge=True, + ) self.assertEqual(self.repo.description, "Description edited by PyGithub") self.repo.edit("PyGithub", "Python library implementing the full Github API v3") - self.assertEqual(self.repo.description, "Python library implementing the full Github API v3") + self.assertEqual( + self.repo.description, "Python library implementing the full Github API v3" + ) def testEditWithDefaultBranch(self): self.assertEqual(self.repo.master_branch, None) @@ -117,10 +145,19 @@ class Repository(Framework.TestCase): repo.delete() def testGetContributors(self): - self.assertListKeyEqual(self.repo.get_contributors(), lambda c: (c.login, c.contributions), [("jacquev6", 355)]) + self.assertListKeyEqual( + self.repo.get_contributors(), + lambda c: (c.login, c.contributions), + [("jacquev6", 355)], + ) def testCreateMilestone(self): - milestone = self.repo.create_milestone("Milestone created by PyGithub", state="open", description="Description created by PyGithub", due_on=datetime.date(2012, 6, 15)) + milestone = self.repo.create_milestone( + "Milestone created by PyGithub", + state="open", + description="Description created by PyGithub", + due_on=datetime.date(2012, 6, 15), + ) self.assertEqual(milestone.number, 5) def testCreateMilestoneWithMinimalArguments(self): @@ -135,40 +172,72 @@ class Repository(Framework.TestCase): user = self.g.get_user("jacquev6") milestone = self.repo.get_milestone(2) question = self.repo.get_label("Question") - issue = self.repo.create_issue("Issue also created by PyGithub", "Body created by PyGithub", user, milestone, [question], ["jacquev6", "stuglaser"]) + issue = self.repo.create_issue( + "Issue also created by PyGithub", + "Body created by PyGithub", + user, + milestone, + [question], + ["jacquev6", "stuglaser"], + ) self.assertEqual(issue.number, 30) def testCreateIssueWithAllArgumentsStringLabel(self): user = self.g.get_user("jacquev6") milestone = self.repo.get_milestone(2) - issue = self.repo.create_issue("Issue also created by PyGithub", "Body created by PyGithub", user, milestone, ["Question"], ["jacquev6", "stuglaser"]) + issue = self.repo.create_issue( + "Issue also created by PyGithub", + "Body created by PyGithub", + user, + milestone, + ["Question"], + ["jacquev6", "stuglaser"], + ) self.assertEqual(issue.number, 30) def testCreateLabel(self): - label = self.repo.create_label("Label with silly name % * + created by PyGithub", "00ff00", "Description of label with silly name") + label = self.repo.create_label( + "Label with silly name % * + created by PyGithub", + "00ff00", + "Description of label with silly name", + ) self.assertEqual(label.color, "00ff00") self.assertEqual(label.description, "Description of label with silly name") self.assertEqual(label.name, "Label with silly name % * + created by PyGithub") - self.assertEqual(label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub") + self.assertEqual( + label.url, + "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub", + ) def testGetLabel(self): label = self.repo.get_label("Label with silly name % * + created by PyGithub") self.assertEqual(label.color, "00ff00") self.assertEqual(label.name, "Label with silly name % * + created by PyGithub") - self.assertEqual(label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub") + self.assertEqual( + label.url, + "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub", + ) def testCreateHookWithMinimalParameters(self): hook = self.repo.create_hook("web", {"url": "http://foobar.com"}) self.assertEqual(hook.id, 257967) def testCreateHookWithAllParameters(self): - hook = self.repo.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False) + hook = self.repo.create_hook( + "web", {"url": "http://foobar.com"}, ["fork"], False + ) self.assertTrue(hook.active) # WTF self.assertEqual(hook.id, 257993) def testCreateGitRef(self): - ref = self.repo.create_git_ref("refs/heads/BranchCreatedByPyGithub", "4303c5b90e2216d927155e9609436ccb8984c495") - self.assertEqual(ref.url, "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub") + ref = self.repo.create_git_ref( + "refs/heads/BranchCreatedByPyGithub", + "4303c5b90e2216d927155e9609436ccb8984c495", + ) + self.assertEqual( + ref.url, + "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub", + ) def testCreateGitBlob(self): blob = self.repo.create_git_blob("Blob created by PyGithub", "latin1") @@ -176,36 +245,41 @@ class Repository(Framework.TestCase): def testCreateGitTree(self): tree = self.repo.create_git_tree( - [github.InputGitTreeElement( - "Foobar.txt", - "100644", - "blob", - content="File created by PyGithub" - )] + [ + github.InputGitTreeElement( + "Foobar.txt", "100644", "blob", content="File created by PyGithub" + ) + ] ) self.assertEqual(tree.sha, "41cf8c178c636a018d537cb20daae09391efd70b") def testCreateGitTreeWithBaseTree(self): - base_tree = self.repo.get_git_tree("41cf8c178c636a018d537cb20daae09391efd70b", recursive=False) + base_tree = self.repo.get_git_tree( + "41cf8c178c636a018d537cb20daae09391efd70b", recursive=False + ) tree = self.repo.create_git_tree( - [github.InputGitTreeElement( - "Barbaz.txt", - "100644", - "blob", - content="File also created by PyGithub" - )], - base_tree + [ + github.InputGitTreeElement( + "Barbaz.txt", + "100644", + "blob", + content="File also created by PyGithub", + ) + ], + base_tree, ) self.assertEqual(tree.sha, "107139a922f33bab6fbeb9f9eb8787e7f19e0528") def testCreateGitTreeWithSha(self): tree = self.repo.create_git_tree( - [github.InputGitTreeElement( - "Barbaz.txt", - "100644", - "blob", - sha="5dd930f591cd5188e9ea7200e308ad355182a1d8" - )] + [ + github.InputGitTreeElement( + "Barbaz.txt", + "100644", + "blob", + sha="5dd930f591cd5188e9ea7200e308ad355182a1d8", + ) + ] ) self.assertEqual(tree.sha, "fae707821159639589bf94f3fb0a7154ec5d441b") @@ -220,12 +294,24 @@ class Repository(Framework.TestCase): self.repo.get_git_commit("12d427464f8d91c8e981043a86ba8a2a9e7319ea"), ] tree = self.repo.get_git_tree("fae707821159639589bf94f3fb0a7154ec5d441b") - commit = self.repo.create_git_commit("Commit created by PyGithub", tree, parents) + commit = self.repo.create_git_commit( + "Commit created by PyGithub", tree, parents + ) self.assertEqual(commit.sha, "6adf9ea25ff8a8f2a42bcb1c09e42526339037cd") def testCreateGitCommitWithAllArguments(self): tree = self.repo.get_git_tree("107139a922f33bab6fbeb9f9eb8787e7f19e0528") - commit = self.repo.create_git_commit("Commit created by PyGithub", tree, [], github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"), github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00")) + commit = self.repo.create_git_commit( + "Commit created by PyGithub", + tree, + [], + github.InputGitAuthor( + "John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00" + ), + github.InputGitAuthor( + "John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00" + ), + ) self.assertEqual(commit.sha, "526946197ae9da59c6507cacd13ad6f1cfb686ea") def testCreateGitRelease(self): @@ -254,33 +340,69 @@ class Repository(Framework.TestCase): self.assertEqual(release.body, "This release is also created by PyGithub") self.assertEqual(release.draft, False) self.assertEqual(release.prerelease, True) - tag = [tag for tag in self.repo.get_tags() if tag.name == "vX.Y.Z-by-PyGithub-acctest2"].pop() + tag = [ + tag + for tag in self.repo.get_tags() + if tag.name == "vX.Y.Z-by-PyGithub-acctest2" + ].pop() self.assertEqual(tag.commit.sha, "da9a285fd8b782461e56cba39ae8d2fa41ca7cdc") def testCreateGitTag(self): - tag = self.repo.create_git_tag("TaggedByPyGithub", "Tag created by PyGithub", "0b820628236ab8bab3890860fc414fa757ca15f4", "commit") + tag = self.repo.create_git_tag( + "TaggedByPyGithub", + "Tag created by PyGithub", + "0b820628236ab8bab3890860fc414fa757ca15f4", + "commit", + ) self.assertEqual(tag.sha, "5ba561eaa2b7ca9015662510157b15d8f3b0232a") def testCreateGitTagWithAllArguments(self): - tag = self.repo.create_git_tag("TaggedByPyGithub2", "Tag also created by PyGithub", "526946197ae9da59c6507cacd13ad6f1cfb686ea", "commit", github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00")) + tag = self.repo.create_git_tag( + "TaggedByPyGithub2", + "Tag also created by PyGithub", + "526946197ae9da59c6507cacd13ad6f1cfb686ea", + "commit", + github.InputGitAuthor( + "John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00" + ), + ) self.assertEqual(tag.sha, "f0e99a8335fbc84c53366c4a681118468f266625") def testCreateKey(self): - key = self.repo.create_key("Key added through PyGithub", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE") + key = self.repo.create_key( + "Key added through PyGithub", + "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE", + ) self.assertEqual(key.id, 2626761) def testCreateSourceImport(self): import_repo = self.g.get_user("brix4dayz").get_repo("source-import-test") - source_import = import_repo.create_source_import("mercurial", "https://bitbucket.org/hfuss/source-import-test") + source_import = import_repo.create_source_import( + "mercurial", "https://bitbucket.org/hfuss/source-import-test" + ) self.assertEqual(source_import.authors_count, 0) - self.assertEqual(source_import.authors_url, "https://api.github.com/repos/brix4dayz/source-import-test/import/authors") - self.assertEqual(source_import.html_url, "https://github.com/brix4dayz/source-import-test/import") - self.assertEqual(source_import.repository_url, "https://api.github.com/repos/brix4dayz/source-import-test") + self.assertEqual( + source_import.authors_url, + "https://api.github.com/repos/brix4dayz/source-import-test/import/authors", + ) + self.assertEqual( + source_import.html_url, + "https://github.com/brix4dayz/source-import-test/import", + ) + self.assertEqual( + source_import.repository_url, + "https://api.github.com/repos/brix4dayz/source-import-test", + ) self.assertEqual(source_import.status, "importing") self.assertEqual(source_import.status_text, "Importing...") - self.assertEqual(source_import.url, "https://api.github.com/repos/brix4dayz/source-import-test/import") + self.assertEqual( + source_import.url, + "https://api.github.com/repos/brix4dayz/source-import-test/import", + ) self.assertEqual(source_import.vcs, "mercurial") - self.assertEqual(source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test") + self.assertEqual( + source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test" + ) def testCollaborators(self): lyloa = self.g.get_user("Lyloa") @@ -298,7 +420,7 @@ class Repository(Framework.TestCase): self.assertFalse(self.repo.has_in_collaborators(lyloa)) def testCollaboratorPermission(self): - self.assertEqual(self.repo.get_collaborator_permission('jacquev6'), 'admin') + self.assertEqual(self.repo.get_collaborator_permission("jacquev6"), "admin") def testGetPendingInvitations(self): lyloa = self.g.get_user("Lyloa") @@ -311,27 +433,65 @@ class Repository(Framework.TestCase): def testCollaboratorPermissionNoPushAccess(self): with self.assertRaises(github.GithubException) as raisedexp: - self.repo.get_collaborator_permission('lyloa') + self.repo.get_collaborator_permission("lyloa") self.assertEqual(raisedexp.exception.status, 403) - self.assertEqual(raisedexp.exception.data, { - u'documentation_url': u'https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level', - u'message': u'Must have push access to view collaborator permission.' - }) + self.assertEqual( + raisedexp.exception.data, + { + u"documentation_url": u"https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level", + u"message": u"Must have push access to view collaborator permission.", + }, + ) def testCompare(self): comparison = self.repo.compare("v0.6", "v0.7") self.assertEqual(comparison.status, "ahead") self.assertEqual(comparison.ahead_by, 4) self.assertEqual(comparison.behind_by, 0) - self.assertEqual(comparison.diff_url, "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.diff") - self.assertEqual(comparison.html_url, "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7") - self.assertEqual(comparison.url, "https://api.github.com/repos/jacquev6/PyGithub/compare/v0.6...v0.7") - self.assertEqual(comparison.patch_url, "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.patch") - self.assertEqual(comparison.permalink_url, "https://github.com/jacquev6/PyGithub/compare/jacquev6:4303c5b...jacquev6:ecda065") + self.assertEqual( + comparison.diff_url, + "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.diff", + ) + self.assertEqual( + comparison.html_url, + "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7", + ) + self.assertEqual( + comparison.url, + "https://api.github.com/repos/jacquev6/PyGithub/compare/v0.6...v0.7", + ) + self.assertEqual( + comparison.patch_url, + "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.patch", + ) + self.assertEqual( + comparison.permalink_url, + "https://github.com/jacquev6/PyGithub/compare/jacquev6:4303c5b...jacquev6:ecda065", + ) self.assertEqual(comparison.total_commits, 4) - self.assertListKeyEqual(comparison.files, lambda f: f.filename, ["ReferenceOfClasses.md", "github/Github.py", "github/Requester.py", "setup.py"]) - self.assertEqual(comparison.base_commit.sha, "4303c5b90e2216d927155e9609436ccb8984c495") - self.assertListKeyEqual(comparison.commits, lambda c: c.sha, ["5bb654d26dd014d36794acd1e6ecf3736f12aad7", "cb0313157bf904f2d364377d35d9397b269547a5", "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7"]) + self.assertListKeyEqual( + comparison.files, + lambda f: f.filename, + [ + "ReferenceOfClasses.md", + "github/Github.py", + "github/Requester.py", + "setup.py", + ], + ) + self.assertEqual( + comparison.base_commit.sha, "4303c5b90e2216d927155e9609436ccb8984c495" + ) + self.assertListKeyEqual( + comparison.commits, + lambda c: c.sha, + [ + "5bb654d26dd014d36794acd1e6ecf3736f12aad7", + "cb0313157bf904f2d364377d35d9397b269547a5", + "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", + "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", + ], + ) def testGetComments(self): self.assertListKeyEqual( @@ -341,49 +501,243 @@ class Repository(Framework.TestCase): "probably a noob question: does this completion refer to autocompletion in IDE's/editors? \nI have observed that this is pretty erratic sometimes. I'm using PyDev+Eclipse.\nFor example, in the tutorial from the readme, `g.get_u` gets autocompleted correctly, but `g.get_user().get_r` (or any method or attribute applicable to NamedUsers/AuthenticatedUser, really) does not show autocompletion to `g.get_user().get_repo()`. Is that by design? It makes exploring the library/API a bit cumbersome. ", "No, it has nothing to do with auto-completion in IDEs :D\n\nGithub API v3 sends only the main part of objects in reply to some requests. So, if the user wants an attribute that has not been received yet, I have to do another request to complete the object.\n\nYet, in version 1.0 (see the milesone), my library will be much more readable for IDEs and their auto-completion mechanisms, because I am giving up the meta-description that I used until 0.6, and I'm now generating much more traditional code, that you will be able to explore as if it was written manually.\n\nIf you want to take the time to open an issue about auto-completion in IDEs, I'll deal with it in milestone 1.0.\n\nThanks !", "Ah, thanks for the clarification. :blush:\n\nI made issue #27 for the autocompletion. I already suspected something like this meta-description magic, since I tried to read some of the code and it was pretty arcane. I attributed that to my pythonic noobness, though. Thank you. ", - "Comment created by PyGithub" - ] + "Comment created by PyGithub", + ], ) def testGetCommits(self): - self.assertListKeyBegin(self.repo.get_commits(), lambda c: c.sha, ['ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7', '0cec0d25e606c023a62a4fc7cdc815309ebf6d16', 'cb0313157bf904f2d364377d35d9397b269547a5', '5bb654d26dd014d36794acd1e6ecf3736f12aad7', '4303c5b90e2216d927155e9609436ccb8984c495', '2a7e80e6421c5d4d201d60619068dea6bae612cb', '0af24499a98e85f8ab2191898e8b809e5cebd4c5', 'e5ae923a68a9ae295ce5aa20b1227253de60e918', '2f64b625f7e2afc9bef61d0decb459e2ef65c550', '590798d349cba7de6e83b43aa5d4f8b0a38e685d', 'e7dca9143a23b8e2045a4a910a4a329007b10086', 'ab3f9b422cb3043d35cf6002fc9c042f8ead8c2a', '632d8b63c32a2b79e87eb3b93e1ad228724de4bd', '64c6a1e975e61b9c1449bed016cd19f33ee4b1c5', '99963536fc81db3b9986c761b9dd08de22089aa2', '8d57522bbd15d1fb6b616fae795cd8721deb1c4d', '1140a91f3e45d09bc15463724f178a7ebf8e3149', '936f4a97f1a86392637ec002bbf89ff036a5062d', 'e10470481795506e2c232720e2a9ecf588c8b567', 'e456549e5265406f8090ae5145255c8ca9ea5e4e', 'a91131be42eb328ae030f584af500f56aa08424b', '2469c6e1aeb7919126a8271f6980b555b167e8b0', 'a655d0424135befd3a0d53f3f7eff2d1c754854f', 'ce62e91268aa34dad0ba0dbee4769933e3a71e50', '1c88ee221b7f995855a1fdfac7d0ba19db918739', 'bd1a5dff3c547c634b2d89f5847218820e343883', 'b226b5b4e2f44107dde674e7a5d3e88d4e3518df', '25dbd4053e982402c7d92139f167dbe46008c932', 'a0cc821c1beada4aa9ca0d5218664c5372720936', 'c1440bdf20bfeb62684c6d1779448719dce9d2df', '1095d304b7fab3818dcb4c42093c8c56d3ac05e4', 'bd39726f7cf86ea7ffb33b5718241fdab5fc8f53', '1d2b27824d20612066d84be42d6691c66bb18ef4', '6af2bfd0d46bc0eeb8c37b85c7b3003e0e4ae297', 'a475d685d8ae709095d09094ea0962ac182d33f0', 'a85de99ea5b5e7b38bd68e076d09c49207b8687e', 'd24cf209ddd1758188c5f35344f76df818d09a46', '0909fec395bb1f97e2580d6a029cfc64b352aff9', '6e421e9e85e12008758870bc046bc2c6120af72a', '32ed0ebc377efbed5b482b3d49ff54bf1715d55a', '8213df1d744f251aa8e52229643a9f6ce352f3c0', '69cc298fd159f19eb204dd09f17d31dc4abc3d41', '85eef756353e13efcb24c726320cd2617c2a7bd8', '50ac55b25ceba555b84709839f80447552450697', '767d75a580279e457f9bc52bc308a17ff8ea0509', '75e72ffa3066693291f7da03070666e8f885097a', '504047e218e6b34a3828ccc408431634f17b9504', '960db1d5c9853e9f5fbbc9237c2c166ceef1f080', '877dde23e140bbf038f9a2d8f0f07b4e3a965c61', '1c95ddfa09ec0aa1f07ee9ad50a77be1dd74b55e', '99564c1cab139d1e4678f5f83f60d26f1210db7e', '231926207709ceaa61e87b64e34e17d85adecd9c', 'fb722625dddb9a32f75190723f7da12683b7c4b2', 'cab9d71603e127bdd1f600a759dccea1781fa1ab', 'e648e5aeb5edc1fbf83e9d37d2a3cb57c005019a', '4a5cf98e7f959f1b5d9af484760c25cd27d9180d', '5d1add448e0b0b1dadb8c6094a9e5e19b255f67e', '0d9fc99a4b5d1ec6473c9c81c888917c132ffa65', 'b56aa09011378b014221f86dffb8304957a9e6bd', '3e8169c0a98ce1e2c6a32ae1256ae0f735065df5', '378558f6cac6183b4a7100c0ce5eaad1cfff6717', '58b4396aa0e7cb72911b75cb035798143a06e0ee', 'a3be28756101370fbc689eec3a7825c4c385a6c9', '3d6bd49ce229243fea4bb46a937622d0ec7d4d1c', '58cb0dbdef9765e0e913c726f923a47315aaf80e', '7b7ac20c6fa27f72a24483c73ab1bf4deffc89f0', '97f308e67383368a2d15788cac28e126c8528bb2', 'fc33a6de4f0e08d7ff2de05935517ec3932d212e', 'cc6d0fc044eadf2e6fde5da699f61654c1e691f3', '2dd71f3777b87f2ba61cb20d2c67f10401e3eb2c', '366ca58ca004b9129f9d435db8204ce0f5bc57c3', '0d3b3ffd1e5c143af8725fdee808101f626f683d', '157f9c13275738b6b39b8d7a874f5f0aee47cb18']) + self.assertListKeyBegin( + self.repo.get_commits(), + lambda c: c.sha, + [ + "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", + "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", + "cb0313157bf904f2d364377d35d9397b269547a5", + "5bb654d26dd014d36794acd1e6ecf3736f12aad7", + "4303c5b90e2216d927155e9609436ccb8984c495", + "2a7e80e6421c5d4d201d60619068dea6bae612cb", + "0af24499a98e85f8ab2191898e8b809e5cebd4c5", + "e5ae923a68a9ae295ce5aa20b1227253de60e918", + "2f64b625f7e2afc9bef61d0decb459e2ef65c550", + "590798d349cba7de6e83b43aa5d4f8b0a38e685d", + "e7dca9143a23b8e2045a4a910a4a329007b10086", + "ab3f9b422cb3043d35cf6002fc9c042f8ead8c2a", + "632d8b63c32a2b79e87eb3b93e1ad228724de4bd", + "64c6a1e975e61b9c1449bed016cd19f33ee4b1c5", + "99963536fc81db3b9986c761b9dd08de22089aa2", + "8d57522bbd15d1fb6b616fae795cd8721deb1c4d", + "1140a91f3e45d09bc15463724f178a7ebf8e3149", + "936f4a97f1a86392637ec002bbf89ff036a5062d", + "e10470481795506e2c232720e2a9ecf588c8b567", + "e456549e5265406f8090ae5145255c8ca9ea5e4e", + "a91131be42eb328ae030f584af500f56aa08424b", + "2469c6e1aeb7919126a8271f6980b555b167e8b0", + "a655d0424135befd3a0d53f3f7eff2d1c754854f", + "ce62e91268aa34dad0ba0dbee4769933e3a71e50", + "1c88ee221b7f995855a1fdfac7d0ba19db918739", + "bd1a5dff3c547c634b2d89f5847218820e343883", + "b226b5b4e2f44107dde674e7a5d3e88d4e3518df", + "25dbd4053e982402c7d92139f167dbe46008c932", + "a0cc821c1beada4aa9ca0d5218664c5372720936", + "c1440bdf20bfeb62684c6d1779448719dce9d2df", + "1095d304b7fab3818dcb4c42093c8c56d3ac05e4", + "bd39726f7cf86ea7ffb33b5718241fdab5fc8f53", + "1d2b27824d20612066d84be42d6691c66bb18ef4", + "6af2bfd0d46bc0eeb8c37b85c7b3003e0e4ae297", + "a475d685d8ae709095d09094ea0962ac182d33f0", + "a85de99ea5b5e7b38bd68e076d09c49207b8687e", + "d24cf209ddd1758188c5f35344f76df818d09a46", + "0909fec395bb1f97e2580d6a029cfc64b352aff9", + "6e421e9e85e12008758870bc046bc2c6120af72a", + "32ed0ebc377efbed5b482b3d49ff54bf1715d55a", + "8213df1d744f251aa8e52229643a9f6ce352f3c0", + "69cc298fd159f19eb204dd09f17d31dc4abc3d41", + "85eef756353e13efcb24c726320cd2617c2a7bd8", + "50ac55b25ceba555b84709839f80447552450697", + "767d75a580279e457f9bc52bc308a17ff8ea0509", + "75e72ffa3066693291f7da03070666e8f885097a", + "504047e218e6b34a3828ccc408431634f17b9504", + "960db1d5c9853e9f5fbbc9237c2c166ceef1f080", + "877dde23e140bbf038f9a2d8f0f07b4e3a965c61", + "1c95ddfa09ec0aa1f07ee9ad50a77be1dd74b55e", + "99564c1cab139d1e4678f5f83f60d26f1210db7e", + "231926207709ceaa61e87b64e34e17d85adecd9c", + "fb722625dddb9a32f75190723f7da12683b7c4b2", + "cab9d71603e127bdd1f600a759dccea1781fa1ab", + "e648e5aeb5edc1fbf83e9d37d2a3cb57c005019a", + "4a5cf98e7f959f1b5d9af484760c25cd27d9180d", + "5d1add448e0b0b1dadb8c6094a9e5e19b255f67e", + "0d9fc99a4b5d1ec6473c9c81c888917c132ffa65", + "b56aa09011378b014221f86dffb8304957a9e6bd", + "3e8169c0a98ce1e2c6a32ae1256ae0f735065df5", + "378558f6cac6183b4a7100c0ce5eaad1cfff6717", + "58b4396aa0e7cb72911b75cb035798143a06e0ee", + "a3be28756101370fbc689eec3a7825c4c385a6c9", + "3d6bd49ce229243fea4bb46a937622d0ec7d4d1c", + "58cb0dbdef9765e0e913c726f923a47315aaf80e", + "7b7ac20c6fa27f72a24483c73ab1bf4deffc89f0", + "97f308e67383368a2d15788cac28e126c8528bb2", + "fc33a6de4f0e08d7ff2de05935517ec3932d212e", + "cc6d0fc044eadf2e6fde5da699f61654c1e691f3", + "2dd71f3777b87f2ba61cb20d2c67f10401e3eb2c", + "366ca58ca004b9129f9d435db8204ce0f5bc57c3", + "0d3b3ffd1e5c143af8725fdee808101f626f683d", + "157f9c13275738b6b39b8d7a874f5f0aee47cb18", + ], + ) def testGetCommitsWithArguments(self): - self.assertListKeyEqual(self.repo.get_commits("topic/RewriteWithGeneratedCode", "codegen/GenerateCode.py"), lambda c: c.sha, ["de386d5dc9cf103c90c4128eeca0e6abdd382065", "5b44982f6111bff2454243869df2e1c3086ccbba", "d6835ff949141957a733c8ddfa147026515ae493", "075d3d961d4614a2a0835d5583248adfc0687a7d", "8956796e7f462a49f499eac52fab901cdb59abdb", "283da5e7de6a4a3b6aaae7045909d70b643ad380", "d631e83b7901b0a0b6061b361130700a79505319"]) + self.assertListKeyEqual( + self.repo.get_commits( + "topic/RewriteWithGeneratedCode", "codegen/GenerateCode.py" + ), + lambda c: c.sha, + [ + "de386d5dc9cf103c90c4128eeca0e6abdd382065", + "5b44982f6111bff2454243869df2e1c3086ccbba", + "d6835ff949141957a733c8ddfa147026515ae493", + "075d3d961d4614a2a0835d5583248adfc0687a7d", + "8956796e7f462a49f499eac52fab901cdb59abdb", + "283da5e7de6a4a3b6aaae7045909d70b643ad380", + "d631e83b7901b0a0b6061b361130700a79505319", + ], + ) def testGetCommitsWithSinceUntil(self): - self.assertListKeyEqual(self.repo.get_commits(since=datetime.datetime(2013, 3, 1), until=datetime.datetime(2013, 3, 31)), lambda c: c.sha, ['db5560bd658b5d8057a864f7037ace4d5f618f1b', 'f266fed520fea4f683caabe0b38e1f758cfc5cff', 'dff094650011398fd8f0a57bf2668a066fb2cbcb', 'c1d747a9133a1c6cae1f0e11105a5f490f65fda6', '0bc368973acfb50a531329b6c196ba92e0a81890', '7b3e4c15ed6182963d66ffa9f0522acd0765275c', '4df3a7eb47888f38c4c6dae50573f030a0a3f1e1', 'e0db8cad4ec01c65e5e0eb50e11765e425e88ef9', '1c47be4e895b823baf907b25c647e43ab63c16dd', '8a9afbb1aa36c6ba04142c6e6c1cfbd7de982a6a', '1c67359a318f05e50bf457818e1983ce95aa5946', '1d18bd66f3a4a4225435bd38df04b8a227b5e821', 'b9d71fa787a2ffb99b6631e4bd6df932a4d4adbb', 'f5d8e221d116b74a200d87afca32247f01204ba1', 'dc96fef052f2b5c6adb34da65169e8df3f35f611', 'c85af79db11ed1d2f93261ea4069a23ff1709125', '0dd1adb4f06f45d554d12083b312fcdb6f6be8d1', 'b7e4000450e89b8c6e947e3a1e52fb06da7c9621', '1d9ad14fa918866c418067e774f65cede8e38682', '1bb05fef01d0a040cb2b931a4d44392784a2f0c1', 'd9b29851ddccc907f71f1ae662e57f2cd7c7dc71', 'f962bc71fee609cd54fe69c956c8b81703d2c19a', '7a9c0b916c632be8d6a65bc1b6f558508f04bb22', '82ce7b1ee30d308b48bdac6d8737dbca70500462', '1e99e7d5b21c71bf68cc5cc21faec30ee603b8b8', 'a397fac6db9f87a903ec3ede9643cb2b4224ed82', '109495175e926731703a55cafd8b542a07366513', 'da6bbdb69485fc3256030d8296589d4c2fb5df21', '34c18342dcce9697abc6f522c3506485202e6e7e', 'ee29deddd27480401db484733ecde9e7b1df5eda', '0901df1a2bed3f993cfe6e0d4cff5923bbf6ce32', 'edcf40bc7f25d1aff5c404406fbb37ad1bcf691e', 'f25c54e1d4eefb11c18f3de85270a4b19edea3ce', '23d668f11bdd806a871e0979bf5295d001f66ef2', '50a243671f1fa139cb1186c4a44c1e96b8cd5749', '6a3a384fd0decac1203db6c2bddc58039b0390bc', '82f5b4c61f86ae8c7cc85a31cb1a31180eeae32f', '6ac783974d3985dd0c162c1e8d1150615cc0082e', '0f9bb5d9fd2dcfbf03f094362e86323c9ef915e6', 'e25a6a49d1ab1a10c84db9b6722a6186ff6dfcbd', '4f1780f427eba400cbc06897e69eda0ecdecd887', '28648a51a15e430b85d6fe8f2514e1cb06bc76b8', 'a39f421ca24bd7aae984f8703159c7e30798a121', '86fe370b97b62548317cb35bc02ece3fabb7fa03', '03a256a4052cacea998d8205a83d5b5465f31e18', '9e6b086c2db5e4884484a04934f6f2e53e3f441b', '0ddb34d987b5a03813fdfa2fac13c933834a4804']) + self.assertListKeyEqual( + self.repo.get_commits( + since=datetime.datetime(2013, 3, 1), + until=datetime.datetime(2013, 3, 31), + ), + lambda c: c.sha, + [ + "db5560bd658b5d8057a864f7037ace4d5f618f1b", + "f266fed520fea4f683caabe0b38e1f758cfc5cff", + "dff094650011398fd8f0a57bf2668a066fb2cbcb", + "c1d747a9133a1c6cae1f0e11105a5f490f65fda6", + "0bc368973acfb50a531329b6c196ba92e0a81890", + "7b3e4c15ed6182963d66ffa9f0522acd0765275c", + "4df3a7eb47888f38c4c6dae50573f030a0a3f1e1", + "e0db8cad4ec01c65e5e0eb50e11765e425e88ef9", + "1c47be4e895b823baf907b25c647e43ab63c16dd", + "8a9afbb1aa36c6ba04142c6e6c1cfbd7de982a6a", + "1c67359a318f05e50bf457818e1983ce95aa5946", + "1d18bd66f3a4a4225435bd38df04b8a227b5e821", + "b9d71fa787a2ffb99b6631e4bd6df932a4d4adbb", + "f5d8e221d116b74a200d87afca32247f01204ba1", + "dc96fef052f2b5c6adb34da65169e8df3f35f611", + "c85af79db11ed1d2f93261ea4069a23ff1709125", + "0dd1adb4f06f45d554d12083b312fcdb6f6be8d1", + "b7e4000450e89b8c6e947e3a1e52fb06da7c9621", + "1d9ad14fa918866c418067e774f65cede8e38682", + "1bb05fef01d0a040cb2b931a4d44392784a2f0c1", + "d9b29851ddccc907f71f1ae662e57f2cd7c7dc71", + "f962bc71fee609cd54fe69c956c8b81703d2c19a", + "7a9c0b916c632be8d6a65bc1b6f558508f04bb22", + "82ce7b1ee30d308b48bdac6d8737dbca70500462", + "1e99e7d5b21c71bf68cc5cc21faec30ee603b8b8", + "a397fac6db9f87a903ec3ede9643cb2b4224ed82", + "109495175e926731703a55cafd8b542a07366513", + "da6bbdb69485fc3256030d8296589d4c2fb5df21", + "34c18342dcce9697abc6f522c3506485202e6e7e", + "ee29deddd27480401db484733ecde9e7b1df5eda", + "0901df1a2bed3f993cfe6e0d4cff5923bbf6ce32", + "edcf40bc7f25d1aff5c404406fbb37ad1bcf691e", + "f25c54e1d4eefb11c18f3de85270a4b19edea3ce", + "23d668f11bdd806a871e0979bf5295d001f66ef2", + "50a243671f1fa139cb1186c4a44c1e96b8cd5749", + "6a3a384fd0decac1203db6c2bddc58039b0390bc", + "82f5b4c61f86ae8c7cc85a31cb1a31180eeae32f", + "6ac783974d3985dd0c162c1e8d1150615cc0082e", + "0f9bb5d9fd2dcfbf03f094362e86323c9ef915e6", + "e25a6a49d1ab1a10c84db9b6722a6186ff6dfcbd", + "4f1780f427eba400cbc06897e69eda0ecdecd887", + "28648a51a15e430b85d6fe8f2514e1cb06bc76b8", + "a39f421ca24bd7aae984f8703159c7e30798a121", + "86fe370b97b62548317cb35bc02ece3fabb7fa03", + "03a256a4052cacea998d8205a83d5b5465f31e18", + "9e6b086c2db5e4884484a04934f6f2e53e3f441b", + "0ddb34d987b5a03813fdfa2fac13c933834a4804", + ], + ) def testGetCommitsWithAuthor(self): self.g.per_page = 5 akfish = self.g.get_user("AKFish") - self.assertListKeyBegin(self.repo.get_commits(author=self.user), lambda c: c.sha, ["54f718a15770579a37ffbe7ae94ad30003407786"]) - self.assertListKeyBegin(self.repo.get_commits(author=akfish), lambda c: c.sha, ["38b137fb37c0fdc74f8802a4184518e105db9121"]) - self.assertListKeyBegin(self.repo.get_commits(author="m.ki2@laposte.net"), lambda c: c.sha, ["ab674dfcbc86c70bc32d9ecbe171b48a5694c337"]) + self.assertListKeyBegin( + self.repo.get_commits(author=self.user), + lambda c: c.sha, + ["54f718a15770579a37ffbe7ae94ad30003407786"], + ) + self.assertListKeyBegin( + self.repo.get_commits(author=akfish), + lambda c: c.sha, + ["38b137fb37c0fdc74f8802a4184518e105db9121"], + ) + self.assertListKeyBegin( + self.repo.get_commits(author="m.ki2@laposte.net"), + lambda c: c.sha, + ["ab674dfcbc86c70bc32d9ecbe171b48a5694c337"], + ) def testGetDownloads(self): self.assertListKeyEqual(self.repo.get_downloads(), lambda d: d.id, [245143]) def testGetEvents(self): - self.assertListKeyBegin(self.repo.get_events(), lambda e: e.type, ["DownloadEvent", "DownloadEvent", "PushEvent", "IssuesEvent", "MemberEvent", "MemberEvent"]) + self.assertListKeyBegin( + self.repo.get_events(), + lambda e: e.type, + [ + "DownloadEvent", + "DownloadEvent", + "PushEvent", + "IssuesEvent", + "MemberEvent", + "MemberEvent", + ], + ) def testGetForks(self): - self.assertListKeyEqual(self.repo.get_forks(), lambda r: r.owner.login, ["abersager"]) + self.assertListKeyEqual( + self.repo.get_forks(), lambda r: r.owner.login, ["abersager"] + ) def testCreateFork(self): self.assertEqual(self.repo.create_fork("prtg-dev").full_name, "prtg-dev/PyGithub") def testGetGitRefs(self): - self.assertListKeyEqual(self.repo.get_git_refs(), lambda r: r.ref, ["refs/heads/develop", "refs/heads/master", "refs/heads/topic/DependencyGraph", "refs/heads/topic/RewriteWithGeneratedCode", "refs/tags/v0.1", "refs/tags/v0.2", "refs/tags/v0.3", "refs/tags/v0.4", "refs/tags/v0.5", "refs/tags/v0.6", "refs/tags/v0.7"]) + self.assertListKeyEqual( + self.repo.get_git_refs(), + lambda r: r.ref, + [ + "refs/heads/develop", + "refs/heads/master", + "refs/heads/topic/DependencyGraph", + "refs/heads/topic/RewriteWithGeneratedCode", + "refs/tags/v0.1", + "refs/tags/v0.2", + "refs/tags/v0.3", + "refs/tags/v0.4", + "refs/tags/v0.5", + "refs/tags/v0.6", + "refs/tags/v0.7", + ], + ) def testGetGitRef(self): self.assertTrue(self.g.FIX_REPO_GET_GIT_REF) - self.assertEqual(self.repo.get_git_ref("heads/master").object.sha, "31110327ec45f3138e58ed247b2cf420fee481ec") + self.assertEqual( + self.repo.get_git_ref("heads/master").object.sha, + "31110327ec45f3138e58ed247b2cf420fee481ec", + ) def testGetGitRefWithIssue102Reverted(self): self.g.FIX_REPO_GET_GIT_REF = False self.assertFalse(self.g.FIX_REPO_GET_GIT_REF) - self.assertEqual(self.repo.get_git_ref("refs/heads/master").object.sha, "31110327ec45f3138e58ed247b2cf420fee481ec") + self.assertEqual( + self.repo.get_git_ref("refs/heads/master").object.sha, + "31110327ec45f3138e58ed247b2cf420fee481ec", + ) self.g.FIX_REPO_GET_GIT_REF = True self.assertTrue(self.g.FIX_REPO_GET_GIT_REF) @@ -396,30 +750,123 @@ class Repository(Framework.TestCase): self.assertListKeyEqual(self.repo.get_hooks(), lambda h: h.id, [257993]) def testGetIssues(self): - self.assertListKeyEqual(self.repo.get_issues(), lambda i: i.id, [4769659, 4639931, 4452000, 4356743, 3716033, 3715946, 3643837, 3628022, 3624595, 3624570, 3624561, 3624556, 3619973, 3527266, 3527245, 3527231]) + self.assertListKeyEqual( + self.repo.get_issues(), + lambda i: i.id, + [ + 4769659, + 4639931, + 4452000, + 4356743, + 3716033, + 3715946, + 3643837, + 3628022, + 3624595, + 3624570, + 3624561, + 3624556, + 3619973, + 3527266, + 3527245, + 3527231, + ], + ) def testGetIssuesWithArguments(self): milestone = self.repo.get_milestone(3) user = self.g.get_user("jacquev6") otherUser = self.g.get_user("Lyloa") bug = self.repo.get_label("Bug") - self.assertListKeyEqual(self.repo.get_issues(milestone, "closed"), lambda i: i.id, [3624472, 3620132, 3619658, 3561926]) - self.assertListKeyEqual(self.repo.get_issues(labels=[bug]), lambda i: i.id, [4780155]) - self.assertListKeyEqual(self.repo.get_issues(assignee=user, sort="comments", direction="asc"), lambda i: i.id, [4793106, 3527231, 3527266, 3624556, 4793216, 3619973, 3624595, 4452000, 3643837, 3628022, 3527245, 4793162, 4356743, 4780155]) - self.assertListKeyEqual(self.repo.get_issues(since=datetime.datetime(2012, 5, 28, 23, 0, 0)), lambda i: i.id, [4793216, 4793162, 4793106, 3624556, 3619973, 3527266]) - self.assertListKeyEqual(self.repo.get_issues(mentioned=otherUser), lambda i: i.id, [4793162]) + self.assertListKeyEqual( + self.repo.get_issues(milestone, "closed"), + lambda i: i.id, + [3624472, 3620132, 3619658, 3561926], + ) + self.assertListKeyEqual( + self.repo.get_issues(labels=[bug]), lambda i: i.id, [4780155] + ) + self.assertListKeyEqual( + self.repo.get_issues(assignee=user, sort="comments", direction="asc"), + lambda i: i.id, + [ + 4793106, + 3527231, + 3527266, + 3624556, + 4793216, + 3619973, + 3624595, + 4452000, + 3643837, + 3628022, + 3527245, + 4793162, + 4356743, + 4780155, + ], + ) + self.assertListKeyEqual( + self.repo.get_issues(since=datetime.datetime(2012, 5, 28, 23, 0, 0)), + lambda i: i.id, + [4793216, 4793162, 4793106, 3624556, 3619973, 3527266], + ) + self.assertListKeyEqual( + self.repo.get_issues(mentioned=otherUser), lambda i: i.id, [4793162] + ) def testGetIssuesWithWildcards(self): - self.assertListKeyEqual(self.repo.get_issues(milestone="*"), lambda i: i.id, [4809786, 4793216, 4789817, 4452000, 3628022, 3624595, 3619973, 3527231]) - self.assertListKeyEqual(self.repo.get_issues(milestone="none"), lambda i: i.id, [4823331, 4809803, 4809778, 4793106, 3643837, 3527245]) - self.assertListKeyEqual(self.repo.get_issues(assignee="*"), lambda i: i.id, [4823331, 4809803, 4809786, 4809778, 4793216, 4793106, 4789817, 4452000, 3643837, 3628022, 3624595, 3527245, 3527231]) - self.assertListKeyEqual(self.repo.get_issues(assignee="none"), lambda i: i.id, [3619973]) + self.assertListKeyEqual( + self.repo.get_issues(milestone="*"), + lambda i: i.id, + [4809786, 4793216, 4789817, 4452000, 3628022, 3624595, 3619973, 3527231], + ) + self.assertListKeyEqual( + self.repo.get_issues(milestone="none"), + lambda i: i.id, + [4823331, 4809803, 4809778, 4793106, 3643837, 3527245], + ) + self.assertListKeyEqual( + self.repo.get_issues(assignee="*"), + lambda i: i.id, + [ + 4823331, + 4809803, + 4809786, + 4809778, + 4793216, + 4793106, + 4789817, + 4452000, + 3643837, + 3628022, + 3624595, + 3527245, + 3527231, + ], + ) + self.assertListKeyEqual( + self.repo.get_issues(assignee="none"), lambda i: i.id, [3619973] + ) def testGetKeys(self): - self.assertListKeyEqual(self.repo.get_keys(), lambda k: k.title, ["Key added through PyGithub"]) + self.assertListKeyEqual( + self.repo.get_keys(), lambda k: k.title, ["Key added through PyGithub"] + ) def testGetLabels(self): - self.assertListKeyEqual(self.repo.get_labels(), lambda l: l.name, ["Refactoring", "Public interface", "Functionalities", "Project management", "Bug", "Question"]) + self.assertListKeyEqual( + self.repo.get_labels(), + lambda l: l.name, + [ + "Refactoring", + "Public interface", + "Functionalities", + "Project management", + "Bug", + "Question", + ], + ) def testGetLanguages(self): self.assertEqual(self.repo.get_languages(), {"Python": 127266, "Shell": 673}) @@ -428,40 +875,164 @@ class Repository(Framework.TestCase): self.assertListKeyEqual(self.repo.get_milestones(), lambda m: m.id, [93547]) def testGetMilestonesWithArguments(self): - self.assertListKeyEqual(self.repo.get_milestones("closed", "due_date", "asc"), lambda m: m.id, [93546, 95354, 108652, 124045]) + self.assertListKeyEqual( + self.repo.get_milestones("closed", "due_date", "asc"), + lambda m: m.id, + [93546, 95354, 108652, 124045], + ) def testGetIssuesEvents(self): - self.assertListKeyBegin(self.repo.get_issues_events(), lambda e: e.event, ["assigned", "subscribed", "closed", "assigned", "closed"]) + self.assertListKeyBegin( + self.repo.get_issues_events(), + lambda e: e.event, + ["assigned", "subscribed", "closed", "assigned", "closed"], + ) def testGetNetworkEvents(self): - self.assertListKeyBegin(self.repo.get_network_events(), lambda e: e.type, ["DownloadEvent", "DownloadEvent", "PushEvent", "IssuesEvent", "MemberEvent"]) + self.assertListKeyBegin( + self.repo.get_network_events(), + lambda e: e.type, + [ + "DownloadEvent", + "DownloadEvent", + "PushEvent", + "IssuesEvent", + "MemberEvent", + ], + ) def testGetTeams(self): repo = self.g.get_organization("BeaverSoftware").get_repo("FatherBeaver") self.assertListKeyEqual(repo.get_teams(), lambda t: t.name, ["Members"]) def testGetWatchers(self): - self.assertListKeyEqual(self.repo.get_watchers(), lambda u: u.login, ["Stals", "att14", "jardon-u", "huxley", "mikofski", "L42y", "fanzeyi", "abersager", "waylan", "adericbourg", "tallforasmurf", "pvicente", "roskakori", "michaelpedersen", "BeaverSoftware"]) + self.assertListKeyEqual( + self.repo.get_watchers(), + lambda u: u.login, + [ + "Stals", + "att14", + "jardon-u", + "huxley", + "mikofski", + "L42y", + "fanzeyi", + "abersager", + "waylan", + "adericbourg", + "tallforasmurf", + "pvicente", + "roskakori", + "michaelpedersen", + "BeaverSoftware", + ], + ) def testGetSourceImport(self): import_repo = self.g.get_user("brix4dayz").get_repo("source-import-test") source_import = import_repo.get_source_import() self.assertEqual(source_import.authors_count, 1) - self.assertEqual(source_import.authors_url, "https://api.github.com/repos/brix4dayz/source-import-test/import/authors") + self.assertEqual( + source_import.authors_url, + "https://api.github.com/repos/brix4dayz/source-import-test/import/authors", + ) self.assertEqual(source_import.has_large_files, False) - self.assertEqual(source_import.html_url, "https://github.com/brix4dayz/source-import-test/import") + self.assertEqual( + source_import.html_url, + "https://github.com/brix4dayz/source-import-test/import", + ) self.assertEqual(source_import.large_files_count, 0) self.assertEqual(source_import.large_files_size, 0) - self.assertEqual(source_import.repository_url, "https://api.github.com/repos/brix4dayz/source-import-test") + self.assertEqual( + source_import.repository_url, + "https://api.github.com/repos/brix4dayz/source-import-test", + ) self.assertEqual(source_import.status, "complete") self.assertEqual(source_import.status_text, "Done") - self.assertEqual(source_import.url, "https://api.github.com/repos/brix4dayz/source-import-test/import") + self.assertEqual( + source_import.url, + "https://api.github.com/repos/brix4dayz/source-import-test/import", + ) self.assertEqual(source_import.use_lfs, "undecided") self.assertEqual(source_import.vcs, "mercurial") - self.assertEqual(source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test") + self.assertEqual( + source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test" + ) def testGetStargazers(self): - self.assertListKeyEqual(self.repo.get_stargazers(), lambda u: u.login, ["Stals", "att14", "jardon-u", "huxley", "mikofski", "L42y", "fanzeyi", "abersager", "waylan", "adericbourg", "tallforasmurf", "pvicente", "roskakori", "michaelpedersen", "stefanfoulis", "equus12", "JuRogn", "joshmoore", "jsilter", "dasapich", "ritratt", "hcilab", "vxnick", "pmuilu", "herlo", "malexw", "ahmetvurgun", "PengGu", "cosmin", "Swop", "kennethreitz", "bryandyck", "jason2506", "zsiciarz", "waawal", "gregorynicholas", "sente", "richmiller55", "thouis", "mazubieta", "michaelhood", "engie", "jtriley", "oangeor", "coryking", "noddi", "alejo8591", "omab", "Carreau", "bilderbuchi", "schwa", "rlerallut", "PengHub", "zoek1", "xobb1t", "notgary", "hattya", "ZebtinRis", "aaronhall", "youngsterxyf", "ailling", "gregwjacobs", "n0rmrx", "awylie", "firstthumb", "joshbrand", "berndca"]) + self.assertListKeyEqual( + self.repo.get_stargazers(), + lambda u: u.login, + [ + "Stals", + "att14", + "jardon-u", + "huxley", + "mikofski", + "L42y", + "fanzeyi", + "abersager", + "waylan", + "adericbourg", + "tallforasmurf", + "pvicente", + "roskakori", + "michaelpedersen", + "stefanfoulis", + "equus12", + "JuRogn", + "joshmoore", + "jsilter", + "dasapich", + "ritratt", + "hcilab", + "vxnick", + "pmuilu", + "herlo", + "malexw", + "ahmetvurgun", + "PengGu", + "cosmin", + "Swop", + "kennethreitz", + "bryandyck", + "jason2506", + "zsiciarz", + "waawal", + "gregorynicholas", + "sente", + "richmiller55", + "thouis", + "mazubieta", + "michaelhood", + "engie", + "jtriley", + "oangeor", + "coryking", + "noddi", + "alejo8591", + "omab", + "Carreau", + "bilderbuchi", + "schwa", + "rlerallut", + "PengHub", + "zoek1", + "xobb1t", + "notgary", + "hattya", + "ZebtinRis", + "aaronhall", + "youngsterxyf", + "ailling", + "gregwjacobs", + "n0rmrx", + "awylie", + "firstthumb", + "joshbrand", + "berndca", + ], + ) def testGetStargazersWithDates(self): repo = self.g.get_user("danvk").get_repo("comparea") @@ -469,36 +1040,64 @@ class Repository(Framework.TestCase): repo.get_stargazers_with_dates(), lambda stargazer: (stargazer.starred_at, stargazer.user.login), [ - (datetime.datetime(2014, 8, 13, 19, 22, 5), u'sAlexander'), - (datetime.datetime(2014, 10, 15, 5, 2, 30), u'ThomasG77'), - (datetime.datetime(2015, 4, 14, 15, 22, 40), u'therusek'), - (datetime.datetime(2015, 4, 29, 0, 9, 40), u'athomann'), - (datetime.datetime(2015, 4, 29, 14, 26, 46), u'jcapron'), - (datetime.datetime(2015, 5, 9, 19, 14, 45), u'JoePython1') - ] + (datetime.datetime(2014, 8, 13, 19, 22, 5), u"sAlexander"), + (datetime.datetime(2014, 10, 15, 5, 2, 30), u"ThomasG77"), + (datetime.datetime(2015, 4, 14, 15, 22, 40), u"therusek"), + (datetime.datetime(2015, 4, 29, 0, 9, 40), u"athomann"), + (datetime.datetime(2015, 4, 29, 14, 26, 46), u"jcapron"), + (datetime.datetime(2015, 5, 9, 19, 14, 45), u"JoePython1"), + ], ) def testGetSubscribers(self): - self.assertListKeyEqual(self.repo.get_subscribers(), lambda u: u.login, ["jacquev6", "equus12", "bilderbuchi", "hcilab", "hattya", "firstthumb", "gregwjacobs", "sagarsane", "liang456", "berndca", "Lyloa"]) + self.assertListKeyEqual( + self.repo.get_subscribers(), + lambda u: u.login, + [ + "jacquev6", + "equus12", + "bilderbuchi", + "hcilab", + "hattya", + "firstthumb", + "gregwjacobs", + "sagarsane", + "liang456", + "berndca", + "Lyloa", + ], + ) def testCreatePull(self): - pull = self.repo.create_pull("Pull request created by PyGithub", "Body of the pull request", "topic/RewriteWithGeneratedCode", "BeaverSoftware:master", True) + pull = self.repo.create_pull( + "Pull request created by PyGithub", + "Body of the pull request", + "topic/RewriteWithGeneratedCode", + "BeaverSoftware:master", + True, + ) self.assertEqual(pull.id, 1436215) def testCreateProject(self): - project = self.repo.create_project("Project created by PyGithub", "Body of the project") + project = self.repo.create_project( + "Project created by PyGithub", "Body of the project" + ) self.assertEqual(project.id, 2013820) def testCreatePullFromIssue(self): issue = self.repo.get_issue(32) - pull = self.repo.create_pull(issue, "topic/RewriteWithGeneratedCode", "BeaverSoftware:master") + pull = self.repo.create_pull( + issue, "topic/RewriteWithGeneratedCode", "BeaverSoftware:master" + ) self.assertEqual(pull.id, 1436310) def testGetPulls(self): self.assertListKeyEqual(self.repo.get_pulls(), lambda p: p.id, [1436310]) def testGetPullsWithArguments(self): - self.assertListKeyEqual(self.repo.get_pulls("closed"), lambda p: p.id, [1448168, 1436310, 1436215]) + self.assertListKeyEqual( + self.repo.get_pulls("closed"), lambda p: p.id, [1448168, 1436310, 1436215] + ) def testLegacySearchIssues(self): issues = self.repo.legacy_search_issues("open", "search") @@ -506,14 +1105,20 @@ 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)) + self.assertEqual( + issues[0].created_at, datetime.datetime(2012, 6, 21, 12, 27, 38) + ) self.assertEqual(issues[0].comments, 4) - self.assertEqual(issues[0].body[: 20], "New API ported from ") + 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)) + self.assertEqual( + issues[0].updated_at, datetime.datetime(2012, 6, 28, 21, 13, 25) + ) self.assertEqual(issues[0].user.login, "kukuts") self.assertEqual(issues[0].user.url, "/users/kukuts") - self.assertListKeyEqual(issues[0].labels, lambda l: l.name, ["Functionalities", "RequestedByUser"]) + self.assertListKeyEqual( + issues[0].labels, lambda l: l.name, ["Functionalities", "RequestedByUser"] + ) self.assertEqual(issues[0].state, "open") def testMarkNotificationsAsRead(self): @@ -527,13 +1132,17 @@ class Repository(Framework.TestCase): self.assertFalse(self.repo.has_in_assignees(lyloa)) self.repo.add_to_collaborators(lyloa) self.assertTrue(self.repo.has_in_assignees(lyloa)) - self.assertListKeyEqual(self.repo.get_assignees(), lambda u: u.login, ["jacquev6", "Lyloa"]) + self.assertListKeyEqual( + self.repo.get_assignees(), lambda u: u.login, ["jacquev6", "Lyloa"] + ) self.repo.remove_from_collaborators(lyloa) self.assertFalse(self.repo.has_in_assignees(lyloa)) def testGetContents(self): self.assertEqual(len(self.repo.get_readme().content), 10212) - self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md").content), 38121) + self.assertEqual( + len(self.repo.get_contents("doc/ReferenceOfClasses.md").content), 38121 + ) def testGetContentsDir(self): contents = self.repo.get_contents("") @@ -546,36 +1155,85 @@ class Repository(Framework.TestCase): self.assertEqual(len(contents), 14) def testGetContentsWithRef(self): - self.assertEqual(len(self.repo.get_readme(ref="refs/heads/topic/ExperimentOnDocumentation").content), 6747) - self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md", ref="refs/heads/topic/ExperimentOnDocumentation").content), 43929) + self.assertEqual( + len( + self.repo.get_readme( + ref="refs/heads/topic/ExperimentOnDocumentation" + ).content + ), + 6747, + ) + self.assertEqual( + len( + self.repo.get_contents( + "doc/ReferenceOfClasses.md", + ref="refs/heads/topic/ExperimentOnDocumentation", + ).content + ), + 43929, + ) def testCreateFile(self): - newFile = 'doc/testCreateUpdateDeleteFile.md' - content = 'Hello world'.encode() + newFile = "doc/testCreateUpdateDeleteFile.md" + content = "Hello world".encode() self.repo.create_file( - path=newFile, message='Create file for testCreateFile', content=content, - branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"), - author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00")) + path=newFile, + message="Create file for testCreateFile", + content=content, + branch="master", + committer=github.InputGitAuthor( + "Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00" + ), + author=github.InputGitAuthor( + "Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00" + ), + ) def testUpdateFile(self): - updateFile = 'doc/testCreateUpdateDeleteFile.md' - content = 'Hello World' + updateFile = "doc/testCreateUpdateDeleteFile.md" + content = "Hello World" sha = self.repo.get_contents(updateFile).sha self.repo.update_file( - path=updateFile, message='Update file for testUpdateFile', content=content, sha=sha, - branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"), - author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00")) + path=updateFile, + message="Update file for testUpdateFile", + content=content, + sha=sha, + branch="master", + committer=github.InputGitAuthor( + "Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00" + ), + author=github.InputGitAuthor( + "Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00" + ), + ) def testDeleteFile(self): - deleteFile = 'doc/testCreateUpdateDeleteFile.md' + deleteFile = "doc/testCreateUpdateDeleteFile.md" sha = self.repo.get_contents(deleteFile).sha - self.repo.delete_file(path=deleteFile, message='Delete file for testDeleteFile', sha=sha, branch="master") + self.repo.delete_file( + path=deleteFile, + message="Delete file for testDeleteFile", + sha=sha, + branch="master", + ) def testGetArchiveLink(self): - self.assertEqual(self.repo.get_archive_link("tarball"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/master") - self.assertEqual(self.repo.get_archive_link("zipball"), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master") - self.assertEqual(self.repo.get_archive_link("zipball", "master"), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master") - self.assertEqual(self.repo.get_archive_link("tarball", "develop"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/develop") + self.assertEqual( + self.repo.get_archive_link("tarball"), + "https://nodeload.github.com/jacquev6/PyGithub/tarball/master", + ) + self.assertEqual( + self.repo.get_archive_link("zipball"), + "https://nodeload.github.com/jacquev6/PyGithub/zipball/master", + ) + self.assertEqual( + self.repo.get_archive_link("zipball", "master"), + "https://nodeload.github.com/jacquev6/PyGithub/zipball/master", + ) + self.assertEqual( + self.repo.get_archive_link("tarball", "develop"), + "https://nodeload.github.com/jacquev6/PyGithub/tarball/develop", + ) def testGetBranch(self): branch = self.repo.get_branch("develop") @@ -583,14 +1241,20 @@ class Repository(Framework.TestCase): def testMergeWithoutMessage(self): commit = self.repo.merge("branchForBase", "branchForHead") - self.assertEqual(commit.commit.message, "Merge branchForHead into branchForBase") + self.assertEqual( + commit.commit.message, "Merge branchForHead into branchForBase" + ) def testMergeWithMessage(self): - commit = self.repo.merge("branchForBase", "branchForHead", "Commit message created by PyGithub") + commit = self.repo.merge( + "branchForBase", "branchForHead", "Commit message created by PyGithub" + ) self.assertEqual(commit.commit.message, "Commit message created by PyGithub") def testMergeWithNothingToDo(self): - commit = self.repo.merge("branchForBase", "branchForHead", "Commit message created by PyGithub") + commit = self.repo.merge( + "branchForBase", "branchForHead", "Commit message created by PyGithub" + ) self.assertEqual(commit, None) def testMergeWithConflict(self): @@ -600,23 +1264,176 @@ class Repository(Framework.TestCase): self.assertEqual(raisedexp.exception.data, {"message": "Merge conflict"}) def testGetIssuesComments(self): - self.assertListKeyEqual(self.repo.get_issues_comments()[:40], lambda c: c.id, [5168757, 5181640, 5183010, 5186061, 5226090, 5449237, 5518272, 5547576, 5780183, 5781803, 5820199, 5820912, 5924198, 5965724, 5965812, 5965891, 5966555, 5966633, 5981084, 5981232, 5981409, 5981451, 5991965, 6019700, 6088432, 6293572, 6305625, 6357374, 6357422, 6447481, 6467193, 6467312, 6467642, 6481200, 6481392, 6556134, 6557261, 6568164, 6568181, 6568553]) - self.assertListKeyEqual(self.repo.get_issues_comments(sort="created", direction="asc")[:40], lambda c: c.id, [5168757, 5181640, 5183010, 5186061, 5226090, 5449237, 5518272, 5547576, 5780183, 5781803, 5820199, 5820912, 5924198, 5965724, 5965812, 5965891, 5966555, 5966633, 5981084, 5981232, 5981409, 5981451, 5991965, 6019700, 6088432, 6293572, 6305625, 6357374, 6357422, 6447481, 6467193, 6467312, 6467642, 6481200, 6481392, 6556134, 6557261, 6568164, 6568181, 6568553]) - self.assertListKeyEqual(self.repo.get_issues_comments(since=datetime.datetime(2012, 5, 28, 23, 0, 0))[:40], lambda c: c.id, [5981084, 5981232, 5981409, 5981451, 5991965, 6019700, 6088432, 6293572, 6305625, 6357374, 6357422, 6447481, 6467193, 6467312, 6467642, 6481200, 6481392, 6556134, 6557261, 6568164, 6568181, 6568553, 6640187, 6640189, 6641223, 6673380, 6710355, 6727553, 6727659, 6727848, 6728069, 6728241, 6728370, 6886561, 6972414, 6994436, 7060818, 7060993, 7211543, 7407798]) + self.assertListKeyEqual( + self.repo.get_issues_comments()[:40], + lambda c: c.id, + [ + 5168757, + 5181640, + 5183010, + 5186061, + 5226090, + 5449237, + 5518272, + 5547576, + 5780183, + 5781803, + 5820199, + 5820912, + 5924198, + 5965724, + 5965812, + 5965891, + 5966555, + 5966633, + 5981084, + 5981232, + 5981409, + 5981451, + 5991965, + 6019700, + 6088432, + 6293572, + 6305625, + 6357374, + 6357422, + 6447481, + 6467193, + 6467312, + 6467642, + 6481200, + 6481392, + 6556134, + 6557261, + 6568164, + 6568181, + 6568553, + ], + ) + self.assertListKeyEqual( + self.repo.get_issues_comments(sort="created", direction="asc")[:40], + lambda c: c.id, + [ + 5168757, + 5181640, + 5183010, + 5186061, + 5226090, + 5449237, + 5518272, + 5547576, + 5780183, + 5781803, + 5820199, + 5820912, + 5924198, + 5965724, + 5965812, + 5965891, + 5966555, + 5966633, + 5981084, + 5981232, + 5981409, + 5981451, + 5991965, + 6019700, + 6088432, + 6293572, + 6305625, + 6357374, + 6357422, + 6447481, + 6467193, + 6467312, + 6467642, + 6481200, + 6481392, + 6556134, + 6557261, + 6568164, + 6568181, + 6568553, + ], + ) + self.assertListKeyEqual( + self.repo.get_issues_comments( + since=datetime.datetime(2012, 5, 28, 23, 0, 0) + )[:40], + lambda c: c.id, + [ + 5981084, + 5981232, + 5981409, + 5981451, + 5991965, + 6019700, + 6088432, + 6293572, + 6305625, + 6357374, + 6357422, + 6447481, + 6467193, + 6467312, + 6467642, + 6481200, + 6481392, + 6556134, + 6557261, + 6568164, + 6568181, + 6568553, + 6640187, + 6640189, + 6641223, + 6673380, + 6710355, + 6727553, + 6727659, + 6727848, + 6728069, + 6728241, + 6728370, + 6886561, + 6972414, + 6994436, + 7060818, + 7060993, + 7211543, + 7407798, + ], + ) def testGetPullsComments(self): - self.assertListKeyEqual(self.repo.get_pulls_comments(), lambda c: c.id, [1580134]) - self.assertListKeyEqual(self.repo.get_pulls_comments(sort="created", direction="asc"), lambda c: c.id, [1580134]) - self.assertListKeyEqual(self.repo.get_pulls_comments(since=datetime.datetime(2012, 5, 28, 23, 0, 0)), lambda c: c.id, [1580134]) + self.assertListKeyEqual( + self.repo.get_pulls_comments(), lambda c: c.id, [1580134] + ) + self.assertListKeyEqual( + self.repo.get_pulls_comments(sort="created", direction="asc"), + lambda c: c.id, + [1580134], + ) + self.assertListKeyEqual( + self.repo.get_pulls_comments( + since=datetime.datetime(2012, 5, 28, 23, 0, 0) + ), + lambda c: c.id, + [1580134], + ) def testSubscribePubSubHubbub(self): self.repo.subscribe_to_hub("push", "http://requestb.in/1bc1sc61", "my_secret") def testBadSubscribePubSubHubbub(self): with self.assertRaises(github.GithubException) as raisedexp: - self.repo.subscribe_to_hub("non-existing-event", "http://requestb.in/1bc1sc61") + self.repo.subscribe_to_hub( + "non-existing-event", "http://requestb.in/1bc1sc61" + ) self.assertEqual(raisedexp.exception.status, 422) - self.assertEqual(raisedexp.exception.data, {"message": "Invalid event: \"non-existing-event\""}) + self.assertEqual( + raisedexp.exception.data, {"message": 'Invalid event: "non-existing-event"'} + ) def testUnsubscribePubSubHubbub(self): self.repo.unsubscribe_from_hub("push", "http://requestb.in/1bc1sc61") @@ -648,8 +1465,120 @@ class Repository(Framework.TestCase): self.assertEqual(stats[0].deletions, -2098) stats = self.repo.get_stats_participation() - self.assertEqual(stats.owner, [1, 36, 8, 0, 0, 8, 18, 0, 0, 0, 0, 7, 20, 6, 9, 0, 4, 11, 20, 16, 0, 3, 0, 16, 0, 0, 6, 1, 4, 0, 1, 6, 0, 0, 12, 10, 0, 0, 0, 1, 44, 0, 20, 10, 0, 0, 0, 0, 0, 10, 0, 0]) - self.assertEqual(stats.all, [4, 36, 8, 0, 0, 10, 20, 0, 0, 0, 0, 11, 20, 6, 9, 0, 4, 14, 21, 16, 0, 3, 0, 20, 0, 0, 8, 1, 9, 16, 1, 15, 1, 0, 12, 12, 0, 4, 6, 15, 116, 20, 20, 11, 0, 0, 0, 0, 0, 10, 0, 0]) + self.assertEqual( + stats.owner, + [ + 1, + 36, + 8, + 0, + 0, + 8, + 18, + 0, + 0, + 0, + 0, + 7, + 20, + 6, + 9, + 0, + 4, + 11, + 20, + 16, + 0, + 3, + 0, + 16, + 0, + 0, + 6, + 1, + 4, + 0, + 1, + 6, + 0, + 0, + 12, + 10, + 0, + 0, + 0, + 1, + 44, + 0, + 20, + 10, + 0, + 0, + 0, + 0, + 0, + 10, + 0, + 0, + ], + ) + self.assertEqual( + stats.all, + [ + 4, + 36, + 8, + 0, + 0, + 10, + 20, + 0, + 0, + 0, + 0, + 11, + 20, + 6, + 9, + 0, + 4, + 14, + 21, + 16, + 0, + 3, + 0, + 20, + 0, + 0, + 8, + 1, + 9, + 16, + 1, + 15, + 1, + 0, + 12, + 12, + 0, + 4, + 6, + 15, + 116, + 20, + 20, + 11, + 0, + 0, + 0, + 0, + 0, + 10, + 0, + 0, + ], + ) stats = self.repo.get_stats_punch_card() self.assertEqual(stats.get(4, 12), 7) @@ -660,23 +1589,22 @@ class Repository(Framework.TestCase): def testGetTopics(self): topic_list = self.repo.get_topics() - topic = u'github' + topic = u"github" self.assertIn(topic, topic_list) def testReplaceTopics(self): - self.repo.replace_topics(['github', 'testing']) + self.repo.replace_topics(["github", "testing"]) def testGetRepositoryWith301Redirect(self): repo = self.g.get_repo("protoncoin/protoncoin") - self.assertEqual(repo.full_name, 'padima2/protoncoin') + self.assertEqual(repo.full_name, "padima2/protoncoin") class LazyRepository(Framework.TestCase): - def setUp(self): Framework.TestCase.setUp(self) self.user = self.g.get_user() - self.repository_name = '%s/%s' % (self.user.login, "PyGithub") + self.repository_name = "%s/%s" % (self.user.login, "PyGithub") def getLazyRepository(self): return self.g.get_repo(self.repository_name, lazy=True) diff --git a/tests/RepositoryKey.py b/tests/RepositoryKey.py index 866c1c1d..96a0f1b6 100644 --- a/tests/RepositoryKey.py +++ b/tests/RepositoryKey.py @@ -32,10 +32,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class RepositoryKey(Framework.TestCase): def setUp(self): @@ -46,14 +47,21 @@ class RepositoryKey(Framework.TestCase): def testAttributes(self): self.assertEqual(self.key.id, 21870881) - self.assertEqual(self.key.key, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLOoLSVPwG1OSgVSeEXNbfIofYdxR5zs3u4PryhnamfFPYwi2vZW3ZxeI1oRcDh2VEdwGvlN5VUduKJNoOWMVzV2jSyR8CeDHH+I0soQCC7kfJVodU96HcPMzZ6MuVwSfD4BFGvKMXyCnBUqzo28BGHFwVQG8Ya9gL6/cTbuWywgM4xaJgMHv1OVcESXBtBkrqOneTJuOgeEmP0RfUnIAK/3/wbg9mfiBq7JV4cmWAg1xNE8GJoAbci59Tdx1dQgVuuqdQGk5jzNusOVneyMtGEB+p7UpPLJsGBW29rsMt7ITUbXM/kl9v11vPtWb+oOUThoFsDYmsWy7fGGP9YAFB") + self.assertEqual( + self.key.key, + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLOoLSVPwG1OSgVSeEXNbfIofYdxR5zs3u4PryhnamfFPYwi2vZW3ZxeI1oRcDh2VEdwGvlN5VUduKJNoOWMVzV2jSyR8CeDHH+I0soQCC7kfJVodU96HcPMzZ6MuVwSfD4BFGvKMXyCnBUqzo28BGHFwVQG8Ya9gL6/cTbuWywgM4xaJgMHv1OVcESXBtBkrqOneTJuOgeEmP0RfUnIAK/3/wbg9mfiBq7JV4cmWAg1xNE8GJoAbci59Tdx1dQgVuuqdQGk5jzNusOVneyMtGEB+p7UpPLJsGBW29rsMt7ITUbXM/kl9v11vPtWb+oOUThoFsDYmsWy7fGGP9YAFB", + ) self.assertEqual(self.key.title, "PyGithub Test Key") - self.assertEqual(self.key.url, "https://api.github.com/repos/lra/mackup/keys/21870881") + 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.assertTrue(self.key.verified) # test __repr__() based on this attributes - self.assertEqual(self.key.__repr__(), 'RepositoryKey(title="PyGithub Test Key", id=21870881)') + self.assertEqual( + self.key.__repr__(), 'RepositoryKey(title="PyGithub Test Key", id=21870881)' + ) def testDelete(self): self.key.delete() diff --git a/tests/RequiredPullRequestReviews.py b/tests/RequiredPullRequestReviews.py index 501be3b4..d69c5185 100644 --- a/tests/RequiredPullRequestReviews.py +++ b/tests/RequiredPullRequestReviews.py @@ -23,24 +23,50 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class RequiredPullRequestReviews(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.required_pull_request_reviews = self.g.get_user().get_repo("PyGithub").get_branch("integrations").get_required_pull_request_reviews() + self.required_pull_request_reviews = ( + self.g.get_user() + .get_repo("PyGithub") + .get_branch("integrations") + .get_required_pull_request_reviews() + ) def testAttributes(self): self.assertTrue(self.required_pull_request_reviews.dismiss_stale_reviews) self.assertTrue(self.required_pull_request_reviews.require_code_owner_reviews) - self.assertEqual(self.required_pull_request_reviews.required_approving_review_count, 3) - self.assertEqual(self.required_pull_request_reviews.url, "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews") + self.assertEqual( + self.required_pull_request_reviews.required_approving_review_count, 3 + ) + self.assertEqual( + self.required_pull_request_reviews.url, + "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews", + ) self.assertIs(self.required_pull_request_reviews.dismissal_users, None) self.assertIs(self.required_pull_request_reviews.dismissal_teams, None) - self.assertEqual(self.required_pull_request_reviews.__repr__(), 'RequiredPullRequestReviews(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews", require_code_owner_reviews=True, dismiss_stale_reviews=True)') + self.assertEqual( + self.required_pull_request_reviews.__repr__(), + 'RequiredPullRequestReviews(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews", require_code_owner_reviews=True, dismiss_stale_reviews=True)', + ) def testOrganizationOwnedTeam(self): - required_pull_request_reviews = self.g.get_repo("PyGithub/PyGithub", lazy=True).get_branch("integrations").get_required_pull_request_reviews() - self.assertListKeyEqual(required_pull_request_reviews.dismissal_users, lambda u: u.login, ["jacquev6"]) - self.assertListKeyEqual(required_pull_request_reviews.dismissal_teams, lambda t: t.slug, ["pygithub-owners"]) + required_pull_request_reviews = ( + self.g.get_repo("PyGithub/PyGithub", lazy=True) + .get_branch("integrations") + .get_required_pull_request_reviews() + ) + self.assertListKeyEqual( + required_pull_request_reviews.dismissal_users, + lambda u: u.login, + ["jacquev6"], + ) + self.assertListKeyEqual( + required_pull_request_reviews.dismissal_teams, + lambda t: t.slug, + ["pygithub-owners"], + ) diff --git a/tests/RequiredStatusChecks.py b/tests/RequiredStatusChecks.py index 47a3141e..07f3b163 100644 --- a/tests/RequiredStatusChecks.py +++ b/tests/RequiredStatusChecks.py @@ -23,16 +23,28 @@ ################################################################################ from __future__ import absolute_import + from . import Framework class RequiredStatusChecks(Framework.TestCase): def setUp(self): Framework.TestCase.setUp(self) - self.required_status_checks = self.g.get_user().get_repo("PyGithub").get_branch("integrations").get_required_status_checks() + self.required_status_checks = ( + self.g.get_user() + .get_repo("PyGithub") + .get_branch("integrations") + .get_required_status_checks() + ) def testAttributes(self): self.assertTrue(self.required_status_checks.strict) self.assertEqual(self.required_status_checks.contexts, ["foo/bar"]) - self.assertEqual(self.required_status_checks.url, "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_status_checks") - self.assertEqual(self.required_status_checks.__repr__(), 'RequiredStatusChecks(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_status_checks", strict=True)') + self.assertEqual( + self.required_status_checks.url, + "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_status_checks", + ) + self.assertEqual( + self.required_status_checks.__repr__(), + 'RequiredStatusChecks(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_status_checks", strict=True)', + ) diff --git a/tests/Retry.py b/tests/Retry.py index 5ba6314a..dfd945b5 100644 --- a/tests/Retry.py +++ b/tests/Retry.py @@ -25,17 +25,17 @@ # along with PyGithub. If not, see . # # # ################################################################################ + from __future__ import absolute_import + +import github +import requests import urllib3 from httpretty import httpretty from . import Framework -import requests - -import github - -REPO_NAME = 'PyGithub/PyGithub' +REPO_NAME = "PyGithub/PyGithub" class Retry(Framework.TestCase): @@ -43,10 +43,7 @@ class Retry(Framework.TestCase): # status codes returned on random github server errors status_forcelist = (500, 502, 504) retry = urllib3.Retry( - total=3, - read=3, - connect=3, - status_forcelist=status_forcelist + total=3, read=3, connect=3, status_forcelist=status_forcelist ) Framework.enableRetry(retry) @@ -61,7 +58,7 @@ class Retry(Framework.TestCase): repository = self.g.get_repo(REPO_NAME) self.assertEqual(len(httpretty.latest_requests), 4) for request in httpretty.latest_requests: - self.assertEqual(request.path, '/repos/' + REPO_NAME) + self.assertEqual(request.path, "/repos/" + REPO_NAME) self.assertIsInstance(repository, github.Repository.Repository) self.assertEqual(repository.full_name, REPO_NAME) @@ -70,14 +67,14 @@ class Retry(Framework.TestCase): repository = self.g.get_repo(REPO_NAME) self.assertEqual(len(httpretty.latest_requests), 2) for request in httpretty.latest_requests: - self.assertEqual(request.path, '/repos/' + REPO_NAME) + self.assertEqual(request.path, "/repos/" + REPO_NAME) self.assertIsInstance(repository, github.Repository.Repository) self.assertEqual(repository.full_name, REPO_NAME) def testRaisesRetryErrorAfterMaxRetries(self): with self.assertRaises(requests.exceptions.RetryError): - self.g.get_repo('PyGithub/PyGithub') + self.g.get_repo("PyGithub/PyGithub") self.assertEqual(len(httpretty.latest_requests), 4) for request in httpretty.latest_requests: - self.assertEqual(request.path, '/repos/PyGithub/PyGithub') + self.assertEqual(request.path, "/repos/PyGithub/PyGithub") diff --git a/tests/Search.py b/tests/Search.py index c7b0d1ca..cdc74929 100644 --- a/tests/Search.py +++ b/tests/Search.py @@ -27,6 +27,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -40,32 +41,171 @@ class Search(Framework.TestCase): def testPaginateSearchUsers(self): users = self.g.search_users("", location="Berlin") - self.assertListKeyBegin(users, lambda u: u.login, [u'cloudhead', u'felixge', u'sferik', u'rkh', u'jezdez', u'janl', u'marijnh', u'nikic', u'igorw', u'froschi', u'svenfuchs', u'omz', u'chad', u'bergie', u'roidrage', u'pcalcado', u'durran', u'hukl', u'mttkay', u'aFarkas', u'ole', u'hagenburger', u'jberkel', u'naderman', u'joshk', u'pudo', u'robb', u'josephwilk', u'hanshuebner', u'txus', u'paulasmuth', u'splitbrain', u'langalex', u'bendiken', u'stefanw']) + self.assertListKeyBegin( + users, + lambda u: u.login, + [ + u"cloudhead", + u"felixge", + u"sferik", + u"rkh", + u"jezdez", + u"janl", + u"marijnh", + u"nikic", + u"igorw", + u"froschi", + u"svenfuchs", + u"omz", + u"chad", + u"bergie", + u"roidrage", + u"pcalcado", + u"durran", + u"hukl", + u"mttkay", + u"aFarkas", + u"ole", + u"hagenburger", + u"jberkel", + u"naderman", + u"joshk", + u"pudo", + u"robb", + u"josephwilk", + u"hanshuebner", + u"txus", + u"paulasmuth", + u"splitbrain", + u"langalex", + u"bendiken", + u"stefanw", + ], + ) self.assertEqual(users.totalCount, 6038) def testGetPageOnSearchUsers(self): users = self.g.search_users("", location="Berlin") - self.assertEqual([u.login for u in users.get_page(7)], [u'ursachec', u'bitboxer', u'fs111', u'michenriksen', u'witsch', u'booo', u'mortice', u'r0man', u'MikeBild', u'mhagger', u'bkw', u'fwbrasil', u'mschneider', u'lydiapintscher', u'asksven', u'iamtimm', u'sneak', u'kr1sp1n', u'Feh', u'GordonLesti', u'annismckenzie', u'eskimoblood', u'tsujigiri', u'riethmayer', u'lauritzthamsen', u'scotchi', u'peritor', u'toto', u'hwaxxer', u'lukaszklis']) + self.assertEqual( + [u.login for u in users.get_page(7)], + [ + u"ursachec", + u"bitboxer", + u"fs111", + u"michenriksen", + u"witsch", + u"booo", + u"mortice", + u"r0man", + u"MikeBild", + u"mhagger", + u"bkw", + u"fwbrasil", + u"mschneider", + u"lydiapintscher", + u"asksven", + u"iamtimm", + u"sneak", + u"kr1sp1n", + u"Feh", + u"GordonLesti", + u"annismckenzie", + u"eskimoblood", + u"tsujigiri", + u"riethmayer", + u"lauritzthamsen", + u"scotchi", + u"peritor", + u"toto", + u"hwaxxer", + u"lukaszklis", + ], + ) def testSearchRepos(self): - repos = self.g.search_repositories("github", sort="stars", order="desc", language="Python") - self.assertListKeyBegin(repos, lambda r: r.full_name, [u'kennethreitz/legit', u'RuudBurger/CouchPotatoV1', u'gelstudios/gitfiti', u'gpjt/webgl-lessons', u'jacquev6/PyGithub', u'aaasen/github_globe', u'hmason/gitmarks', u'dnerdy/factory_boy', u'binaryage/drydrop', u'bgreenlee/sublime-github', u'karan/HackerNewsAPI', u'mfenniak/pyPdf', u'skazhy/github-decorator', u'llvmpy/llvmpy', u'lexrupy/gmate', u'ask/python-github2', u'audreyr/cookiecutter-pypackage', u'tabo/django-treebeard', u'dbr/tvdb_api', u'jchris/couchapp', u'joeyespo/grip', u'nigelsmall/py2neo', u'ask/chishop', u'sigmavirus24/github3.py', u'jsmits/github-cli', u'lincolnloop/django-layout', u'amccloud/django-project-skel', u'Stiivi/brewery', u'webpy/webpy.github.com', u'dustin/py-github', u'logsol/Github-Auto-Deploy', u'cloudkick/libcloud', u'berkerpeksag/github-badge', u'bitprophet/ssh', u'azavea/OpenTreeMap']) + repos = self.g.search_repositories( + "github", sort="stars", order="desc", language="Python" + ) + self.assertListKeyBegin( + repos, + lambda r: r.full_name, + [ + u"kennethreitz/legit", + u"RuudBurger/CouchPotatoV1", + u"gelstudios/gitfiti", + u"gpjt/webgl-lessons", + u"jacquev6/PyGithub", + u"aaasen/github_globe", + u"hmason/gitmarks", + u"dnerdy/factory_boy", + u"binaryage/drydrop", + u"bgreenlee/sublime-github", + u"karan/HackerNewsAPI", + u"mfenniak/pyPdf", + u"skazhy/github-decorator", + u"llvmpy/llvmpy", + u"lexrupy/gmate", + u"ask/python-github2", + u"audreyr/cookiecutter-pypackage", + u"tabo/django-treebeard", + u"dbr/tvdb_api", + u"jchris/couchapp", + u"joeyespo/grip", + u"nigelsmall/py2neo", + u"ask/chishop", + u"sigmavirus24/github3.py", + u"jsmits/github-cli", + u"lincolnloop/django-layout", + u"amccloud/django-project-skel", + u"Stiivi/brewery", + u"webpy/webpy.github.com", + u"dustin/py-github", + u"logsol/Github-Auto-Deploy", + u"cloudkick/libcloud", + u"berkerpeksag/github-badge", + u"bitprophet/ssh", + u"azavea/OpenTreeMap", + ], + ) def testSearchReposWithNoResults(self): repos = self.g.search_repositories("doesnotexist") self.assertEqual(repos.totalCount, 0) def testSearchIssues(self): - issues = self.g.search_issues("compile", sort="comments", order="desc", language="C++") - self.assertListKeyBegin(issues, lambda i: i.id, [12068673, 23250111, 14371957, 9423897, 24277400, 2408877, 11338741, 13980502, 27697165, 23102422]) + issues = self.g.search_issues( + "compile", sort="comments", order="desc", language="C++" + ) + self.assertListKeyBegin( + issues, + lambda i: i.id, + [ + 12068673, + 23250111, + 14371957, + 9423897, + 24277400, + 2408877, + 11338741, + 13980502, + 27697165, + 23102422, + ], + ) def testPaginateSearchCommits(self): - commits = self.g.search_commits(query="hash:5b0224e868cc9242c9450ef02efbe3097abd7ba2") + commits = self.g.search_commits( + query="hash:5b0224e868cc9242c9450ef02efbe3097abd7ba2" + ) self.assertEqual(commits.totalCount, 3) def testSearchTopics(self): topics = self.g.search_topics("python", repositories=">950") - self.assertListKeyBegin(topics, lambda r: r.name, [u"python", u"django", u"flask", u"ruby", u"scikit-learn", u"wagtail"]) + self.assertListKeyBegin( + topics, + lambda r: r.name, + [u"python", u"django", u"flask", u"ruby", u"scikit-learn", u"wagtail"], + ) def testPaginateSearchTopics(self): repos = self.g.search_topics("python", repositories=">950") @@ -73,23 +213,48 @@ class Search(Framework.TestCase): def testSearchCode(self): files = self.g.search_code("toto", sort="indexed", order="asc", user="jacquev6") - self.assertListKeyEqual(files, lambda f: f.name, [u'Commit.setUp.txt', u'PullRequest.testGetFiles.txt', u'NamedUser.testGetEvents.txt', u'PullRequest.testCreateComment.txt', u'PullRequestFile.setUp.txt', u'Repository.testGetIssuesWithWildcards.txt', u'Repository.testGetIssuesWithArguments.txt', u'test_ebnf.cpp', u'test_abnf.cpp', u'PullRequestFile.py', u'SystemCalls.py', u'tests.py', u'LexerTestCase.py', u'ParserTestCase.py']) + self.assertListKeyEqual( + files, + lambda f: f.name, + [ + u"Commit.setUp.txt", + u"PullRequest.testGetFiles.txt", + u"NamedUser.testGetEvents.txt", + u"PullRequest.testCreateComment.txt", + u"PullRequestFile.setUp.txt", + u"Repository.testGetIssuesWithWildcards.txt", + u"Repository.testGetIssuesWithArguments.txt", + u"test_ebnf.cpp", + u"test_abnf.cpp", + u"PullRequestFile.py", + u"SystemCalls.py", + u"tests.py", + u"LexerTestCase.py", + u"ParserTestCase.py", + ], + ) self.assertEqual(files[0].repository.full_name, "jacquev6/PyGithub") content = files[0].decoded_content if isinstance(content, bytes): - content = content.decode('utf-8') - self.assertEqual(content[:30], 'https\nGET\napi.github.com\nNone\n') + content = content.decode("utf-8") + self.assertEqual(content[:30], "https\nGET\napi.github.com\nNone\n") def testSearchHighlightingCode(self): - files = self.g.search_code("toto", sort="indexed", order="asc", user="jacquev6", highlight=True) + files = self.g.search_code( + "toto", sort="indexed", order="asc", user="jacquev6", highlight=True + ) self.assertTrue(files[0].text_matches) def testUrlquotingOfQualifiers(self): # Example taken from #236 - issues = self.g.search_issues("repo:saltstack/salt-api type:Issues", updated=">2014-03-04T18:28:11Z") + issues = self.g.search_issues( + "repo:saltstack/salt-api type:Issues", updated=">2014-03-04T18:28:11Z" + ) self.assertEqual(issues[0].id, 29138794) def testUrlquotingOfQuery(self): # Example taken from #236 - issues = self.g.search_issues("repo:saltstack/salt-api type:Issues updated:>2014-03-04T18:28:11Z") + issues = self.g.search_issues( + "repo:saltstack/salt-api type:Issues updated:>2014-03-04T18:28:11Z" + ) self.assertEqual(issues[0].id, 29138794) diff --git a/tests/SourceImport.py b/tests/SourceImport.py index 10432091..2a39aace 100644 --- a/tests/SourceImport.py +++ b/tests/SourceImport.py @@ -23,6 +23,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -35,21 +36,37 @@ class SourceImport(Framework.TestCase): def testAttributes(self): self.assertEqual(self.source_import.authors_count, 1) - self.assertEqual(self.source_import.authors_url, "https://api.github.com/repos/brix4dayz/source-import-test/import/authors") + self.assertEqual( + self.source_import.authors_url, + "https://api.github.com/repos/brix4dayz/source-import-test/import/authors", + ) self.assertEqual(self.source_import.has_large_files, False) - self.assertEqual(self.source_import.html_url, "https://github.com/brix4dayz/source-import-test/import") + self.assertEqual( + self.source_import.html_url, + "https://github.com/brix4dayz/source-import-test/import", + ) self.assertEqual(self.source_import.large_files_count, 0) self.assertEqual(self.source_import.large_files_size, 0) - self.assertEqual(self.source_import.repository_url, "https://api.github.com/repos/brix4dayz/source-import-test") + self.assertEqual( + self.source_import.repository_url, + "https://api.github.com/repos/brix4dayz/source-import-test", + ) self.assertEqual(self.source_import.status, "complete") self.assertEqual(self.source_import.status_text, "Done") - self.assertEqual(self.source_import.url, "https://api.github.com/repos/brix4dayz/source-import-test/import") + self.assertEqual( + self.source_import.url, + "https://api.github.com/repos/brix4dayz/source-import-test/import", + ) self.assertEqual(self.source_import.use_lfs, "undecided") self.assertEqual(self.source_import.vcs, "mercurial") - self.assertEqual(self.source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test") + self.assertEqual( + self.source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test" + ) - self.assertEqual(self.source_import.__repr__(), - 'SourceImport(vcs_url="https://bitbucket.org/hfuss/source-import-test", url="https://api.github.com/repos/brix4dayz/source-import-test/import", status="complete", repository_url="https://api.github.com/repos/brix4dayz/source-import-test")') + self.assertEqual( + self.source_import.__repr__(), + 'SourceImport(vcs_url="https://bitbucket.org/hfuss/source-import-test", url="https://api.github.com/repos/brix4dayz/source-import-test/import", status="complete", repository_url="https://api.github.com/repos/brix4dayz/source-import-test")', + ) def testUpdate(self): # The real test is that update() method passes the header diff --git a/tests/Tag.py b/tests/Tag.py index ca0f3ffe..82a4a195 100644 --- a/tests/Tag.py +++ b/tests/Tag.py @@ -29,6 +29,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -38,10 +39,19 @@ class Tag(Framework.TestCase): self.tag = self.g.get_user().get_repo("PyGithub").get_tags()[0] def testAttributes(self): - self.assertEqual(self.tag.commit.sha, "636e6112deb72277b3bffcc3303cd7e8a7431a5d") + self.assertEqual( + self.tag.commit.sha, "636e6112deb72277b3bffcc3303cd7e8a7431a5d" + ) self.assertEqual(self.tag.name, "v0.3") - self.assertEqual(self.tag.tarball_url, "https://github.com/jacquev6/PyGithub/tarball/v0.3") - self.assertEqual(self.tag.zipball_url, "https://github.com/jacquev6/PyGithub/zipball/v0.3") + self.assertEqual( + self.tag.tarball_url, "https://github.com/jacquev6/PyGithub/tarball/v0.3" + ) + self.assertEqual( + self.tag.zipball_url, "https://github.com/jacquev6/PyGithub/zipball/v0.3" + ) # test __repr__() based on this attributes - self.assertEqual(self.tag.__repr__(), 'Tag(name="v0.3", commit=Commit(sha="636e6112deb72277b3bffcc3303cd7e8a7431a5d"))') + self.assertEqual( + self.tag.__repr__(), + 'Tag(name="v0.3", commit=Commit(sha="636e6112deb72277b3bffcc3303cd7e8a7431a5d"))', + ) diff --git a/tests/Team.py b/tests/Team.py index 3ee47f23..83163843 100644 --- a/tests/Team.py +++ b/tests/Team.py @@ -58,7 +58,9 @@ class Team(Framework.TestCase): self.assertEqual(self.team.privacy, "closed") # test __repr__() based on this attributes - self.assertEqual(self.team.__repr__(), 'Team(name="Team created by PyGithub", id=189850)') + self.assertEqual( + self.team.__repr__(), 'Team(name="Team created by PyGithub", id=189850)' + ) def testDiscussions(self): discussions = list(self.team.get_discussions()) @@ -70,9 +72,14 @@ class Team(Framework.TestCase): self.assertEqual(d.body_html, "

BODY

") self.assertEqual(d.body_version, "bedf0740b01d2d758cff9873c2387817") self.assertEqual(d.comments_count, 0) - self.assertEqual(d.comments_url, "https://api.github.com/teams/189850/discussions/1/comments") + 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.html_url, "https://github.com/orgs/BeaverSoftware/teams/Team/discussions/1") + self.assertEqual( + d.html_url, + "https://github.com/orgs/BeaverSoftware/teams/Team/discussions/1", + ) self.assertEqual(d.last_edited_at, None) self.assertEqual(d.node_id, "MDE0OlRlYW1EaXNjdXNzaW9uMzA=") self.assertEqual(d.number, 1) @@ -88,7 +95,9 @@ class Team(Framework.TestCase): self.assertListKeyEqual(self.team.get_members(), None, []) self.assertFalse(self.team.has_in_members(user)) self.team.add_to_members(user) - self.assertListKeyEqual(self.team.get_members(), lambda u: u.login, ["jacquev6"]) + self.assertListKeyEqual( + self.team.get_members(), lambda u: u.login, ["jacquev6"] + ) self.assertTrue(self.team.has_in_members(user)) self.team.remove_from_members(user) self.assertListKeyEqual(self.team.get_members(), None, []) @@ -106,7 +115,9 @@ class Team(Framework.TestCase): self.assertListKeyEqual(self.team.get_repos(), None, []) self.assertFalse(self.team.has_in_repos(repo)) self.team.add_to_repos(repo) - self.assertListKeyEqual(self.team.get_repos(), lambda r: r.name, ["FatherBeaver"]) + self.assertListKeyEqual( + self.team.get_repos(), lambda r: r.name, ["FatherBeaver"] + ) self.assertTrue(self.team.has_in_repos(repo)) self.team.remove_from_repos(repo) self.assertListKeyEqual(self.team.get_repos(), None, []) @@ -117,7 +128,12 @@ class Team(Framework.TestCase): self.assertEqual(self.team.name, "Name edited by PyGithub") def testEditWithAllArguments(self): - self.team.edit("Name edited twice by PyGithub", "Description edited by PyGithub", "admin", "secret") + self.team.edit( + "Name edited twice by PyGithub", + "Description edited by PyGithub", + "admin", + "secret", + ) self.assertEqual(self.team.name, "Name edited twice by PyGithub") self.assertEqual(self.team.description, "Description edited by PyGithub") self.assertEqual(self.team.permission, "admin") diff --git a/tests/Time.py b/tests/Time.py index a63f7986..fd9b9b33 100644 --- a/tests/Time.py +++ b/tests/Time.py @@ -21,6 +21,7 @@ ################################################################################ from __future__ import absolute_import + from datetime import timedelta, tzinfo diff --git a/tests/Topic.py b/tests/Topic.py index 876b04d0..378e5bcb 100644 --- a/tests/Topic.py +++ b/tests/Topic.py @@ -40,8 +40,14 @@ class Topic(Framework.TestCase): self.assertEqual(topic.name, "python") self.assertEqual(topic.display_name, "Python") - self.assertEqual(topic.short_description, "Python is a dynamically typed programming language.") - self.assertEqual(topic.description, "Python is a dynamically typed programming language designed by Guido van Rossum. Much like the programming language Ruby, Python was designed to be easily read by programmers. Because of its large following and many libraries, Python can be implemented and used to do anything from webpages to scientific research.") + self.assertEqual( + topic.short_description, + "Python is a dynamically typed programming language.", + ) + self.assertEqual( + topic.description, + "Python is a dynamically typed programming language designed by Guido van Rossum. Much like the programming language Ruby, Python was designed to be easily read by programmers. Because of its large following and many libraries, Python can be implemented and used to do anything from webpages to scientific research.", + ) 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)) @@ -54,36 +60,36 @@ class Topic(Framework.TestCase): def testNamesFromSearchResults(self): expected_names = [ - 'python', - 'django', - 'flask', - 'python-script', - 'python36', - 'opencv-python', - 'ruby', - 'python-library', - 'scikit-learn', - 'python37', - 'selenium-python', - 'sublime-text', - 'leetcode-python', - 'learning-python', - 'tkinter-python', - 'python35', - 'machinelearning-python', - 'python-flask', - 'python-package', - 'python-telegram-bot', - 'python-wrapper', - 'python3-6', - 'opencv3-python', - 'hackerrank-python', - 'python-api', - 'python2-7', - 'pythonista', - 'haxe', - 'python-requests', - 'python-2-7', + "python", + "django", + "flask", + "python-script", + "python36", + "opencv-python", + "ruby", + "python-library", + "scikit-learn", + "python37", + "selenium-python", + "sublime-text", + "leetcode-python", + "learning-python", + "tkinter-python", + "python35", + "machinelearning-python", + "python-flask", + "python-package", + "python-telegram-bot", + "python-wrapper", + "python3-6", + "opencv3-python", + "hackerrank-python", + "python-api", + "python2-7", + "pythonista", + "haxe", + "python-requests", + "python-2-7", ] self.assertListKeyEqual(self.topics, attrgetter("name"), expected_names) diff --git a/tests/Traffic.py b/tests/Traffic.py index 431a1215..c55e30b3 100644 --- a/tests/Traffic.py +++ b/tests/Traffic.py @@ -27,10 +27,11 @@ ################################################################################ from __future__ import absolute_import -from . import Framework import datetime +from . import Framework + class Traffic(Framework.TestCase): def setUp(self): @@ -51,7 +52,10 @@ class Traffic(Framework.TestCase): self.assertEqual(pathsResponse[0].uniques, 4) self.assertEqual(pathsResponse[0].count, 23) self.assertEqual(pathsResponse[0].path, "/jkufro/PyGithub") - self.assertEqual(pathsResponse[0].title, "jkufro/PyGithub: Typed interactions with the GitHub API v3") + self.assertEqual( + pathsResponse[0].title, + "jkufro/PyGithub: Typed interactions with the GitHub API v3", + ) def testGetViews(self): viewsResponse = self.repo.get_views_traffic() diff --git a/tests/UserKey.py b/tests/UserKey.py index 4c583c70..9d5d85c5 100644 --- a/tests/UserKey.py +++ b/tests/UserKey.py @@ -30,6 +30,7 @@ ################################################################################ from __future__ import absolute_import + from . import Framework @@ -40,13 +41,19 @@ class UserKey(Framework.TestCase): def testAttributes(self): self.assertEqual(self.key.id, 2626650) - self.assertEqual(self.key.key, "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw==") + self.assertEqual( + self.key.key, + "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw==", + ) self.assertEqual(self.key.title, "Key added through PyGithub") self.assertEqual(self.key.url, "https://api.github.com/user/keys/2626650") self.assertTrue(self.key.verified) # test __repr__() based on this attributes - self.assertEqual(self.key.__repr__(), 'UserKey(title="Key added through PyGithub", id=2626650)') + self.assertEqual( + self.key.__repr__(), + 'UserKey(title="Key added through PyGithub", id=2626650)', + ) def testDelete(self): self.key.delete() diff --git a/tests/__main__.py b/tests/__main__.py index 132a5d94..461aafc4 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -29,10 +29,11 @@ ################################################################################ from __future__ import absolute_import + import sys import unittest -from . import Framework -from . import AllTests + +from . import AllTests, Framework def main(argv):