Skip to content

Commit

Permalink
fixed isbin err, remove charset in zip, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
hustlei committed Nov 14, 2019
1 parent a978c91 commit 8aad63b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python3 #--version 3.7.4 3.8.0
- python --version
- python -m pip install --upgrade pip
- pip3 install chardet # can't import chardet from .zip
- python --version
env:
- PATH=/c/Python38:/c/Python38/Scripts:$PATH

Expand All @@ -34,6 +34,7 @@ jobs:
language: shell # 'language: python' is an error on Travis CI macOS
before_install:
- python3 --version
- python --version

install:
- pip3 install PyQt5
Expand Down
Binary file removed src/ui/editor/3rdparty.zip
Binary file not shown.
22 changes: 11 additions & 11 deletions src/ui/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

__version__ = "1.0"

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "3rdparty.zip"))
try:
import chardet
except Exception:
print("load chardet failed.")
# import zipimport
# importer = zipimport.zipimporter(os.path.join(os.path.dirname(__file__), "3rdparty.zip"))
# chardet = importer.load_module('chardet')
print(str(__file__))
import chardet
# import zipimport
# importer = zipimport.zipimporter(os.path.join(os.path.dirname(__file__), "3rdparty.zip"))
# chardet = importer.load_module('chardet')


class CodeEditor(QsciScintilla):
Expand Down Expand Up @@ -261,6 +258,7 @@ def load(self, filename):
# lm=os.path.getsize(filename)
strbytes = f.read()
deteclen = min(len(strbytes), 1024)
print("detect length:" + str(deteclen))
if not deteclen:
self.coding = "utf-8"
self.setText("")
Expand All @@ -284,8 +282,10 @@ def load(self, filename):
except BaseException: # Exception:
self.coding = "none"
self.setText(self.tr("can't open this file, it may be a binary file."))
print("open file failue.")
self.setEnabled(False)
return False
print("coding"+self.coding)
self.setModified(False)
self.setLanguage(self.guessLang(filename))
return True
Expand All @@ -295,7 +295,7 @@ def __byte2str(strbytes, echoescape=True):
s = ""
if echoescape and len(strbytes) < 11 * 1024:
for b in strbytes: # ord(chr(b))
if b < 0x30: # >= 0x80 or c.isalnum() or c == "-" or c == "_":
if b < 0x20 and b not in (9, 10, 13): # >= 0x80 or c.isalnum() or c == "-" or c == "_":
s += " NUL "
else:
c = chr(b)
Expand All @@ -306,10 +306,10 @@ def __byte2str(strbytes, echoescape=True):
return s

def __isBin(self, strbytes):
chr_list = [b for b in strbytes if b > 0x30]
chr_list = [b for b in strbytes if b > 0x20 or b in (9, 10, 13)]
count = len(chr_list)
f = count / len(strbytes)
return f > 0.7
return f < 0.7

def save(self, filename):
"""Save the editor contents to the given filename.
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def sharedwin():
app = App()
app.run(pytest=True)
yield app.windows
app.exit()
app.windows["main"].close()
app.quit()


@fixture(scope="function")
Expand Down
56 changes: 29 additions & 27 deletions tests/test_mainwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@

from PyQt5.QtWidgets import QApplication

def test_findDialog(qtbot, sharedwin):
win = sharedwin["main"]
win.editor.searchDialog.show()
qtbot.waitForWindowShown(win.editor.searchDialog)

def test_theme(sharedwin):
win = sharedwin["main"]
win.actions["DisableQss"].setChecked(True)
win.actions["DisableQss"].setChecked(False)
win.actions["DisableQss"].setChecked(True)
win.themeCombo.setCurrentIndex(win.themeCombo.maxCount() - 1)
assert win.actions["DisableQss"].isChecked()

def test_var_refresh(qtbot, sharedwin):
win = sharedwin["main"]
qtbot.keyPress(win.editor, Qt.Key_Up)
assert "*" not in win.windowTitle()

def test_preivew(qtbot, sharedwin):
sharedwin["main"].docks["preview"].widget().setCurrentIndex(2)
# qtbot.waitForWindowShown(windows["main"])
with mock.patch.object(QApplication, "exit"):
assert QApplication.exit.call_count == 0

def test_confDialog(qtbot, sharedwin):
sharedwin["main"].confDialog.show()
qtbot.waitForWindowShown(sharedwin["main"].confDialog)
# def test_findDialog(qtbot, sharedwin):
# win = sharedwin["main"]
# win.editor.searchDialog.show()
# qtbot.waitForWindowShown(win.editor.searchDialog)
#
# def test_theme(sharedwin):
# win = sharedwin["main"]
# win.actions["DisableQss"].setChecked(True)
# win.actions["DisableQss"].setChecked(False)
# win.actions["DisableQss"].setChecked(True)
# win.themeCombo.setCurrentIndex(win.themeCombo.maxCount() - 1)
# assert win.actions["DisableQss"].isChecked()
#
# def test_var_refresh(qtbot, sharedwin):
# win = sharedwin["main"]
# qtbot.keyPress(win.editor, Qt.Key_Up)
# assert "*" not in win.windowTitle()
#
# def test_preivew(qtbot, sharedwin):
# sharedwin["main"].docks["preview"].widget().setCurrentIndex(2)
# # qtbot.waitForWindowShown(windows["main"])
# with mock.patch.object(QApplication, "exit"):
# assert QApplication.exit.call_count == 0
#
# def test_confDialog(qtbot, sharedwin):
# sharedwin["main"].confDialog.show()
# qtbot.waitForWindowShown(sharedwin["main"].confDialog)


def test_fileop_and_clrpic(qapp, qtbot, mainwin, tmpdir):
Expand Down Expand Up @@ -64,6 +64,8 @@ def closeclrdialog():
# dial.done(0) # dial.close()
qtbot.keyPress(dial, Qt.Key_Enter)
# qtbot.keyPress(qapp.focusWidget(), Qt.Key_Return, delay=50)
import os
os._exit() # exit thread

from threading import Thread
t1 = Thread(target=closeclrdialog)
Expand Down

0 comments on commit 8aad63b

Please sign in to comment.