diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2023-01-31 19:08:26 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2023-01-31 19:53:38 +0000 |
commit | 291b44e10e448be5439e510ef02f2fe709649b8f (patch) | |
tree | ab85339cda13dfcdaec84e98c41600d379125e80 | |
parent | e9f6eef3a0961cdb0a1b823ebbfd7bc289f63cf3 (diff) | |
download | subunit-git-291b44e10e448be5439e510ef02f2fe709649b8f.tar.gz |
Sort Python import definitions with isort
30 files changed, 94 insertions, 158 deletions
diff --git a/python/iso8601/test_iso8601.py b/python/iso8601/test_iso8601.py index ff9e273..ae6741e 100644 --- a/python/iso8601/test_iso8601.py +++ b/python/iso8601/test_iso8601.py @@ -1,5 +1,6 @@ import iso8601 + def test_iso8601_regex(): assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z") diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 144557e..5e318c1 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -115,25 +115,25 @@ Utility modules * subunit.test_results contains TestResult helper classes. """ -from io import BytesIO -from io import StringIO -from io import UnsupportedOperation as _UnsupportedOperation import os import re import subprocess import sys import unittest +from io import BytesIO, StringIO +from io import UnsupportedOperation as _UnsupportedOperation -from testtools import content, content_type, ExtendedToOriginalDecorator -from testtools.content import TracebackContent +from testtools import ExtendedToOriginalDecorator, content, content_type from testtools.compat import _b, _u +from testtools.content import TracebackContent + try: from testtools.testresult.real import _StringException RemoteException = _StringException except ImportError: raise ImportError ("testtools.testresult.real does not contain " "_StringException, check your version.") -from testtools import testresult, CopyStreamResult +from testtools import CopyStreamResult, testresult from subunit import chunked, details, iso8601, test_results from subunit.v2 import ByteStreamToStreamResult, StreamResultToBytes diff --git a/python/subunit/_output.py b/python/subunit/_output.py index aa92646..8141dc9 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -14,19 +14,14 @@ # import datetime -from functools import partial -from optparse import ( - OptionGroup, - OptionParser, - OptionValueError, -) import sys +from functools import partial +from optparse import OptionGroup, OptionParser, OptionValueError from subunit import make_stream_binary from subunit.iso8601 import UTC from subunit.v2 import StreamResultToBytes - _FINAL_ACTIONS = frozenset([ 'exists', 'fail', diff --git a/python/subunit/_to_disk.py b/python/subunit/_to_disk.py index 45f4fb5..8172cde 100644 --- a/python/subunit/_to_disk.py +++ b/python/subunit/_to_disk.py @@ -12,12 +12,12 @@ # license you chose for the specific language governing permissions and # limitations under that license. -from errno import EEXIST import io import json import optparse import os.path import sys +from errno import EEXIST from textwrap import dedent from testtools import StreamToDict diff --git a/python/subunit/filter_scripts/subunit2gtk.py b/python/subunit/filter_scripts/subunit2gtk.py index bcfd1e7..7db1d6e 100755 --- a/python/subunit/filter_scripts/subunit2gtk.py +++ b/python/subunit/filter_scripts/subunit2gtk.py @@ -50,18 +50,14 @@ import threading import unittest import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, GObject +gi.require_version('Gtk', '3.0') +from gi.repository import GObject, Gtk from testtools import StreamToExtendedDecorator -from subunit import ( - PROGRESS_POP, - PROGRESS_PUSH, - PROGRESS_SET, - ByteStreamToStreamResult, - ) -from subunit.progress_model import ProgressModel +from subunit import (PROGRESS_POP, PROGRESS_PUSH, PROGRESS_SET, + ByteStreamToStreamResult) +from subunit.progress_model import ProgressModel class GTKTestResult(unittest.TestResult): diff --git a/python/subunit/filter_scripts/subunit2pyunit.py b/python/subunit/filter_scripts/subunit2pyunit.py index 2a040ec..dd20f0c 100755 --- a/python/subunit/filter_scripts/subunit2pyunit.py +++ b/python/subunit/filter_scripts/subunit2pyunit.py @@ -16,12 +16,13 @@ """Display a subunit stream through python's unittest test runner.""" -from operator import methodcaller -from optparse import OptionParser import sys import unittest +from operator import methodcaller +from optparse import OptionParser -from testtools import StreamToExtendedDecorator, DecorateTestCaseResult, StreamResultRouter +from testtools import (DecorateTestCaseResult, StreamResultRouter, + StreamToExtendedDecorator) from subunit import ByteStreamToStreamResult from subunit.filters import find_stream @@ -50,8 +51,8 @@ def main(): before_run=methodcaller('startTestRun'), after_run=methodcaller('stopTestRun')) if options.progress: - from bzrlib.tests import TextTestRunner from bzrlib import ui + from bzrlib.tests import TextTestRunner ui.ui_factory = ui.make_ui_for_terminal(None, sys.stdout, sys.stderr) runner = TextTestRunner() else: diff --git a/python/subunit/filter_scripts/subunit_1to2.py b/python/subunit/filter_scripts/subunit_1to2.py index 085c0fe..398a3a6 100755 --- a/python/subunit/filter_scripts/subunit_1to2.py +++ b/python/subunit/filter_scripts/subunit_1to2.py @@ -16,8 +16,8 @@ """Convert a version 1 subunit stream to version 2 stream.""" -from optparse import OptionParser import sys +from optparse import OptionParser from testtools import ExtendedToStreamDecorator diff --git a/python/subunit/filter_scripts/subunit_2to1.py b/python/subunit/filter_scripts/subunit_2to1.py index 1f2716a..9e5ab5d 100755 --- a/python/subunit/filter_scripts/subunit_2to1.py +++ b/python/subunit/filter_scripts/subunit_2to1.py @@ -16,13 +16,10 @@ """Convert a version 2 subunit stream to a version 1 stream.""" -from optparse import OptionParser import sys +from optparse import OptionParser -from testtools import ( - StreamToExtendedDecorator, - StreamResultRouter, - ) +from testtools import StreamResultRouter, StreamToExtendedDecorator from subunit import ByteStreamToStreamResult, TestProtocolClient from subunit.filters import find_stream diff --git a/python/subunit/filter_scripts/subunit_filter.py b/python/subunit/filter_scripts/subunit_filter.py index 951672f..cd1ee76 100755 --- a/python/subunit/filter_scripts/subunit_filter.py +++ b/python/subunit/filter_scripts/subunit_filter.py @@ -26,22 +26,16 @@ contains tests which match any of the --with expressions and none of the Remember to quote shell metacharacters. """ -from optparse import OptionParser -import sys import re +import sys +from optparse import OptionParser from testtools import ExtendedToStreamDecorator, StreamToExtendedDecorator -from subunit import ( - StreamResultToBytes, - read_test_list, - ) +from subunit import StreamResultToBytes, read_test_list from subunit.filters import filter_by_result, find_stream -from subunit.test_results import ( - and_predicates, - make_tag_filter, - TestResultFilter, - ) +from subunit.test_results import (TestResultFilter, and_predicates, + make_tag_filter) def make_options(description): diff --git a/python/subunit/filter_scripts/subunit_ls.py b/python/subunit/filter_scripts/subunit_ls.py index 0eee267..55d5298 100755 --- a/python/subunit/filter_scripts/subunit_ls.py +++ b/python/subunit/filter_scripts/subunit_ls.py @@ -16,19 +16,14 @@ """List tests in a subunit stream.""" -from optparse import OptionParser import sys +from optparse import OptionParser -from testtools import ( - CopyStreamResult, StreamResultRouter, - StreamSummary) +from testtools import CopyStreamResult, StreamResultRouter, StreamSummary from subunit import ByteStreamToStreamResult from subunit.filters import find_stream -from subunit.test_results import ( - CatFiles, - TestIdPrintingResult, - ) +from subunit.test_results import CatFiles, TestIdPrintingResult def main(): diff --git a/python/subunit/filter_scripts/subunit_notify.py b/python/subunit/filter_scripts/subunit_notify.py index 44ca758..71e4c73 100755 --- a/python/subunit/filter_scripts/subunit_notify.py +++ b/python/subunit/filter_scripts/subunit_notify.py @@ -17,6 +17,7 @@ """Notify the user of a finished test run.""" import gi + gi.require_version('Gtk', '3.0') from gi.repository import Notify from testtools import StreamToExtendedDecorator diff --git a/python/subunit/filter_scripts/subunit_output.py b/python/subunit/filter_scripts/subunit_output.py index a587e87..176656a 100755 --- a/python/subunit/filter_scripts/subunit_output.py +++ b/python/subunit/filter_scripts/subunit_output.py @@ -20,6 +20,7 @@ import sys from subunit._output import output_main + def main(): sys.exit(output_main()) diff --git a/python/subunit/filters.py b/python/subunit/filters.py index ba534e3..539086c 100644 --- a/python/subunit/filters.py +++ b/python/subunit/filters.py @@ -14,15 +14,13 @@ # -from optparse import OptionParser import sys +from optparse import OptionParser from testtools import CopyStreamResult, StreamResult, StreamResultRouter -from subunit import ( - DiscardStream, ProtocolTestCase, ByteStreamToStreamResult, - StreamResultToBytes, - ) +from subunit import (ByteStreamToStreamResult, DiscardStream, ProtocolTestCase, + StreamResultToBytes) from subunit.test_results import CatFiles diff --git a/python/subunit/iso8601.py b/python/subunit/iso8601.py index 7d392d4..fa42270 100644 --- a/python/subunit/iso8601.py +++ b/python/subunit/iso8601.py @@ -29,8 +29,8 @@ datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.iso8601.Utc ...>) """ -from datetime import datetime, timedelta, tzinfo import re +from datetime import datetime, timedelta, tzinfo __all__ = ["parse_date", "ParseError"] diff --git a/python/subunit/run.py b/python/subunit/run.py index 20fe86c..a69c3d6 100755 --- a/python/subunit/run.py +++ b/python/subunit/run.py @@ -25,17 +25,11 @@ import os import sys from testtools import ExtendedToStreamDecorator +from testtools.run import (BUFFEROUTPUT, CATCHBREAK, FAILFAST, USAGE_AS_MAIN, + TestProgram, list_test) from subunit import StreamResultToBytes from subunit.test_results import AutoTimingTestResultDecorator -from testtools.run import ( - BUFFEROUTPUT, - CATCHBREAK, - FAILFAST, - list_test, - TestProgram, - USAGE_AS_MAIN, - ) class SubunitTestRunner(object): diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index 53c3dad..6478b97 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -20,15 +20,12 @@ import csv import datetime import testtools -from testtools.content import ( - text_content, - TracebackContent, - ) from testtools import StreamResult +from testtools.content import TracebackContent, text_content from testtools.testcase import PlaceHolder -from subunit import iso8601 import subunit +from subunit import iso8601 # NOT a TestResult, because we are implementing the interface, not inheriting diff --git a/python/subunit/tests/__init__.py b/python/subunit/tests/__init__.py index 4c8b2ae..a49a0b2 100644 --- a/python/subunit/tests/__init__.py +++ b/python/subunit/tests/__init__.py @@ -19,7 +19,6 @@ from unittest import TestLoader from testscenarios import generate_scenarios - # Before the test module imports to avoid circularity. # For testing: different pythons have different str() implementations. _remote_exception_repr = "testtools.testresult.real._StringException" @@ -28,22 +27,12 @@ _remote_exception_str = "Traceback (most recent call last):\ntesttools.testresul _remote_exception_str_chunked = "57\r\n" + _remote_exception_str + ": boo qux\n0\r\n" -from subunit.tests import ( - test_chunked, - test_details, - test_filters, - test_filter_to_disk, - test_output_filter, - test_progress_model, - test_run, - test_subunit_filter, - test_subunit_stats, - test_subunit_tags, - test_tap2subunit, - test_test_protocol, - test_test_protocol2, - test_test_results, - ) +from subunit.tests import (test_chunked, test_details, test_filter_to_disk, + test_filters, test_output_filter, + test_progress_model, test_run, test_subunit_filter, + test_subunit_stats, test_subunit_tags, + test_tap2subunit, test_test_protocol, + test_test_protocol2, test_test_results) def test_suite(): diff --git a/python/subunit/tests/sample-script.py b/python/subunit/tests/sample-script.py index f89f6c1..d8cdc76 100755 --- a/python/subunit/tests/sample-script.py +++ b/python/subunit/tests/sample-script.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 import sys + if sys.platform == "win32": - import msvcrt, os + import msvcrt + import os msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) if len(sys.argv) == 2: # subunit.tests.test_test_protocol.TestExecTestCase.test_sample_method_args diff --git a/python/subunit/tests/sample-two-script.py b/python/subunit/tests/sample-two-script.py index a687601..ecddc2e 100755 --- a/python/subunit/tests/sample-two-script.py +++ b/python/subunit/tests/sample-two-script.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import sys + print("test old mcdonald") print("success old mcdonald") print("test bing crosby") diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index 21f4814..bb7ccd6 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -15,8 +15,8 @@ # limitations under that license. # -from io import BytesIO import unittest +from io import BytesIO from testtools.compat import _b diff --git a/python/subunit/tests/test_filter_to_disk.py b/python/subunit/tests/test_filter_to_disk.py index c2b0996..c0654f5 100644 --- a/python/subunit/tests/test_filter_to_disk.py +++ b/python/subunit/tests/test_filter_to_disk.py @@ -18,13 +18,12 @@ import os.path from fixtures import TempDir from testtools import TestCase -from testtools.matchers import ( - FileContains - ) +from testtools.matchers import FileContains from subunit import _to_disk from subunit.v2 import StreamResultToBytes + class SmokeTest(TestCase): def test_smoke(self): diff --git a/python/subunit/tests/test_filters.py b/python/subunit/tests/test_filters.py index bc797da..21cca42 100644 --- a/python/subunit/tests/test_filters.py +++ b/python/subunit/tests/test_filters.py @@ -19,9 +19,8 @@ from tempfile import NamedTemporaryFile from testtools import TestCase -from subunit.filters import find_stream - from subunit import read_test_list +from subunit.filters import find_stream class TestReadTestList(TestCase): diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index 0f61ac5..e247e35 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -15,34 +15,24 @@ # import datetime -from functools import partial -from io import BytesIO, StringIO, TextIOWrapper import optparse import sys +from contextlib import contextmanager +from functools import partial +from io import BytesIO, StringIO, TextIOWrapper from tempfile import NamedTemporaryFile -from contextlib import contextmanager from testtools import TestCase from testtools.compat import _u -from testtools.matchers import ( - Equals, - Matcher, - MatchesAny, - MatchesListwise, - Mismatch, - raises, -) +from testtools.matchers import (Equals, Matcher, MatchesAny, MatchesListwise, + Mismatch, raises) from testtools.testresult.doubles import StreamResult -from subunit.iso8601 import UTC -from subunit.v2 import StreamResultToBytes, ByteStreamToStreamResult -from subunit._output import ( - _ALL_ACTIONS, - _FINAL_ACTIONS, - generate_stream_results, - parse_arguments, -) import subunit._output as _o +from subunit._output import (_ALL_ACTIONS, _FINAL_ACTIONS, + generate_stream_results, parse_arguments) +from subunit.iso8601 import UTC +from subunit.v2 import ByteStreamToStreamResult, StreamResultToBytes class SafeOptionParser(optparse.OptionParser): diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 3ae2a08..81494ad 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -16,21 +16,20 @@ """Tests for subunit.TestResultFilter.""" -from datetime import datetime -from io import BytesIO import os import subprocess import sys import unittest +from datetime import datetime +from io import BytesIO -from testtools.compat import _b from testtools import TestCase +from testtools.compat import _b from testtools.testresult.doubles import ExtendedTestResult, StreamResult import subunit -from subunit import iso8601 -from subunit.test_results import make_tag_filter, TestResultFilter -from subunit import ByteStreamToStreamResult, StreamResultToBytes +from subunit import ByteStreamToStreamResult, StreamResultToBytes, iso8601 +from subunit.test_results import TestResultFilter, make_tag_filter class TestTestResultFilter(TestCase): diff --git a/python/subunit/tests/test_subunit_stats.py b/python/subunit/tests/test_subunit_stats.py index 46be5c2..a4f29f2 100644 --- a/python/subunit/tests/test_subunit_stats.py +++ b/python/subunit/tests/test_subunit_stats.py @@ -16,9 +16,8 @@ """Tests for subunit.TestResultStats.""" -from io import BytesIO -from io import StringIO import unittest +from io import BytesIO, StringIO from testtools.compat import _b diff --git a/python/subunit/tests/test_tap2subunit.py b/python/subunit/tests/test_tap2subunit.py index 5b7c07a..14b5086 100644 --- a/python/subunit/tests/test_tap2subunit.py +++ b/python/subunit/tests/test_tap2subunit.py @@ -16,8 +16,8 @@ """Tests for TAP2SubUnit.""" -from io import BytesIO, StringIO import unittest +from io import BytesIO, StringIO from testtools import TestCase from testtools.compat import _u diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 74cb1ce..52be34c 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -16,39 +16,35 @@ import datetime import io -from io import BytesIO -from io import StringIO import os import tempfile import unittest +from io import BytesIO, StringIO -from testtools import PlaceHolder, skipIf, TestCase, TestResult +from testtools import PlaceHolder, TestCase, TestResult, skipIf from testtools.compat import _b, _u from testtools.content import Content, TracebackContent, text_content from testtools.content_type import ContentType + try: - from testtools.testresult.doubles import ( - Python26TestResult, - Python27TestResult, - ExtendedTestResult, - ) + from testtools.testresult.doubles import (ExtendedTestResult, + Python26TestResult, + Python27TestResult) except ImportError: from testtools.tests.helpers import ( Python26TestResult, Python27TestResult, ExtendedTestResult, ) + from testtools.matchers import Contains, Equals, MatchesAny import subunit -from subunit.tests import ( - _remote_exception_repr, - _remote_exception_repr_chunked, - _remote_exception_str, - _remote_exception_str_chunked, - ) import subunit.iso8601 as iso8601 - +from subunit.tests import (_remote_exception_repr, + _remote_exception_repr_chunked, + _remote_exception_str, + _remote_exception_str_chunked) tb_prelude = "Traceback (most recent call last):\n" @@ -90,14 +86,9 @@ class TestHelpers(TestCase): class TestTestImports(unittest.TestCase): def test_imports(self): - from subunit import DiscardStream - from subunit import TestProtocolServer - from subunit import RemotedTestCase - from subunit import RemoteError - from subunit import ExecTestCase - from subunit import IsolatedTestCase - from subunit import TestProtocolClient - from subunit import ProtocolTestCase + from subunit import (DiscardStream, ExecTestCase, IsolatedTestCase, + ProtocolTestCase, RemotedTestCase, RemoteError, + TestProtocolClient, TestProtocolServer) class TestDiscardStream(unittest.TestCase): diff --git a/python/subunit/tests/test_test_protocol2.py b/python/subunit/tests/test_test_protocol2.py index 0b40929..1f542d5 100644 --- a/python/subunit/tests/test_test_protocol2.py +++ b/python/subunit/tests/test_test_protocol2.py @@ -14,22 +14,22 @@ # limitations under that license. # -from io import BytesIO import datetime +from io import BytesIO try: from hypothesis import given -# To debug hypothesis -# from hypothesis import Settings, Verbosity -# Settings.default.verbosity = Verbosity.verbose + # To debug hypothesis + # from hypothesis import Settings, Verbosity + # Settings.default.verbosity = Verbosity.verbose import hypothesis.strategies as st except ImportError: given = None st = None from testtools import TestCase from testtools.matchers import Contains, HasLength -from testtools.tests.test_testresult import TestStreamResultContract from testtools.testresult.doubles import StreamResult +from testtools.tests.test_testresult import TestStreamResultContract import subunit import subunit.iso8601 as iso8601 diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 31fd0ac..7362624 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -16,23 +16,19 @@ import csv import datetime -from io import StringIO import sys import unittest +from io import StringIO +import testtools from testtools import TestCase -from testtools.content import ( - text_content, - TracebackContent, -) +from testtools.content import TracebackContent, text_content from testtools.testresult.doubles import ExtendedTestResult import subunit import subunit.iso8601 as iso8601 import subunit.test_results -import testtools - class LoggingDecorator(subunit.test_results.HookedTestResultDecorator): @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os.path + from setuptools import setup |