-
Notifications
You must be signed in to change notification settings - Fork 149
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
Fix for #292 and changed filenamelimit #293
Open
rfelten
wants to merge
7
commits into
WikiTeam:master
Choose a base branch
from
rfelten:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
38e6974
#292: added testcase to reproduce issue
rfelten b64513e
#292: added more testcases
rfelten 10f1337
#292: refactoring: truncate filename logic at one place
rfelten 2f826ef
#292: fixed #292
rfelten f92bf8b
#292: make parameter type explicit, removed debug print
rfelten 6c2cbbb
#292: added another testcase
rfelten d638712
changed filenamelimit to 140 after bug fix filename truncation. see #292
rfelten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# This file is part of the wikiteam project. | ||
# | ||
# Copyright (C) 2017 Robert Felten - https://github.com/rfelten/ | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
import sys | ||
import os | ||
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) # q&d import hack, sorry | ||
import unittest | ||
from dumpgenerator import truncateFilename | ||
|
||
# This file is intended to test offline functionality of the dumpgenerator.py. | ||
# For all other tests see test_dumpgenerator.py | ||
|
||
|
||
class TestDumpgeneratorOffline(unittest.TestCase): | ||
|
||
def setUp(self): | ||
other = dict() # FIXME: get from dumpgenerator, but code base is a pre-OO mess | ||
other['filenamelimit'] = 140 # encryptfs reduce the filename limit from 255 to ~148 chars :/ | ||
other['imagesdescext'] = '.desc' | ||
self.other = other | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def helper_truncateFilename(self, fn): | ||
fn_trunc = truncateFilename(other=self.other, filename=fn) | ||
self.assertLessEqual(len(fn_trunc), self.other['filenamelimit'], | ||
"trunced filename '%s' len of %d exceed limit of %d." % ( | ||
fn_trunc, len(fn_trunc), self.other['filenamelimit'])) | ||
|
||
def test_truncateFilename1(self): | ||
""" Test if truncFilename() obey other['filenamelimit'] - real world example 1""" | ||
fn = u"Assortiment de différentes préparation à bases de légumes et féculents, bien sur servit avec de l'injara.JPG" | ||
self.assertEqual(len(fn), 108) | ||
self.assertEqual(len(fn.encode("utf-8")), 113) # chars like 'è' will extend length - this is maybe unexpected | ||
self.helper_truncateFilename(fn) | ||
|
||
def test_truncateFilename2(self): | ||
""" Test if truncFilename() obey other['filenamelimit'] - longest valid name w/o file extension""" | ||
fn = "A" * self.other['filenamelimit'] | ||
self.helper_truncateFilename(fn) | ||
|
||
def test_truncateFilename3(self): | ||
""" Test if truncFilename() obey other['filenamelimit'] - longest valid name w/ file extension""" | ||
fn = "A" * self.other['filenamelimit'] | ||
fn = fn[:-4] + ".jpg" | ||
self.helper_truncateFilename(fn) | ||
|
||
def test_truncateFilename4(self): | ||
""" Test if truncFilename() obey other['filenamelimit'] - valid name w/ file extension""" | ||
fn = "A" * (self.other['filenamelimit'] / 2) | ||
fn = fn[:-4] + ".jpg" | ||
self.helper_truncateFilename(fn) | ||
|
||
def test_truncateFilename5(self): | ||
""" Test if truncFilename() obey other['filenamelimit'] - longest valid name w/ file extension (unicode)""" | ||
fn = u"è" * self.other['filenamelimit'] | ||
fn = fn[:-4] + ".jpg" | ||
self.helper_truncateFilename(fn) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for inspirational quote. Wonderful poetry that summarizes
dumpgenerator.py
in a single sentence.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe, sry, could not resist ;)
I was pretty discouraged after giving up to get the configuration out of
dumpgenerator.py
:(