2
2
import jsonschema
3
3
import os
4
4
import json
5
+ import unittest
6
+ from pathlib import Path
5
7
6
8
from functools import partial
7
9
from contextlib import contextmanager
24
26
"user" : {"foo" : "1" },
25
27
"c" : 3 , "bar" : True , "z" : 4 }
26
28
27
- # expected config after updade by user
29
+ # expected config after update by user
28
30
UPDATED_CONFIG = {"a" : 1 , "b" : 2 , "h" : 2 ,
29
31
"user" : {"foo" : "bar" },
30
32
"c" : 3 , "bar" : True , "z" : 4 }
31
33
32
34
# the schema does not cover extra fields, so users can pass
33
- # wathever they want
35
+ # whatever they want
34
36
SCHEMA = {
35
37
"$schema" : "http://json-schema.org/draft-04/schema#" ,
36
38
"type" : "object" ,
60
62
]
61
63
}
62
64
63
- # schema updaed by adding custom fileds by the
65
+ # schema updated by adding custom fields by the
64
66
UPDATED_SCHEMA = {
65
67
"$schema" : "http://json-schema.org/draft-04/schema#" ,
66
68
"type" : "object" ,
125
127
Config .schema_default_file_name : SCHEMA ,
126
128
}
127
129
128
- # in this case the home config is messging up a type
130
+ # in this case the home config is messing up a type
129
131
BAD_CONFIG_MAP = {Config .default_file_name : {"z" : 1 , "a" : 1 , "b" : 0 },
130
132
ENV_KEY : {"z" : 3 , "h" : 2 , "user" : {"foo" : 1 }},
131
133
Config .home_file_name : {"z" : 3 , "b" : "2" , "user" : "foo" },
138
140
139
141
140
142
@contextmanager
141
- def default_config (user_config : Optional [str ]= None ):
143
+ def default_config (user_config : Optional [str ] = None ):
142
144
"""
143
145
Context manager to temporarily establish default config settings.
144
- This is achieved by overwritting the config paths of the user-,
146
+ This is achieved by overwriting the config paths of the user-,
145
147
environment-, and current directory-config files with the path of the
146
148
config file in the qcodes repository.
147
149
Additionally the current config object `qcodes.config` gets copied and
@@ -230,6 +232,9 @@ def test_missing_config_file(self):
230
232
@patch .object (Config , 'env_file_name' , new_callable = PropertyMock )
231
233
@patch .object (Config , 'load_config' )
232
234
@patch ('os.path.isfile' )
235
+ @unittest .skipIf (Path .cwd () == Path .home (),
236
+ 'This test requires that working dir is different from'
237
+ 'homedir.' )
233
238
def test_default_config_files (self , isfile , load_config , env , schema ):
234
239
# don't try to load custom schemas
235
240
self .conf .schema_cwd_file_name = None
@@ -247,6 +252,9 @@ def test_default_config_files(self, isfile, load_config, env, schema):
247
252
@patch .object (Config , 'env_file_name' , new_callable = PropertyMock )
248
253
@patch .object (Config , 'load_config' )
249
254
@patch ('os.path.isfile' )
255
+ @unittest .skipIf (Path .cwd () == Path .home (),
256
+ 'This test requires that working dir is different from'
257
+ 'homedir.' )
250
258
def test_bad_config_files (self , isfile , load_config , env , schema ):
251
259
# don't try to load custom schemas
252
260
self .conf .schema_cwd_file_name = None
@@ -265,6 +273,9 @@ def test_bad_config_files(self, isfile, load_config, env, schema):
265
273
@patch .object (Config , 'load_config' )
266
274
@patch ('os.path.isfile' )
267
275
@patch ("builtins.open" , mock_open (read_data = USER_SCHEMA ))
276
+ @unittest .skipIf (Path .cwd () == Path .home (),
277
+ 'This test requires that working dir is different from'
278
+ 'homedir.' )
268
279
def test_user_schema (self , isfile , load_config , env , schema ):
269
280
schema .return_value = copy .deepcopy (SCHEMA )
270
281
env .return_value = ENV_KEY
0 commit comments