From c9dbb63b058a543475b53f2638211a300e5832aa Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Mon, 12 Dec 2016 10:12:53 +0000 Subject: [PATCH 1/2] [#371] Non-ascii filename --- CHANGELOG.md | 1 + inselect/tests/gui/test_file_open.py | 28 +++++++++++++++++++++++++--- inselect/tests/lib/test_document.py | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3663da2..f328392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Version 0.1.35 - #377 Windows non-latin username test - #374 Support pyzbar - #372 Support pydmtxlib +- #371 Ugly error message when opening file with non-ascii characters in name - #369 Keyboard shortcuts box too tall on some displays - #368 Ugly error message when creating a new inselect document on Mac OS X - #367 Reveal file doesn't work on Windows diff --git a/inselect/tests/gui/test_file_open.py b/inselect/tests/gui/test_file_open.py index 1ff3d93..b989bf1 100644 --- a/inselect/tests/gui/test_file_open.py +++ b/inselect/tests/gui/test_file_open.py @@ -39,15 +39,17 @@ def assertWindowTitleNoDocument(self): """ self.assertEqual('Inselect', self.window.windowTitle()) - def assertWindowTitleOpenDocument(self): + def assertWindowTitleOpenDocument(self, title='shapes'): """Asserts that self.window.windowTitle is as expected. """ # Some OSes append ' \u2014 inselect' to the window title, so assert # using a regular expression rather than equality. Not possible to # check modified behaviour because MainWindow.modified_changed slot # is not called without event loop. - self.assertRegex(self.window.windowTitle(), - '^shapes\\.inselect.*') + self.assertRegex( + self.window.windowTitle(), + '^{0}\\.inselect.*'.format(title) + ) def test_open_doc(self): "Open an inselect document" @@ -56,6 +58,26 @@ def test_open_doc(self): self.assertWindowTitleOpenDocument() self.assertFalse(self.window.model.is_modified) + def test_open_non_ascii(self): + "Open an inselect document with non-ascii characters in the filename" + # Copy the existing 'shapes' file to a temporary with the a non-latin + # name + with temp_directory_with_files() as tempdir: + stem = 'åland' + path = tempdir.joinpath('{0}.inselect'.format(stem)) + + shutil.copy(str(TESTDATA.joinpath('shapes.inselect')), str(path)) + shutil.copy( + str(TESTDATA.joinpath('shapes.png')), + str(tempdir.joinpath('{0}.png'.format(stem))) + ) + + # Properties are as expected + self.window.open_file(path=path) + self.assertEqual(5, self.window.model.rowCount()) + self.assertWindowTitleOpenDocument(title=stem) + self.assertFalse(self.window.model.is_modified) + @patch.object(QMessageBox, 'warning', return_value=QMessageBox.Ok) def test_open_readonly_doc(self, mock_warning): "User is warned when opening a read-only inselect document" diff --git a/inselect/tests/lib/test_document.py b/inselect/tests/lib/test_document.py index 8f3ff9e..5e7b082 100644 --- a/inselect/tests/lib/test_document.py +++ b/inselect/tests/lib/test_document.py @@ -1,6 +1,7 @@ # -*- coding: UTF-8 -*- import os import pytz +import shutil import sys import tempfile import unittest @@ -52,6 +53,23 @@ def test_load(self): with self.assertRaises(AttributeError): doc.n_items = 1 + def test_open_non_ascii(self): + "Open an inselect document with non-ascii characters in the filename" + with temp_directory_with_files() as tempdir: + stem = 'åland' + path = tempdir.joinpath('{0}.inselect'.format(stem)) + + shutil.copy(str(TESTDATA.joinpath('shapes.inselect')), str(path)) + shutil.copy( + str(TESTDATA.joinpath('shapes.png')), + str(tempdir.joinpath('{0}.png'.format(stem))) + ) + + doc = InselectDocument.load(path) + + # Properties are as expected + self.assertEqual(doc.document_path, path) + def _test_load_fails(self, contents): """Helper that writes contents to a temp file and asserts that InselectDocument.load raises. From 710637fcd701e27829a2db393073c682251a65ae Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Mon, 12 Dec 2016 10:38:46 +0000 Subject: [PATCH 2/2] [#371] Reading images from non-ascii paths is not available on Windows --- inselect/tests/gui/test_file_open.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inselect/tests/gui/test_file_open.py b/inselect/tests/gui/test_file_open.py index b989bf1..0cfef78 100644 --- a/inselect/tests/gui/test_file_open.py +++ b/inselect/tests/gui/test_file_open.py @@ -1,4 +1,5 @@ import shutil +import sys import unittest from functools import partial @@ -58,6 +59,10 @@ def test_open_doc(self): self.assertWindowTitleOpenDocument() self.assertFalse(self.window.model.is_modified) + @unittest.skipIf( + sys.platform.startswith("win"), + "Reading images from non-ascii paths is not available on Windows" + ) def test_open_non_ascii(self): "Open an inselect document with non-ascii characters in the filename" # Copy the existing 'shapes' file to a temporary with the a non-latin