Esempio n. 1
0
def create_file_with_contents(context, filename, text):
    os.makedirs(
        pathlib.Path(os.path.join(context.options.workspace_folder,
                                  filename)).parent,
        exist_ok=True,
    )
    with open(os.path.join(context.options.workspace_folder, filename),
              "w") as file:
        file.write("")

    try:
        # Using `core.dispatch_keys(context.driver, text)` will not always work, as its the same as typing in editor.
        # Sometimes VSC takes over and completes text, such as brackets (auto completion items).
        # Hence the solution is to open the file and paste the text into the editor (without typing it out).
        # This could bomb out, in case we're unable to copy to the clipboard.
        uitests.tools.copy_to_clipboard(text)
        open_file(context, filename)
        _wait_for_editor_focus(context, filename)
        quick_open.select_command(context, "Paste")
    except Exception:
        open_file(context, filename)
        _wait_for_editor_focus(context, filename)
        # Just update the file manually.
        with open(os.path.join(context.options.workspace_folder, filename),
                  "w") as file:
            file.write(text)
        # Let VSC see the changes (dirty hack, but this is a fallback).
        time.sleep(1)

    quick_open.select_command(context, "File: Save")
    quick_open.select_command(context, "View: Close Editor")
Esempio n. 2
0
def open_file(context, filename):
    _refresh_file_explorer(context)
    quick_open.select_command(context, "Go to File...")
    quick_open.select_value(context, filename)
    _wait_for_editor_focus(context, filename)
Esempio n. 3
0
def go_to_line(context, line_number):
    quick_open.select_command(context, "Go to Line...")
    quick_open.select_value(context, str(line_number))
    _wait_for_line(context, line_number)
Esempio n. 4
0
def change_document_language(context, language="Python"):
    quick_open.select_command(context, "Change Language Mode")
    quick_input.select_value(context, language)
Esempio n. 5
0
def create_new_untitled_file(context, language="Python"):
    quick_open.select_command(context, "File: New Untitled File")
    _wait_for_editor_focus(context, "Untitled-1")
    quick_open.select_command(context, "Change Language Mode")
    quick_input.select_value(context, language)
Esempio n. 6
0
def create_new_untitled_file_with_contents(context, text):
    quick_open.select_command(context, "File: New Untitled File")
    _wait_for_editor_focus(context, "Untitled-1")
    core.dispatch_keys(context.driver, text)