def test_remove_duplicate_redundant_import_imports(): assert remove_duplicated_imports([ CodePartition(CodeType.IMPORT, 'import os\n'), CodePartition(CodeType.IMPORT, 'import os.path\n'), ]) == [ CodePartition(CodeType.IMPORT, 'import os.path\n'), ] assert remove_duplicated_imports([ CodePartition(CodeType.IMPORT, 'import os.path\n'), CodePartition(CodeType.IMPORT, 'import os\n'), ]) == [ CodePartition(CodeType.IMPORT, 'import os.path\n'), ]
def test_remove_duplicated_imports_no_dupes_no_removals(): input_partitions = [ CodePartition(CodeType.IMPORT, 'import sys\n'), CodePartition(CodeType.NON_CODE, '\n'), CodePartition(CodeType.IMPORT, 'from six import text_type\n'), ] assert remove_duplicated_imports(input_partitions) == input_partitions
def test_remove_duplicated_imports_removes_duplicated(): assert remove_duplicated_imports([ CodePartition(CodeType.IMPORT, 'import sys\n'), CodePartition(CodeType.IMPORT, 'import sys\n'), ]) == [ CodePartition(CodeType.IMPORT, 'import sys\n'), ]
def test_aliased_imports_not_considered_redundant_v2(): partitions = [ CodePartition(CodeType.IMPORT, 'import os as osmod\n'), CodePartition(CodeType.IMPORT, 'import os.path\n'), ] assert remove_duplicated_imports(partitions) == partitions
def test_remove_duplicated_imports_trivial(): assert remove_duplicated_imports([]) == []