MCPcopy Create free account
hub / github.com/ActiveState/code / test

Function test

recipes/Python/66422_URLNorm/recipe-66422.py:94–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92
93
94def test():
95 tests = { '/foo/bar/.': '/foo/bar/',
96 '/foo/bar/./': '/foo/bar/',
97 '/foo/bar/..': '/foo/',
98 '/foo/bar/../': '/foo/',
99 '/foo/bar/../baz': '/foo/baz',
100 '/foo/bar/../..': '/',
101 '/foo/bar/../../': '/',
102 '/foo/bar/../../baz': '/baz',
103 '/foo/bar/../../../baz': '/../baz',
104 '/foo/bar/../../../../baz': '/baz',
105 '/./foo': '/foo',
106 '/../foo': '/../foo',
107 '/foo.': '/foo.',
108 '/.foo': '/.foo',
109 '/foo..': '/foo..',
110 '/..foo': '/..foo',
111 '/./../foo': '/../foo',
112 '/./foo/.': '/foo/',
113 '/foo/./bar': '/foo/bar',
114 '/foo/../bar': '/bar',
115 '/foo//': '/foo/',
116 '/foo///bar//': '/foo/bar/',
117 'http://www.foo.com:80/foo': 'http://www.foo.com/foo',
118 'http://www.foo.com:8000/foo': 'http://www.foo.com:8000/foo',
119 'http://www.foo.com./foo/bar.html': 'http://www.foo.com/foo/bar.html',
120 'http://www.foo.com.:81/foo': 'http://www.foo.com:81/foo',
121 'http://www.foo.com/%7ebar': 'http://www.foo.com/~bar',
122 'http://www.foo.com/%7Ebar': 'http://www.foo.com/~bar',
123 'ftp://user:pass@ftp.foo.net/foo/bar': 'ftp://user:pass@ftp.foo.net/foo/bar',
124 '-': '-',
125 }
126
127 n_correct, n_fail = 0, 0
128 test_keys = tests.keys()
129 test_keys.sort()
130
131 for i in test_keys:
132 print 'ORIGINAL:', i
133 cleaned = norms(i)
134
135 answer = tests[i]
136 print 'CLEANED: ', cleaned
137 print 'CORRECT: ', answer
138 if cleaned != answer:
139 print "*** TEST FAILED"
140 n_fail = n_fail + 1
141 else:
142 n_correct = n_correct + 1
143 print
144
145 print "TOTAL CORRECT:", n_correct
146 print "TOTAL FAILURE:", n_fail

Callers

nothing calls this directly

Calls 3

normsFunction · 0.85
keysMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected