Esempio n. 1
0
def test_saves_to_filepath():
    temp_name = tempfile.NamedTemporaryFile().name
    assert not os.path.exists(temp_name)
    a_nfile = nfile.NFile(temp_name)
    assert not os.path.exists(a_nfile.file_path)
    a_nfile.save("content")
    assert os.path.exists(a_nfile.file_path)
Esempio n. 2
0
def test_save_no_filename_raises():
    """If there is no filename associated to the nfile we should get error"""
    no_filename_file = nfile.NFile()
    with pytest.raises(NinjaNoFileNameException) as info:
        no_filename_file.save("dumb content")
    assert str(info.value) == "I am asked to write a file but no one told me"\
                              " where"
Esempio n. 3
0
def test_file_is_read_properly():
    to_load_file = tempfile.NamedTemporaryFile()
    load_text = "Something to load"
    to_load_file.write(load_text.encode())
    to_load_file.seek(0)
    a_nfile = nfile.NFile(to_load_file.name)
    content = a_nfile.read()
    assert content == load_text
Esempio n. 4
0
def test_copy_flag_saves_to_path_only():
    temp_name = tempfile.NamedTemporaryFile().name
    temp_name_path = tempfile.NamedTemporaryFile().name
    temp_name_path = u"%s_really_unique" % temp_name_path
    assert temp_name != temp_name_path
    a_nfile = nfile.NFile(temp_name)
    a_nfile.save("content", path=temp_name_path)
    assert not os.path.exists(temp_name)
    assert os.path.exists(temp_name_path)
Esempio n. 5
0
def test_actual_content_is_saved():
    content = "empty content"
    temp_name = tempfile.NamedTemporaryFile().name
    assert not os.path.exists(temp_name)
    a_nfile = nfile.NFile(temp_name)
    a_nfile.save(content)
    a_file = open(temp_name)
    a_file_content = a_file.read()
    assert a_file_content == content
    a_file.close()
Esempio n. 6
0
def test_move_changes_filepath():
    temp_name = tempfile.NamedTemporaryFile().name
    new_temp_name = "%s_new" % temp_name
    test_content = "zero"
    temp_file = open(temp_name, "w")
    temp_file.write(test_content)
    temp_file.close()
    a_nfile = nfile.NFile(temp_name)
    a_nfile.move(new_temp_name)
    assert a_nfile.file_path == new_temp_name
Esempio n. 7
0
def test_path_is_set_as_new_nfile_filepath():
    temp_name = tempfile.NamedTemporaryFile().name
    temp_name_path = tempfile.NamedTemporaryFile().name
    temp_name_path = "%s_really_unique" % temp_name_path
    assert temp_name != temp_name_path
    a_nfile = nfile.NFile(temp_name)
    assert temp_name_path != a_nfile.file_path
    new_nfile = a_nfile.save("content", path=temp_name_path)
    assert temp_name_path == new_nfile.file_path
    assert temp_name != a_nfile.file_path
Esempio n. 8
0
def test_path_overrides_filepath():
    temp_name = tempfile.NamedTemporaryFile().name
    temp_name_path = tempfile.NamedTemporaryFile().name
    temp_name_path = "%s_really_unique" % temp_name_path
    assert temp_name != temp_name_path
    assert not temp_name == temp_name_path
    a_nfile = nfile.NFile(temp_name)
    assert not os.path.exists(a_nfile.file_path)
    a_nfile.save("content", path=temp_name_path)
    assert not os.path.exists(temp_name)
    assert os.path.exists(temp_name_path)
Esempio n. 9
0
def test_file_is_moved():
    temp_name = tempfile.NamedTemporaryFile().name
    new_temp_name = "%s_new" % temp_name
    test_content = "zero"
    temp_file = open(temp_name, "w")
    temp_file.write(test_content)
    temp_file.close()
    a_nfile = nfile.NFile(temp_name)
    a_nfile.move(new_temp_name)
    assert os.path.exists(new_temp_name)
    read_test_content = open(new_temp_name, "r")
    assert read_test_content.read() == test_content
    read_test_content.close()
    assert not os.path.exists(temp_name)
