Make flake8 use built-in mock from unittest, if available (Python 3.4+)

This commit is contained in:
Kurt Mosiejczuk 2019-09-13 16:19:22 -04:00
parent 121ea4f056
commit 5faa1df46a
21 changed files with 84 additions and 21 deletions

View file

@ -1,5 +1,8 @@
"""Integration tests for the checker submodule.""" """Integration tests for the checker submodule."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import checker from flake8 import checker

View file

@ -2,7 +2,10 @@
import json import json
import os import os
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import utils from flake8 import utils

View file

@ -2,7 +2,10 @@
import argparse import argparse
import sys import sys
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.main import application as app from flake8.main import application as app

View file

@ -1,7 +1,10 @@
"""Tests for the BaseFormatter object.""" """Tests for the BaseFormatter object."""
import argparse import argparse
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import style_guide from flake8 import style_guide

View file

@ -1,7 +1,10 @@
"""Tests for the Manager object for FileCheckers.""" """Tests for the Manager object for FileCheckers."""
import errno import errno
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import checker from flake8 import checker

View file

@ -4,7 +4,10 @@ import configparser
import os import os
import sys import sys
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.options import config from flake8.options import config

View file

@ -1,6 +1,9 @@
"""Tests for our debugging module.""" """Tests for our debugging module."""
import entrypoints import entrypoints
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.main import debug from flake8.main import debug

View file

@ -1,5 +1,8 @@
"""Unit tests for the FileChecker class.""" """Unit tests for the FileChecker class."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
import flake8 import flake8

View file

@ -2,7 +2,10 @@
import ast import ast
import tokenize import tokenize
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import processor from flake8 import processor

View file

@ -1,5 +1,8 @@
"""Tests for get_local_plugins.""" """Tests for get_local_plugins."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
from flake8.options import config from flake8.options import config

View file

@ -1,5 +1,8 @@
"""Tests around functionality in the git integration.""" """Tests around functionality in the git integration."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.main import git from flake8.main import git

View file

@ -1,5 +1,8 @@
"""Tests for Flake8's legacy API.""" """Tests for Flake8's legacy API."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.api import legacy as api from flake8.api import legacy as api

View file

@ -1,7 +1,10 @@
"""Unit tests for flake8.options.config.MergedConfigParser.""" """Unit tests for flake8.options.config.MergedConfigParser."""
import os import os
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.options import config from flake8.options import config

View file

@ -1,7 +1,10 @@
"""Unit tests for flake8.options.manager.Option.""" """Unit tests for flake8.options.manager.Option."""
import functools import functools
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8.options import manager from flake8.options import manager

View file

@ -2,7 +2,10 @@
import argparse import argparse
import os import os
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import utils from flake8 import utils

View file

@ -1,7 +1,10 @@
"""Tests for flake8.plugins.manager.Plugin.""" """Tests for flake8.plugins.manager.Plugin."""
import argparse import argparse
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import exceptions from flake8 import exceptions

View file

@ -1,5 +1,8 @@
"""Tests for flake8.plugins.manager.PluginManager.""" """Tests for flake8.plugins.manager.PluginManager."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
from flake8.plugins import manager from flake8.plugins import manager

View file

@ -1,5 +1,8 @@
"""Tests for flake8.plugins.manager.PluginTypeManager.""" """Tests for flake8.plugins.manager.PluginTypeManager."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import exceptions from flake8 import exceptions

View file

@ -1,7 +1,10 @@
"""Tests for the flake8.style_guide.StyleGuide class.""" """Tests for the flake8.style_guide.StyleGuide class."""
import argparse import argparse
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import statistics from flake8 import statistics

View file

@ -1,7 +1,10 @@
"""Tests for flake8's utils module.""" """Tests for flake8's utils module."""
import os import os
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import exceptions from flake8 import exceptions

View file

@ -1,5 +1,8 @@
"""Tests for the flake8.style_guide.Violation class.""" """Tests for the flake8.style_guide.Violation class."""
import mock try:
from unittest import mock
except (ImportError, AttributeError):
import mock
import pytest import pytest
from flake8 import style_guide from flake8 import style_guide