diff --git a/hepdata_validator/schema_downloader.py b/hepdata_validator/schema_downloader.py index ca45c83..a777e29 100644 --- a/hepdata_validator/schema_downloader.py +++ b/hepdata_validator/schema_downloader.py @@ -114,11 +114,18 @@ def save_locally(self, schema_name, schema_spec, overwrite=False): """ file_path = os.path.join(self.saved_schema_path, schema_name) + file_folder = os.path.dirname(file_path) # Skip download if the file exist if os.path.isfile(file_path) and not overwrite: return - os.makedirs(os.path.dirname(file_path), exist_ok=True) + # This is compatible both with Python2 and Python3 + try: + os.makedirs(file_folder) + except OSError: + if not os.path.isdir(file_folder): + raise + with open(file_path, 'w') as f: f.write(schema_spec) diff --git a/setup.py b/setup.py index 1cd9a6c..18e1a04 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ 'pytest-cov>=1.8.0', 'pytest-pep8>=1.0.6', 'coverage>=3.7.1', + 'mock>=2.0.0', ] extras_require = { diff --git a/testsuite/test_schema_downloader.py b/testsuite/test_schema_downloader.py index 2a45dfa..e161467 100644 --- a/testsuite/test_schema_downloader.py +++ b/testsuite/test_schema_downloader.py @@ -2,7 +2,7 @@ import pytest from hepdata_validator.schema_downloader import HTTPSchemaDownloader from requests.exceptions import HTTPError -from unittest.mock import patch +from mock import patch ####################################################