1- from bottle import ResourceManager
21import os .path
2+ import sys
33import unittest
4+ from bottle import ResourceManager
5+
6+ if sys .platform == 'win32' :
7+ TEST_PATHS = ('C:\\ foo\\ bar\\ ' , 'C:\\ foo\\ bar\\ baz' , 'C:\\ foo\\ baz\\ ..\\ bar\\ blub' )
8+ EXPECTED = ['C:\\ foo\\ bar\\ ' ]
9+ else :
10+ TEST_PATHS = ('/foo/bar/' , '/foo/bar/baz' , '/foo/baz/../bar/blub' )
11+ EXPECTED = ['/foo/bar/' ]
12+
413
514class TestResourceManager (unittest .TestCase ):
615
716 def test_path_normalize (self ):
8- tests = ('/foo/bar/' , '/foo/bar/baz' , '/foo/baz/../bar/blub' )
9- for test in tests :
17+ for test in TEST_PATHS :
1018 rm = ResourceManager ()
1119 rm .add_path (test )
12- self .assertEqual (rm .path , [ '/foo/bar/' ] )
20+ self .assertEqual (rm .path , EXPECTED )
1321
1422 def test_path_create (self ):
15- import tempfile , shutil
23+ import shutil
24+ import tempfile
1625 tempdir = tempfile .mkdtemp ()
1726 try :
1827 rm = ResourceManager ()
@@ -24,8 +33,13 @@ def test_path_create(self):
2433 shutil .rmtree (tempdir )
2534
2635 def test_path_absolutize (self ):
27- tests = ('./foo/bar/' , './foo/bar/baz' , './foo/baz/../bar/blub' )
28- abspath = os .path .abspath ('./foo/bar/' ) + os .sep
36+ if sys .platform == 'win32' :
37+ tests = ('.\\ foo\\ bar\\ ' , '.\\ foo\\ bar\\ baz' , '.\\ foo\\ baz\\ ..\\ bar\\ blub' )
38+ abspath = os .path .abspath ('.\\ foo\\ bar\\ ' ) + os .sep
39+ else :
40+ tests = ('./foo/bar/' , './foo/bar/baz' , './foo/baz/../bar/blub' )
41+ abspath = os .path .abspath ('./foo/bar/' ) + os .sep
42+
2943 for test in tests :
3044 rm = ResourceManager ()
3145 rm .add_path (test )
@@ -37,29 +51,36 @@ def test_path_absolutize(self):
3751 self .assertEqual (rm .path , [abspath ])
3852
3953 def test_path_unique (self ):
40- tests = ('/foo/bar/' , '/foo/bar/baz' , '/foo/baz/../bar/blub' )
4154 rm = ResourceManager ()
42- [rm .add_path (test ) for test in tests ]
43- self .assertEqual (rm .path , [ '/foo/bar/' ] )
55+ [rm .add_path (test ) for test in TEST_PATHS ]
56+ self .assertEqual (rm .path , EXPECTED )
4457
4558 def test_root_path (self ):
46- tests = ('/foo/bar/' , '/foo/bar/baz' , '/foo/baz/../bar/blub' )
47- for test in tests :
59+ if sys .platform == 'win32' :
60+ expected = ['C:\\ foo\\ bar\\ baz\\ ' ]
61+ else :
62+ expected = ['/foo/bar/baz/' ]
63+
64+ for test in TEST_PATHS :
4865 rm = ResourceManager ()
4966 rm .add_path ('./baz/' , test )
50- self .assertEqual (rm .path , [ '/foo/bar/baz/' ] )
67+ self .assertEqual (rm .path , expected )
5168
52- for test in tests :
69+ for test in TEST_PATHS :
5370 rm = ResourceManager ()
5471 rm .add_path ('baz/' , test )
55- self .assertEqual (rm .path , [ '/foo/bar/baz/' ] )
72+ self .assertEqual (rm .path , expected )
5673
5774 def test_path_order (self ):
5875 rm = ResourceManager ()
5976 rm .add_path ('/middle/' )
6077 rm .add_path ('/first/' , index = 0 )
6178 rm .add_path ('/last/' )
62- self .assertEqual (rm .path , ['/first/' , '/middle/' , '/last/' ])
79+
80+ if sys .platform == 'win32' :
81+ self .assertEqual (rm .path , ['C:\\ first\\ ' , 'C:\\ middle\\ ' , 'C:\\ last\\ ' ])
82+ else :
83+ self .assertEqual (rm .path , ['/first/' , '/middle/' , '/last/' ])
6384
6485 def test_get (self ):
6586 rm = ResourceManager ()
0 commit comments