Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/371 non ascii filename #404

Merged
merged 2 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 30 additions & 3 deletions inselect/tests/gui/test_file_open.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shutil
import sys
import unittest

from functools import partial
Expand Down Expand Up @@ -39,15 +40,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"
Expand All @@ -56,6 +59,30 @@ 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
# 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"
Expand Down
18 changes: 18 additions & 0 deletions inselect/tests/lib/test_document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
import os
import pytz
import shutil
import sys
import tempfile
import unittest
Expand Down Expand Up @@ -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.
Expand Down