File: test_api.py

package info (click to toggle)
isort 7.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,548 kB
  • sloc: python: 15,337; javascript: 42; makefile: 28; sh: 22
file content (31 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Any

import pytest

from isort import api

imperfect_content = "import b\nimport a\n"
fixed_content = "import a\nimport b\n"


@pytest.fixture
def imperfect(tmpdir) -> Any:
    imperfect_file = tmpdir.join("test_needs_changes.py")
    imperfect_file.write_text(imperfect_content, "utf8")
    return imperfect_file


def test_sort_file(benchmark, imperfect) -> None:
    def sort_file():
        api.sort_file(imperfect)

    benchmark.pedantic(sort_file, iterations=10, rounds=100)
    assert imperfect.read() == fixed_content


def test_sort_file_in_place(benchmark, imperfect) -> None:
    def sort_file():
        api.sort_file(imperfect, overwrite_in_place=True)

    benchmark.pedantic(sort_file, iterations=10, rounds=100)
    assert imperfect.read() == fixed_content