OLD | NEW |
(Empty) | |
| 1 # coding: utf-8 |
| 2 |
| 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2013 Eyeo GmbH |
| 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. |
| 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. |
| 14 # |
| 15 # You should have received a copy of the GNU General Public License |
| 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
| 18 import unittest |
| 19 import re |
| 20 import sitescripts.stats.common as common |
| 21 |
| 22 class Test(unittest.TestCase): |
| 23 longMessage = True |
| 24 maxDiff = None |
| 25 |
| 26 def test_fileencoding(self): |
| 27 tests = [ |
| 28 ("foo_bar", True), |
| 29 ("1234.txt", True), |
| 30 ("xYz.DAT", True), |
| 31 ("foo/bar.txt", False), |
| 32 ("foo/bar+bas-xyz.txt", False), |
| 33 (u"foo\u1234-bar\u4321", False), |
| 34 ] |
| 35 for name, expect_identical in tests: |
| 36 path = common.filename_encode(name) |
| 37 if expect_identical: |
| 38 self.assertEqual(path, name, "Encoding '%s' shouldn't change string" % n
ame) |
| 39 else: |
| 40 self.assertTrue(re.match(r"^[\w\.\-]*$", path), "Encoding '%s' should re
place all special characters" % name) |
| 41 self.assertEqual(common.filename_decode(path), name, "Encoding and decodin
g '%s' should produce the original string" % name) |
| 42 |
| 43 if __name__ == '__main__': |
| 44 unittest.main() |
OLD | NEW |