Skip to content

Commit

Permalink
Add test for an example for shared profiles support (issue #970)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 26, 2020
1 parent 3972ecc commit 57eb70a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
7 changes: 7 additions & 0 deletions example_shared_isort_profile/example_shared_isort_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PROFILE = {
"multi_line_output": 3,
"include_trailing_comma": True,
"force_grid_wrap": 0,
"use_parentheses": True,
"line_length": 100,
}
7 changes: 7 additions & 0 deletions example_shared_isort_profile/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions example_shared_isort_profile/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "example_shared_isort_profile"
version = "0.0.1"
description = "An example shared isort profile"
authors = ["Timothy Crosley <timothy.crosley@gmail.com>"]
license = "MIT"

[tool.poetry.plugins."isort.profiles"]
example = "example_shared_isort_profile:PROFILE"

[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
4 changes: 2 additions & 2 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ def _build_arg_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--profile",
dest="profile",
choices=list(profiles.keys()),
type=str,
help="Base profile type to use for configuration.",
help="Base profile type to use for configuration. "
f"Profiles include: {', '.join(profiles.keys())}. As well as any shared profiles.",
)
parser.add_argument(
"--interactive",
Expand Down
2 changes: 1 addition & 1 deletion isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __init__(
import pkg_resources

for plugin in pkg_resources.iter_entry_points("isort.profiles"):
profiles.setdefault(plugin.name, plugin.load().PROFILE) # pragma: no cover
profiles.setdefault(plugin.name, plugin.load())

if profile_name not in profiles:
raise ProfileDoesNotExist(profile_name)
Expand Down
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pip-shims = "^0.5.2"
smmap2 = "^3.0.1"
gitdb2 = "^4.0.2"
httpx = "^0.13.3"
example_shared_isort_profile = "^0.0.1"

[tool.poetry.scripts]
isort = "isort.main:main"
Expand Down
14 changes: 12 additions & 2 deletions tests/test_ticketed_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

import isort
from isort import Config
from isort import Config, exceptions


def test_semicolon_ignored_for_dynamic_lines_after_import_issue_1178():
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_isort_warns_when_known_sections_dont_match_issue_1331():
)


def test_isort_supports_append_only_imports_727():
def test_isort_supports_append_only_imports_issue_727():
"""Test to ensure isort provides a way to only add imports as an append.
See: https://github.com/timothycrosley/isort/issues/727.
"""
Expand All @@ -212,3 +212,13 @@ def test_isort_supports_append_only_imports_727():
import os
"""
)


def test_isort_supports_shared_profiles_issue_970():
"""Test to ensure isort provides a way to use shared profiles.
See: https://github.com/timothycrosley/isort/issues/970.
"""
assert isort.code("import a", profile="example") == "import a\n" # shared profile
assert isort.code("import a", profile="black") == "import a\n" # bundled profile
with pytest.raises(exceptions.ProfileDoesNotExist):
assert isort.code("import a", profile="madeupfake") == "import a\n" # non-existent profile

0 comments on commit 57eb70a

Please sign in to comment.