<commit_before>from __future__ import absolute_import

from textwrap import dedent

from importmagic.importer import update_imports
from importmagic.symbols import Scope


def test_deep_import_of_unknown_symbol(index):
    src = dedent("""
        print(os.unknown('/'))<commit_msg>Add a test for get_update().<commit_after>from __future__ import absolute_import

from textwrap import dedent

from importmagic.importer import update_imports, get_update
from importmagic.symbols import Scope


def test_get_update(index):
    src = dedent("""
         # header comment
         import sys

         print(os.unknown('/'))
         """).strip()
    unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
    start_line, end_line, new_block = get_update(src, index, unresolved, unreferenced)
    assert dedent("""\
        import os


        """).lstrip() == new_block


def test_deep_import_of_unknown_symbol(index):
    src = dedent("""
         print(os.unknown('/'))
{'fraction_non_alphanumeric': 0.09940357852882704, 'fraction_numerical': 0.0, 'mean_word_length': 4.009950248756219, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1334330', 'n_tokens_mistral': 311, 'n_tokens_neox': 299, 'n_words': 72}