Skip to content

Commit

Permalink
Improve test suite import grouping/sorting, __all__ placement
Browse files Browse the repository at this point in the history
There is only one __all__ in the test suite, so this is mostly the
change to imports, grouping and sorting them in a fully consistent
style that is the same as the import style in the code under test.
  • Loading branch information
EliahKagan committed Mar 19, 2024
1 parent f705fd6 commit 4a4d880
Show file tree
Hide file tree
Showing 27 changed files with 99 additions and 95 deletions.
32 changes: 16 additions & 16 deletions test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = [
"fixture_path",
"fixture",
"StringProcessAdapter",
"with_rw_directory",
"with_rw_repo",
"with_rw_and_rw_remote_repo",
"TestBase",
"VirtualEnvironment",
"TestCase",
"SkipTest",
"skipIf",
"GIT_REPO",
"GIT_DAEMON_PORT",
]

import contextlib
from functools import wraps
import gc
Expand Down Expand Up @@ -31,22 +47,6 @@
GIT_REPO = os.environ.get("GIT_PYTHON_TEST_GIT_REPO_BASE", ospd(ospd(ospd(__file__))))
GIT_DAEMON_PORT = os.environ.get("GIT_PYTHON_TEST_GIT_DAEMON_PORT", "19418")

__all__ = (
"fixture_path",
"fixture",
"StringProcessAdapter",
"with_rw_directory",
"with_rw_repo",
"with_rw_and_rw_remote_repo",
"TestBase",
"VirtualEnvironment",
"TestCase",
"SkipTest",
"skipIf",
"GIT_REPO",
"GIT_DAEMON_PORT",
)

_logger = logging.getLogger(__name__)

# { Routines
Expand Down
2 changes: 2 additions & 0 deletions test/performance/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
5 changes: 3 additions & 2 deletions test/performance/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import logging
import os
import os.path as osp
import tempfile

from git import Repo
from git.db import GitCmdObjectDB, GitDB
from test.lib import TestBase
from git.util import rmtree
import os.path as osp

from test.lib import TestBase

# { Invariants

Expand Down
6 changes: 4 additions & 2 deletions test/performance/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
from time import time
import sys

from .lib import TestBigRepoRW
from git import Commit
from gitdb import IStream

from git import Commit

from test.performance.lib import TestBigRepoRW
from test.test_commit import TestCommitSerialization


Expand Down
2 changes: 1 addition & 1 deletion test/performance/test_odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from time import time

from .lib import TestBigRepoR
from test.performance.lib import TestBigRepoR


class TestObjDBPerformance(TestBigRepoR):
Expand Down
8 changes: 4 additions & 4 deletions test/performance/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import gc
import os
import os.path as osp
import subprocess
import sys
from time import time

from test.lib import with_rw_repo
from git.util import bin_to_hex
from gitdb import LooseObjectDB, IStream
from gitdb.test.lib import make_memory_file

import os.path as osp
from git.util import bin_to_hex

from .lib import TestBigRepoR
from test.lib import with_rw_repo
from test.performance.lib import TestBigRepoR


class TestObjDBPerformance(TestBigRepoR):
Expand Down
3 changes: 2 additions & 1 deletion test/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from test.lib import TestBase
from git import Actor

from test.lib import TestBase


class TestActor(TestBase):
def test_from_string_should_separate_name_and_email(self):
Expand Down
10 changes: 5 additions & 5 deletions test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import gc
import os
import os.path as osp
import sys
import tempfile
from unittest import skipIf

from git import Repo
from git.objects import Blob, Tree, Commit, TagObject
from git.objects import Blob, Commit, TagObject, Tree
import git.objects.base as base
from git.objects.util import get_object_type_by_name
from test.lib import TestBase as _TestBase, with_rw_repo, with_rw_and_rw_remote_repo
from git.util import hex_to_bin, HIDE_WINDOWS_FREEZE_ERRORS
from git.util import HIDE_WINDOWS_FREEZE_ERRORS, hex_to_bin

import git.objects.base as base
import os.path as osp
from test.lib import TestBase as _TestBase, with_rw_and_rw_remote_repo, with_rw_repo


class TestBase(_TestBase):
Expand Down
3 changes: 2 additions & 1 deletion test/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from test.lib import TestBase
from git import Blob

from test.lib import TestBase


class TestBlob(TestBase):
def test_mime_type_should_return_mime_type_for_known_types(self):
Expand Down
5 changes: 1 addition & 4 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

import git

from .lib import (
TestBase,
with_rw_directory,
)
from test.lib import TestBase, with_rw_directory


class TestClone(TestBase):
Expand Down
20 changes: 11 additions & 9 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
import copy
from datetime import datetime
from io import BytesIO
import os.path as osp
import re
import sys
import time
from unittest.mock import Mock

from git import (
Commit,
Actor,
)
from git import Repo
from gitdb import IStream

from git import Actor, Commit, Repo
from git.objects.util import tzoffset, utc
from git.repo.fun import touch
from test.lib import TestBase, with_rw_repo, fixture_path, StringProcessAdapter
from test.lib import with_rw_directory
from gitdb import IStream

import os.path as osp
from test.lib import (
StringProcessAdapter,
TestBase,
fixture_path,
with_rw_directory,
with_rw_repo,
)


class TestCommitSerialization(TestBase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from git import GitConfigParser
from git.config import _OMD, cp
from git.util import rmfile
from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory

from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory

_tc_lock_fpaths = osp.join(osp.dirname(__file__), "fixtures/*.lock")

Expand Down
5 changes: 3 additions & 2 deletions test/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import os.path as osp

from git.db import GitCmdObjectDB
from git.exc import BadObject
from test.lib import TestBase
from git.util import bin_to_hex

import os.path as osp
from test.lib import TestBase


class TestDB(TestBase):
Expand Down
1 change: 1 addition & 0 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from git import NULL_TREE, Diff, DiffIndex, Diffable, GitCommandError, Repo, Submodule
from git.cmd import Git

from test.lib import StringProcessAdapter, TestBase, fixture, with_rw_directory


Expand Down
3 changes: 1 addition & 2 deletions test/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import gc
import os
import os.path
import sys

import pytest

from test.lib import TestBase
from test.lib.helper import with_rw_directory

import os.path


class Tutorials(TestBase):
def tearDown(self):
Expand Down
7 changes: 4 additions & 3 deletions test/test_exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from itertools import product
import re

import ddt

from git.exc import (
InvalidGitRepositoryError,
WorkTreeRepositoryUnsupported,
Expand All @@ -20,9 +22,8 @@
RepositoryDirtyError,
)
from git.util import remove_password_if_present
from test.lib import TestBase

import itertools as itt
from test.lib import TestBase


_cmd_argvs = (
Expand Down Expand Up @@ -79,7 +80,7 @@ def test_ExceptionsHaveBaseClass(self):
for ex_class in exception_classes:
self.assertTrue(issubclass(ex_class, GitError))

@ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
@ddt.data(*list(product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
def test_CommandError_unicode(self, case):
argv, (cause, subs), stream = case
cls = CommandError
Expand Down
17 changes: 8 additions & 9 deletions test/test_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from io import BytesIO
from stat import S_IFDIR, S_IFREG, S_IFLNK, S_IXUSR
from stat import S_IFDIR, S_IFLNK, S_IFREG, S_IXUSR
from os import stat
import os.path as osp

from gitdb.base import IStream
from gitdb.typ import str_tree_type

from git import Git
from git.index import IndexFile
from git.index.fun import (
aggressive_tree_merge,
stat_mode_to_index_mode,
)
from git.index.fun import aggressive_tree_merge, stat_mode_to_index_mode
from git.objects.fun import (
traverse_tree_recursive,
traverse_trees_recursive,
tree_to_stream,
tree_entries_from_data,
tree_to_stream,
)
from git.repo.fun import find_worktree_git_dir
from test.lib import TestBase, with_rw_repo, with_rw_directory
from git.util import bin_to_hex, cygpath, join_path_native
from gitdb.base import IStream
from gitdb.typ import str_tree_type

from test.lib import TestBase, with_rw_directory, with_rw_repo


class TestFun(TestBase):
Expand Down
3 changes: 2 additions & 1 deletion test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

import ddt

from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
from git import Git, GitCommandError, GitCommandNotFound, Repo, cmd, refresh
from git.util import cwd, finalize_process

from test.lib import TestBase, fixture_path, with_rw_directory


Expand Down
14 changes: 4 additions & 10 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@
import sys
import tempfile

from gitdb.base import IStream

import ddt
import pytest

from git import (
BlobFilter,
Diff,
Git,
IndexFile,
Object,
Repo,
Tree,
)
from git import BlobFilter, Diff, Git, IndexFile, Object, Repo, Tree
from git.exc import (
CheckoutError,
GitCommandError,
Expand All @@ -41,7 +35,7 @@
from git.index.util import TemporaryFileSwap
from git.objects import Blob
from git.util import Actor, cwd, hex_to_bin, rmtree
from gitdb.base import IStream

from test.lib import (
TestBase,
VirtualEnvironment,
Expand Down
5 changes: 3 additions & 2 deletions test/test_reflog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import tempfile

from git.objects import IndexObject
from git.refs import RefLogEntry, RefLog
from git.refs import RefLog, RefLogEntry
from git.util import Actor, hex_to_bin, rmtree

from test.lib import TestBase, fixture_path
from git.util import Actor, rmtree, hex_to_bin


class TestRefLog(TestBase):
Expand Down
Loading

0 comments on commit 4a4d880

Please sign in to comment.