| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ Copyright (C) 2002-2004 TechGame Networks, LLC. |
|---|
| 4 |
##~ |
|---|
| 5 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 6 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 7 |
##~ LICENSE file included with this distribution. |
|---|
| 8 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 9 |
|
|---|
| 10 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 11 |
#~ Imports |
|---|
| 12 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 13 |
|
|---|
| 14 |
from TG.common.testPackageRunner import TestSuite, FunctionTestCase, TestCase, TestProgram |
|---|
| 15 |
|
|---|
| 16 |
from TG.w3c import uri |
|---|
| 17 |
|
|---|
| 18 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 19 |
#~ Definitions |
|---|
| 20 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
class TestURINormalization(TestSuite): |
|---|
| 23 |
baseURI = uri.URI('http://a/b/c/d;p?q#f') |
|---|
| 24 |
uriTests = """ |
|---|
| 25 |
. = |
|---|
| 26 |
./ = |
|---|
| 27 |
./. = |
|---|
| 28 |
.. = ../ |
|---|
| 29 |
../ = ../ |
|---|
| 30 |
../. = ../ |
|---|
| 31 |
../g = ../g |
|---|
| 32 |
../g/ = ../g/ |
|---|
| 33 |
../g/. = ../g/ |
|---|
| 34 |
../.. = ../../ |
|---|
| 35 |
../../ = ../../ |
|---|
| 36 |
../../. = ../../ |
|---|
| 37 |
../../g = ../../g |
|---|
| 38 |
""" |
|---|
| 39 |
uriTests = filter(None, map(str.strip, uriTests.split('\n'))) |
|---|
| 40 |
uriTests = [map(str.strip, test.split('=')) for test in uriTests] |
|---|
| 41 |
|
|---|
| 42 |
def _generateURLNormalizedPathTest(self, uriTest, uriResult): |
|---|
| 43 |
return lambda:self._testURLNormalizedPath(uriTest, uriResult) |
|---|
| 44 |
|
|---|
| 45 |
def generateTests(self): |
|---|
| 46 |
for uriTest, uriResult in self.uriTests: |
|---|
| 47 |
testfn = FunctionTestCase(self._generateURLNormalizedPathTest(uriTest, uriResult), |
|---|
| 48 |
description='URL join of %r and \'%s\' should = \'%s\' '%(self.baseURI, uriTest, uriResult)) |
|---|
| 49 |
self.addTest(testfn) |
|---|
| 50 |
|
|---|
| 51 |
def _testURLNormalizedPath(self, uriTest, uriResult): |
|---|
| 52 |
normURI = uri.URI(uriTest) |
|---|
| 53 |
normURI.normalizePath() |
|---|
| 54 |
normURI = str(normURI) |
|---|
| 55 |
if normURI != uriResult: |
|---|
| 56 |
print |
|---|
| 57 |
print 'E:', uriTest |
|---|
| 58 |
print 'T:', uriResult |
|---|
| 59 |
print '?:', normURI |
|---|
| 60 |
print 'D:', ''.join([(a==b and '1' or '0') for a,b in map(None, normURI, uriResult)]) |
|---|
| 61 |
print |
|---|
| 62 |
|
|---|
| 63 |
assert normURI == uriResult, "Joined URI does not matched prescribed URI form!" |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 67 |
#~ Unittest Main |
|---|
| 68 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 69 |
|
|---|
| 70 |
if __name__=='__main__': |
|---|
| 71 |
TestProgram() |
|---|
| 72 |
|
|---|