Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_output_modes():
"""Test setting isort to use various output modes works as expected"""
test_output_grid = SortImports(file_contents=REALLY_LONG_IMPORT,
multi_line_output=WrapModes.GRID, line_length=40).output
assert test_output_grid == ("from third_party import (lib1, lib2,\n"
" lib3, lib4,\n"
" lib5, lib6,\n"
" lib7, lib8,\n"
" lib9, lib10,\n"
" lib11, lib12,\n"
" lib13, lib14,\n"
" lib15, lib16,\n"
" lib17, lib18,\n"
" lib20, lib21,\n"
" lib22)\n")
test_output_vertical = SortImports(file_contents=REALLY_LONG_IMPORT,
multi_line_output=WrapModes.VERTICAL, line_length=40).output
assert test_output_vertical == ("from third_party import (lib1,\n"
" lib2,\n"
" lib3, lib4, lib5, lib6, lib7, \\\n"
" lib8, lib9, lib10, lib11, lib12, \\\n"
" lib13, lib14, lib15, lib16, lib17, \\\n"
" lib18, lib20, lib21, lib22\n")
comment_output_hanging_indent = SortImports(file_contents=REALLY_LONG_IMPORT_WITH_COMMENT,
multi_line_output=WrapModes.HANGING_INDENT,
line_length=40, indent=" ").output
assert comment_output_hanging_indent == ("from third_party import lib1, \\ # comment\n"
" lib2, lib3, lib4, lib5, lib6, \\\n"
" lib7, lib8, lib9, lib10, lib11, \\\n"
" lib12, lib13, lib14, lib15, lib16, \\\n"
" lib17, lib18, lib20, lib21, lib22\n")
test_output_vertical_indent = SortImports(file_contents=REALLY_LONG_IMPORT,
multi_line_output=WrapModes.VERTICAL_HANGING_INDENT,
line_length=40, indent=" ").output
assert test_output_vertical_indent == ("from third_party import (\n"
" lib1,\n"
" lib2,\n"
" lib3,\n"
" lib4,\n"
" lib5,\n"
" lib6,\n"
" lib7,\n"
" lib8,\n"
" lib9,\n"
" lib10,\n"
" lib11,\n"
" lib12,\n"
" lib13,\n"
" lib14,\n"
parser.add_argument(
"--interactive",
dest="ask_to_apply",
action="store_true",
help="Tells isort to apply changes interactively.",
)
arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value}
if "dont_order_by_type" in arguments:
arguments["order_by_type"] = False
multi_line_output = arguments.get("multi_line_output", None)
if multi_line_output:
if multi_line_output.isdigit():
arguments["multi_line_output"] = WrapModes(int(multi_line_output))
else:
arguments["multi_line_output"] = WrapModes[multi_line_output]
return arguments
help="Base profile type to use for configuration.",
)
parser.add_argument(
"--interactive",
dest="ask_to_apply",
action="store_true",
help="Tells isort to apply changes interactively.",
)
arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value}
if "dont_order_by_type" in arguments:
arguments["order_by_type"] = False
multi_line_output = arguments.get("multi_line_output", None)
if multi_line_output:
if multi_line_output.isdigit():
arguments["multi_line_output"] = WrapModes(int(multi_line_output))
else:
arguments["multi_line_output"] = WrapModes[multi_line_output]
return arguments
dest="line_ending",
help="Forces line endings to the specified value. "
"If not set, values will be guessed per-file.",
)
parser.add_argument(
"--ls",
"--length-sort",
help="Sort imports by their string length.",
dest="length_sort",
action="store_true",
)
parser.add_argument(
"-m",
"--multi-line",
dest="multi_line_output",
choices=list(WrapModes.__members__.keys())
+ [str(mode.value) for mode in WrapModes.__members__.values()],
type=str,
help="Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, "
"5-vert-grid-grouped, 6-vert-grid-grouped-no-comma).",
)
inline_args_group.add_argument(
"--nis",
"--no-inline-sort",
dest="no_inline_sort",
action="store_true",
help="Leaves `from` imports with multiple imports 'as-is' "
"(e.g. `from foo import a, c ,b`).",
)
parser.add_argument(
"--nlb",
"--no-lines-before",
parser.add_argument('-i', '--indent', help='String to place for indents defaults to " " (4 spaces).',
dest='indent', type=str)
parser.add_argument('-j', '--jobs', help='Number of files to process in parallel.',
dest='jobs', type=int)
parser.add_argument('-k', '--keep-direct-and-as', dest='keep_direct_and_as_imports', action='store_true',
help="Turns off default behavior that removes direct imports when as imports exist.")
parser.add_argument('-l', '--lines', help='[Deprecated] The max length of an import line (used for wrapping '
'long imports).',
dest='line_length', type=int)
parser.add_argument('-lai', '--lines-after-imports', dest='lines_after_imports', type=int)
parser.add_argument('-lbt', '--lines-between-types', dest='lines_between_types', type=int)
parser.add_argument('-le', '--line-ending', dest='line_ending',
help="Forces line endings to the specified value. If not set, values will be guessed per-file.")
parser.add_argument('-ls', '--length-sort', help='Sort imports by their string length.',
dest='length_sort', action='store_true')
parser.add_argument('-m', '--multi-line', dest='multi_line_output', type=int, choices=range(len(WrapModes)),
help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, '
'5-vert-grid-grouped, 6-vert-grid-grouped-no-comma).')
inline_args_group.add_argument('-nis', '--no-inline-sort', dest='no_inline_sort', action='store_true',
help='Leaves `from` imports with multiple imports \'as-is\' (e.g. `from foo import a, c ,b`).')
parser.add_argument('-nlb', '--no-lines-before', help='Sections which should not be split with previous by empty lines',
dest='no_lines_before', action='append')
parser.add_argument('-ns', '--dont-skip', help='Files that sort imports should never skip over.',
dest='not_skip', action='append')
parser.add_argument('-o', '--thirdparty', dest='known_third_party', action='append',
help='Force sortImports to recognize a module as being part of a third party library.')
parser.add_argument('-ot', '--order-by-type', dest='order_by_type',
action='store_true', help='Order imports by type in addition to alphabetically')
parser.add_argument('-p', '--project', dest='known_first_party', action='append',
help='Force sortImports to recognize a module as being part of the current python project.')
parser.add_argument('-q', '--quiet', action='store_true', dest="quiet",
help='Shows extra quiet output, only errors are outputted.')