Skip to content

Commit

Permalink
Add test for current sort import.
Browse files Browse the repository at this point in the history
This add some test for what was requested in #13 and implemented in #263
  • Loading branch information
Carreau committed Jan 30, 2024
1 parent 58ff86f commit f3aaa53
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/tests_sorts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from pyflyby._parse import PythonBlock
from pyflyby._imports2s import sort_imports
from textwrap import dedent
import pytest

code1 = dedent("""
import external
import os
import sympy
import numpy
import json
import simplejson
from pkg1.mod1 import foo
from pkg1.mod2 import bar
from pkg2 import baz
import yy
from pkg1.mod1 import foo2
from pkg1.mod3 import quux
from pkg2 import baar
import zz
""")

# The logic requested in issue 13 whas to keep blocks, but order
# lexicographically. we do seem to be splitting stdlib from installed packages,
# but not adding a blank line and then sort lexicographically if an package has
# several submodules importted we put it in a block, otherwise we keep
# everything together.

expected1 = dedent("""
import json
import os
import external
import numpy
from pkg1.mod1 import foo, foo2
from pkg1.mod2 import bar
from pkg1.mod3 import quux
from pkg2 import baar, baz
import simplejson
import sympy
import yy
import zz
""")

@pytest.mark.parametrize('code, expected',[(code1, expected1)])
def test_sort_1(code, expected):

assert str(sort_imports(PythonBlock(code))) == expected
# expected is stable
assert str(sort_imports(PythonBlock(expected))) == expected

0 comments on commit f3aaa53

Please sign in to comment.