Esempio n. 10
0
    def __init__(self, filepath=None, project=None):
        super(NEditable, self).__init__()
        self.__id = ''
        self.__editor = None
        #Create NFile
        self._nfile = None
        if filepath is None:
            #temp file
            self.__id = 'temp'
        else:
            self.__id = filepath
            self._nfile = nfile.NFile(filepath)
        self.text_modified = False
        self._has_checkers = False
        self._lang = 'python'

        #Project:
        self.project = project

        #Checkers:
        self.registered_checkers = []
        self._checkers_executed = 0
Esempio n. 11
0
from ninja_ide.tools import json_manager
from ninja_ide import resources

from ninja_ide.core.file_handling import nfile
from ninja_ide.gui.editor import neditable
from ninja_ide.gui.editor.editor import NEditor
from ninja_ide.gui.syntax_registry import syntax_registry  # noqa

json_manager.load_syntax()
themes = json_manager.load_editor_schemes()
resources.COLOR_SCHEME = themes["Ninja Dark"]

qapp = QApplication(sys.argv)

ninja_editor = NEditor(neditable=neditable.NEditable(nfile.NFile()))
ninja_editor.side_widgets.remove("CodeFoldingWidget")
ninja_editor.side_widgets.remove("MarkerWidget")
ninja_editor.side_widgets.remove("TextChangeWidget")
ninja_editor.side_widgets.update_viewport()
ninja_editor.side_widgets.resize()
ninja_editor.register_syntax_for()
ninja_editor.showMaximized()

click_times = {}

with open(sys.argv[1]) as fp:
    text = fp.read()


def click(key):
Esempio n. 12
0
def make_editor():
    editable = neditable.NEditable(nfile.NFile())
    _editor = editor.create_editor(editable)
    return _editor
Esempio n. 13
0
def editor_bot(qtbot):
    editable = neditable.NEditable(nfile.NFile())
    _editor = editor.create_editor(editable)
    return _editor
Esempio n. 14
0
def test_file_read_blows_when_nonexistent_path():
    a_nfile = nfile.NFile()
    with pytest.raises(NinjaNoFileNameException):
        a_nfile.read()
Esempio n. 15
0
def create_editor(language=None):
    nfile_ref = nfile.NFile()
    neditable_ref = neditable.NEditable(nfile_ref)
    editor_ref = editor.create_editor(neditable_ref)
    return editor_ref
Esempio n. 16
0
def test_file_read_blows_on_nonexistent_file():
    temp_name = tempfile.NamedTemporaryFile().name
    a_nfile = nfile.NFile(temp_name)
    with pytest.raises(NinjaIOException):
        a_nfile.read()
Esempio n. 17
0
def test_filepath_changes_even_if_inexistent():
    temp_name = tempfile.NamedTemporaryFile().name
    a_nfile = nfile.NFile()
    a_nfile.move(temp_name)
    assert a_nfile.file_path == temp_name
Esempio n. 18
0
def test_knows_if_exists():
    """If the file exists, can NFile tell?"""
    temp_file = tempfile.NamedTemporaryFile()
    existing_nfile = nfile.NFile(temp_file.name)
    assert existing_nfile._exists()
Esempio n. 19
0
def test_creates_if_doesnt_exist():
    temp_name = tempfile.NamedTemporaryFile().name
    assert not os.path.exists(temp_name)
    a_nfile = nfile.NFile(temp_name)
    a_nfile.save("empty content")
    assert os.path.exists(temp_name)
Esempio n. 20
0
def test_knows_if_doesnt_exists():
    """If the file does not exists, can NFile tell?"""
    temp_file = tempfile.NamedTemporaryFile()
    existing_nfile = nfile.NFile(temp_file.name)
    temp_file.close()
    assert not existing_nfile._exists()