11from pyswagger import utils , errs
2+ from .utils import is_windows , is_py2
23from datetime import datetime
34import unittest
45import functools
56import six
7+ import os
68
79
810class SwaggerUtilsTestCase (unittest .TestCase ):
@@ -118,10 +120,16 @@ def test_import_string(self):
118120 self .assertEqual (utils .import_string ('qoo_%^&%&' ), None )
119121 self .assertNotEqual (utils .import_string ('pyswagger' ), None )
120122
121- def test_path2url (self ):
123+ @unittest .skipUnless (not is_windows (), 'make no sense on windows' )
124+ def test_path2url_on_unix (self ):
122125 """ test path2url """
123126 self .assertEqual (utils .path2url ('/opt/local/a.json' ), 'file:///opt/local/a.json' )
124127
128+ @unittest .skipUnless (is_windows (), 'make no sense on unix' )
129+ def test_path2url_on_windows (self ):
130+ """ test path2url on windows """
131+ self .assertEqual (utils .path2url (r'C:\opt\local\a.json' ), 'file:///C:/opt/local/a.json' )
132+
125133 def test_jr_split (self ):
126134 """ test jr_split """
127135 self .assertEqual (utils .jr_split (
@@ -133,12 +141,6 @@ def test_jr_split(self):
133141 self .assertEqual (utils .jr_split (
134142 '#/definitions/s1' ), (
135143 '' , '#/definitions/s1' ))
136- self .assertEqual (utils .jr_split (
137- '/user/tmp/local/ttt' ), (
138- 'file:///user/tmp/local/ttt' , '#' ))
139- self .assertEqual (utils .jr_split (
140- '/user/tmp/local/ttt/' ), (
141- 'file:///user/tmp/local/ttt' , '#' ))
142144 # relative path should be converted to absolute one
143145 self .assertEqual (utils .jr_split (
144146 'user' ), (
@@ -150,11 +152,34 @@ def test_jr_split(self):
150152 '//' ), (
151153 '' , '#' ))
152154
155+ @unittest .skipUnless (not is_windows (), 'make no sense on windows' )
156+ def test_jr_split_on_unix (self ):
157+ """ test jr_split on unix-like os """
158+ self .assertEqual (utils .jr_split (
159+ '/user/tmp/local/ttt' ), (
160+ 'file:///user/tmp/local/ttt' , '#' ))
161+ self .assertEqual (utils .jr_split (
162+ '/user/tmp/local/ttt/' ), (
163+ 'file:///user/tmp/local/ttt' , '#' ))
164+
165+ @unittest .skipUnless (is_windows (), 'make no sense on unix' )
166+ def test_jr_split_on_windows (self ):
167+ """ test jr_split on windows """
168+ target = 'file:///C:/user/tmp/local/ttt' if is_py2 () else 'file:///c:/user/tmp/local/ttt'
169+
170+ self .assertEqual (utils .jr_split (r'C:\user\tmp\local\ttt' ), (target , '#' ))
171+ self .assertEqual (utils .jr_split (
172+ # check here for adding backslach at the end of raw string
173+ # https://pythonconquerstheuniverse.wordpress.com/2008/06/04/gotcha-%E2%80%94-backslashes-in-windows-filenames/
174+ os .path .normpath ('C:/user/tmp/local/ttt/' )
175+ ), (target , '#' ))
176+
153177 def test_cycle_guard (self ):
154178 c = utils .CycleGuard ()
155179 c .update (1 )
156180 self .assertRaises (errs .CycleDetectionError , c .update , 1 )
157181
182+ @unittest .skipUnless (not is_windows (), 'make no sense on windows' )
158183 def test_normalize_url (self ):
159184 self .assertEqual (utils .normalize_url (None ), None )
160185 self .assertEqual (utils .normalize_url ('' ), '' )
@@ -163,6 +188,10 @@ def test_normalize_url(self):
163188 self .assertEqual (utils .normalize_url ('/tmp/local/test' ), 'file:///tmp/local/test' )
164189 self .assertEqual (utils .normalize_url ('/tmp/local/test in space.txt' ), 'file:///tmp/local/test%20in%20space.txt' )
165190
191+ @unittest .skipUnless (is_windows (), 'make no sense on unix' )
192+ def test_normalize_url_on_windows (self ):
193+ self .assertEqual (utils .normalize_url (r'C:\path\to\something' ), 'file:///C:/path/to/something' )
194+
166195 def test_normalize_jr (self ):
167196 self .assertEqual (utils .normalize_jr (None ), None )
168197 self .assertEqual (utils .normalize_jr (None , 'http://test.com/api/swagger.json' ), None )
@@ -248,6 +277,7 @@ def test_url_join(self):
248277 self .assertEqual (utils .url_join ('https://localhost/test' , 'swagger.json' ), 'https://localhost/test/swagger.json' )
249278 self .assertEqual (utils .url_join ('https://localhost/test/' , 'swagger.json' ), 'https://localhost/test/swagger.json' )
250279
280+ @unittest .skipUnless (not is_windows (), 'make no sense on windows' )
251281 def test_patch_path (self ):
252282 """ make sure patch_path works
253283 """
@@ -256,6 +286,13 @@ def test_patch_path(self):
256286 '/Users/sudeep.agarwal/src/squiddy/api/v0.1/swagger.yaml' ,
257287 ), '/Users/sudeep.agarwal/src/squiddy/api/v0.1/swagger.yaml' )
258288
289+ @unittest .skipUnless (is_windows (), 'make no sense on unix-like os' )
290+ def test_patch_path_on_windows (self ):
291+ self .assertEqual (utils .patch_path (
292+ 'Users/sudeep.agarwal/src/squiddy/api/v0.1' ,
293+ 'Users/sudeep.agarwal/src/squiddy/api/v0.1/swagger.yaml' ,
294+ ), 'Users/sudeep.agarwal/src/squiddy/api/v0.1/swagger.yaml' )
295+
259296
260297class WalkTestCase (unittest .TestCase ):
261298 """ test for walk """
0 commit comments