Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol committed Mar 19, 2020
1 parent 3666f7e commit ecbc9d7
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions libcst/codemod/commands/tests/test_remove_unused_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# pyre-strict

from libcst.codemod import CodemodTest
from libcst.codemod.commands.remove_unused_imports import RemoveUnusedImportsCommand

class RemoveUnusedImportsCommandTest(CodemodTest):
TRANSFORM = RemoveUnusedImportsCommand

def test_simple_case(self) -> None:
before = "import a, b\na()"
after = "import a\na()"
self.assertCodemod(before, after)

def test_double_import(self) -> None:
before = "import a\nimport a\na()"
self.assertCodemod(before, before)

def test_conditional_import(self) -> None:
before = """
if True:
import a
else:
import b as a
a()
"""
self.assertCodemod(before, before)

def test_unused_in_conditional(self) -> None:
before = """
if False:
import a
"""
after = """
if False:
pass
"""
self.assertCodemod(before, after)

def test_type_annotations(self) -> None:
before = """
import a
x: a = 1
"""
self.assertCodemod(before, before)

0 comments on commit ecbc9d7

Please sign in to comment.