Debian Codegraph @

tests/integration/test_projects_using_isort.py

raw
1 """Tests projects that use isort to see if any differences are found between
2 their current imports and what isort suggest on the develop branch.
3 This is an important early warning signal of regressions.
4
5 NOTE: If you use isort within a public repository, please feel empowered to add your project here!
6 It is important to isort that as few regressions as possible are experienced by our users.
7 Having your project tested here is the most sure way to keep those regressions form ever happening.
8 """
9
10 from __future__ import annotations
11
12 from collections.abc import Generator, Sequence
13 from pathlib import Path
14 from subprocess import check_call
15
16 import pytest
17
18 from isort.main import main
19
20
21 def git_clone(repository_url: str, directory: Path) -> None:
22 """Clones the given repository into the given directory path"""
23 check_call(["git", "clone", "--depth", "1", repository_url, str(directory)])
24
25
26 def run_isort(arguments: Generator[str, None, None] | Sequence[str]) -> None:
27 """Runs isort in diff and check mode with the given arguments"""
28 main(["--check-only", "--diff", *arguments])
29
30
31 def test_django(tmp_path: Path) -> None:
32 git_clone("https://github.com/django/django.git", tmp_path)
33 run_isort(
34 str(target_dir)
35 for target_dir in (tmp_path / "django", tmp_path / "tests", tmp_path / "scripts")
36 )
37
38
39 def test_plone(tmp_path: Path) -> None:
40 git_clone("https://github.com/plone/plone.app.multilingualindexes.git", tmp_path)
41 run_isort([str(tmp_path / "src"), "--skip", "languagefallback.py"])
42
43
44 @pytest.mark.skip(
45 "Skip for now as #2295 introduce a breaking change. Can be re-enabled after pandas has updated."
46 )
47 def test_pandas(tmp_path: Path) -> None:
48 git_clone("https://github.com/pandas-dev/pandas.git", tmp_path)
49 run_isort((str(tmp_path / "pandas"), "--skip", "__init__.py"))
50
51
52 def test_habitat_lab(tmp_path: Path) -> None:
53 git_clone("https://github.com/facebookresearch/habitat-lab.git", tmp_path)
54 run_isort([str(tmp_path)])
55
56
57 def test_pylint(tmp_path: Path) -> None:
58 git_clone("https://github.com/PyCQA/pylint.git", tmp_path)
59 run_isort([str(tmp_path), "--skip", "bad.py"])
60
61
62 def test_hypothesis(tmp_path: Path) -> None:
63 git_clone("https://github.com/HypothesisWorks/hypothesis.git", tmp_path)
64 run_isort(
65 (
66 str(tmp_path),
67 "--skip",
68 "tests",
69 "--profile",
70 "black",
71 "--ca",
72 "--project",
73 "hypothesis",
74 "--project",
75 "hypothesistooling",
76 )
77 )
78
79
80 def test_pyramid(tmp_path: Path) -> None:
81 git_clone("https://github.com/Pylons/pyramid.git", tmp_path)
82 run_isort(
83 str(target_dir)
84 for target_dir in (tmp_path / "src" / "pyramid", tmp_path / "tests", tmp_path / "setup.py")
85 )
86
87
88 def test_products_zopetree(tmp_path: Path) -> None:
89 git_clone("https://github.com/jugmac00/Products.ZopeTree.git", tmp_path)
90 run_isort([str(tmp_path)])
91
92
93 def test_dobby(tmp_path: Path) -> None:
94 git_clone("https://github.com/rocketDuck/dobby.git", tmp_path)
95 run_isort([str(tmp_path / "tests"), str(tmp_path / "src")])
96
97
98 def test_zope(tmp_path: Path) -> None:
99 git_clone("https://github.com/zopefoundation/Zope.git", tmp_path)
100 run_isort([str(tmp_path), "--skip", "util.py"])