Skip to content

Commit

Permalink
Fix test relate to FileManager.save
Browse files Browse the repository at this point in the history
Do not save if not dirty and encoding has not changed
  • Loading branch information
ColinDuquesnoy committed Jun 27, 2015
1 parent 4c268aa commit c3ac6f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pyqode/core/managers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ def save(self, path=None, encoding=None, fallback_encoding=None):
error. None to use the locale preferred encoding
"""
if not self.editor.dirty:
if not self.editor.dirty and (encoding is not None and
encoding == self.encoding):
return
if fallback_encoding is None:
fallback_encoding = locale.getpreferredencoding()
Expand Down
10 changes: 7 additions & 3 deletions test/test_api/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
from pyqode.core.api.utils import TextHelper, keep_tc_pos

from pyqode.qt import QtGui
from pyqode.qt import QtGui, QtWidgets
from pyqode.qt.QtTest import QTest
from ..helpers import editor_open

Expand Down Expand Up @@ -129,6 +129,10 @@ def test_open_file(editor):
def test_save_file(editor):
path = os.path.join(os.getcwd(), 'tmp.py')
TextHelper(editor).select_lines(0, 1)
assert isinstance(editor, QtWidgets.QPlainTextEdit)
assert not editor.dirty
editor.appendPlainText('some text')
assert editor.dirty
editor.file.save(path, encoding='utf-8')
assert os.path.exists(path)
assert editor.file.encoding == 'utf-8'
Expand Down Expand Up @@ -232,7 +236,7 @@ def test_search_text(editor):
occurences, index = TextHelper(editor).search_text(
editor.textCursor(), 'import', QtGui.QTextDocument.FindCaseSensitively)
assert index == -1
assert len(occurences) == 11
assert len(occurences) == 10


@editor_open(__file__)
Expand Down Expand Up @@ -292,7 +296,7 @@ def test_extended_selection(editor):

@editor_open(__file__)
def test_matched_selection(editor):
line, column, text = 232, 14, ''' editor.textCursor(), 'import', QtGui.QTextDocument.FindCaseSensitively'''
line, column, text = 297, 14, '''__file__'''
cursor = editor.textCursor()
assert not cursor.hasSelection()
helper = TextHelper(editor)
Expand Down

0 comments on commit c3ac6f1

Please sign in to comment.