File: test_url_tools.py

package info (click to toggle)
python-fs 2.4.16-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: python: 13,048; makefile: 226; sh: 3
file content (39 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding: utf-8
"""Test url tools. """
from __future__ import unicode_literals

import platform
import unittest

from fs._url_tools import url_quote


class TestBase(unittest.TestCase):
    def test_quote(self):
        test_fixtures = [
            # test_snippet, expected
            ["foo/bar/egg/foofoo", "foo/bar/egg/foofoo"],
            ["foo/bar ha/barz", "foo/bar%20ha/barz"],
            ["example b.txt", "example%20b.txt"],
            ["exampleã„“.txt", "example%E3%84%93.txt"],
        ]
        if platform.system() == "Windows":
            test_fixtures.extend(
                [
                    ["C:\\My Documents\\test.txt", "C:/My%20Documents/test.txt"],
                    ["C:/My Documents/test.txt", "C:/My%20Documents/test.txt"],
                    # on Windows '\' is regarded as path separator
                    ["test/forward\\slash", "test/forward/slash"],
                ]
            )
        else:
            test_fixtures.extend(
                [
                    # colon:tmp is bad path under Windows
                    ["test/colon:tmp", "test/colon%3Atmp"],
                    # Unix treat \ as %5C
                    ["test/forward\\slash", "test/forward%5Cslash"],
                ]
            )
        for test_snippet, expected in test_fixtures:
            self.assertEqual(url_quote(test_snippet), expected)