11from os import path
2+ from pathlib import PurePath
3+ from urllib .parse import urlunparse
24
5+ from jsonschema_spec .handlers .file import FilePathHandler
6+ from jsonschema_spec .handlers .urllib import UrllibHandler
37import pytest
4- from urllib import request
5- from urllib .parse import urlunparse
6- from yaml import safe_load
78
8- from openapi_spec_validator import (openapi_v2_spec_validator ,
9- openapi_v30_spec_validator ,
10- openapi_v31_spec_validator )
11- from openapi_spec_validator .schemas import read_yaml_file
9+ from openapi_spec_validator import openapi_v2_spec_validator
10+ from openapi_spec_validator import openapi_v30_spec_validator
11+ from openapi_spec_validator import openapi_v31_spec_validator
1212
1313
14- def spec_url (spec_file , schema = 'file' ):
14+ def spec_file_url (spec_file , schema = 'file' ):
1515 directory = path .abspath (path .dirname (__file__ ))
1616 full_path = path .join (directory , spec_file )
1717 return urlunparse ((schema , None , full_path , None , None , None ))
@@ -20,12 +20,12 @@ def spec_url(spec_file, schema='file'):
2020def spec_from_file (spec_file ):
2121 directory = path .abspath (path .dirname (__file__ ))
2222 path_full = path .join (directory , spec_file )
23- return read_yaml_file (path_full )
23+ uri = PurePath (path_full ).as_uri ()
24+ return FilePathHandler ()(uri )
2425
2526
2627def spec_from_url (spec_url ):
27- content = request .urlopen (spec_url )
28- return safe_load (content )
28+ return UrllibHandler ("http" , "https" )(spec_url )
2929
3030
3131class Factory (dict ):
@@ -36,7 +36,7 @@ class Factory(dict):
3636@pytest .fixture
3737def factory ():
3838 return Factory (
39- spec_url = spec_url ,
39+ spec_file_url = spec_file_url ,
4040 spec_from_file = spec_from_file ,
4141 spec_from_url = spec_from_url ,
4242 )
0 commit comments