Skip to content

unused unittest2, type -> isinstance #906

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions gitlab/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import pickle

try:
import unittest
except ImportError:
import unittest2 as unittest
import unittest

from gitlab import base

Expand Down
39 changes: 16 additions & 23 deletions gitlab/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
from __future__ import absolute_import

import argparse
import os
import tempfile
import unittest

try:
from contextlib import redirect_stderr # noqa: H302
Expand All @@ -36,11 +34,6 @@ def redirect_stderr(new_target):
sys.stderr = old_target


try:
import unittest
except ImportError:
import unittest2 as unittest

import six

from gitlab import cli
Expand Down Expand Up @@ -120,19 +113,19 @@ def test_parse_args(self):

def test_parser(self):
parser = cli._get_parser(gitlab.v4.cli)
subparsers = None
for action in parser._actions:
if type(action) == argparse._SubParsersAction:
subparsers = action
break
subparsers = next(
action
for action in parser._actions
if isinstance(action, argparse._SubParsersAction)
)
self.assertIsNotNone(subparsers)
self.assertIn("project", subparsers.choices)

user_subparsers = None
for action in subparsers.choices["project"]._actions:
if type(action) == argparse._SubParsersAction:
user_subparsers = action
break
user_subparsers = next(
action
for action in subparsers.choices["project"]._actions
if isinstance(action, argparse._SubParsersAction)
)
self.assertIsNotNone(user_subparsers)
self.assertIn("list", user_subparsers.choices)
self.assertIn("get", user_subparsers.choices)
Expand All @@ -145,10 +138,10 @@ def test_parser(self):
actions = user_subparsers.choices["create"]._option_string_actions
self.assertFalse(actions["--description"].required)

user_subparsers = None
for action in subparsers.choices["group"]._actions:
if type(action) == argparse._SubParsersAction:
user_subparsers = action
break
user_subparsers = next(
action
for action in subparsers.choices["group"]._actions
if isinstance(action, argparse._SubParsersAction)
)
actions = user_subparsers.choices["create"]._option_string_actions
self.assertTrue(actions["--name"].required)
5 changes: 1 addition & 4 deletions gitlab/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

try:
import unittest
except ImportError:
import unittest2 as unittest
import unittest

import mock
import six
Expand Down
30 changes: 12 additions & 18 deletions gitlab/tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import os
import pickle
import tempfile
import json

try:
import unittest
except ImportError:
import unittest2 as unittest
import unittest

from httmock import HTTMock # noqa
from httmock import response # noqa
Expand Down Expand Up @@ -479,7 +473,7 @@ def resp_cont(url, request):
self.gl.auth()
self.assertEqual(self.gl.user.username, name)
self.assertEqual(self.gl.user.id, id_)
self.assertEqual(type(self.gl.user), CurrentUser)
self.assertIsInstance(self.gl.user, CurrentUser)

def test_hooks(self):
@urlmatch(
Expand All @@ -492,7 +486,7 @@ def resp_get_hook(url, request):

with HTTMock(resp_get_hook):
data = self.gl.hooks.get(1)
self.assertEqual(type(data), Hook)
self.assertIsInstance(data, Hook)
self.assertEqual(data.url, "testurl")
self.assertEqual(data.id, 1)

Expand All @@ -507,7 +501,7 @@ def resp_get_project(url, request):

with HTTMock(resp_get_project):
data = self.gl.projects.get(1)
self.assertEqual(type(data), Project)
self.assertIsInstance(data, Project)
self.assertEqual(data.name, "name")
self.assertEqual(data.id, 1)

Expand Down Expand Up @@ -553,7 +547,7 @@ def resp_get_group(url, request):

with HTTMock(resp_get_group):
data = self.gl.groups.get(1)
self.assertEqual(type(data), Group)
self.assertIsInstance(data, Group)
self.assertEqual(data.name, "name")
self.assertEqual(data.path, "path")
self.assertEqual(data.id, 1)
Expand Down Expand Up @@ -586,7 +580,7 @@ def resp_get_user(self, url, request):
def test_users(self):
with HTTMock(self.resp_get_user):
user = self.gl.users.get(1)
self.assertEqual(type(user), User)
self.assertIsInstance(user, User)
self.assertEqual(user.name, "name")
self.assertEqual(user.id, 1)

Expand All @@ -607,7 +601,7 @@ def resp_get_user_status(url, request):
user = self.gl.users.get(1)
with HTTMock(resp_get_user_status):
status = user.status.get()
self.assertEqual(type(status), UserStatus)
self.assertIsInstance(status, UserStatus)
self.assertEqual(status.message, "test")
self.assertEqual(status.emoji, "thumbsup")

Expand Down Expand Up @@ -636,7 +630,7 @@ def resp_mark_as_done(url, request):

with HTTMock(resp_get_todo):
todo = self.gl.todos.list()[0]
self.assertEqual(type(todo), Todo)
self.assertIsInstance(todo, Todo)
self.assertEqual(todo.id, 102)
self.assertEqual(todo.target_type, "MergeRequest")
self.assertEqual(todo.target["assignee"]["username"], "root")
Expand Down Expand Up @@ -683,10 +677,10 @@ def resp_update_submodule(url, request):
"committer_name": "Author",
"committer_email": "author@example.com",
"created_at": "2018-09-20T09:26:24.000-07:00",
"message": "Message",
"parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ],
"message": "Message",
"parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ],
"committed_date": "2018-09-20T09:26:24.000-07:00",
"authored_date": "2018-09-20T09:26:24.000-07:00",
"authored_date": "2018-09-20T09:26:24.000-07:00",
"status": null}"""
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)
Expand Down Expand Up @@ -724,5 +718,5 @@ class MyGitlab(gitlab.Gitlab):

config_path = self._default_config()
gl = MyGitlab.from_config("one", [config_path])
self.assertEqual(type(gl).__name__, "MyGitlab")
self.assertIsInstance(gl, MyGitlab)
os.unlink(config_path)
7 changes: 1 addition & 6 deletions gitlab/tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

try:
import unittest
except ImportError:
import unittest2 as unittest
import unittest

from httmock import HTTMock # noqa
from httmock import response # noqa
Expand Down
5 changes: 1 addition & 4 deletions gitlab/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

try:
import unittest
except ImportError:
import unittest2 as unittest
import unittest

from gitlab import types

Expand Down
5 changes: 1 addition & 4 deletions gitlab/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

try:
import unittest
except ImportError:
import unittest2 as unittest
import unittest

from gitlab import utils

Expand Down