Skip to content

Commit d077336

Browse files
committed
use pyfakefs for validate test
1 parent dad9eac commit d077336

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.cache
12
/.tox
23
/venv
34
__pycache__/

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
@pytest.fixture(autouse=True)
55
def etc(fs):
66
"""Use pyfakefs in every test case"""
7-
fs.add_real_directory('configs', target_path='/etc/ocf')
7+
fs.add_real_directory('configs', target_path='/etc/ocf', read_only=True)

tests/validate_test.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22
import os
33

44
import jsonschema
5-
import pytest
65
import yaml
6+
from pyfakefs.fake_filesystem_unittest import Pause
77

8-
# Disable pyfakefs
9-
@pytest.fixture
10-
def etc():
11-
pass
128

13-
14-
def test_validate():
15-
configs = yaml.safe_load(open('configs/validate.yaml')).items()
9+
def test_validate(fs):
10+
configs = yaml.safe_load(open('/etc/ocf/validate.yaml')).items()
1611

1712
for shortname, metadata in configs:
1813
schema_filename = os.path.join('schemas', metadata['schema'])
19-
config_filename = os.path.join('configs', shortname + '.yaml')
14+
config_filename = os.path.join('/etc/ocf', shortname + '.yaml')
2015

2116
# PyYAML reads YAML date objects as Python date objects, which confuses
2217
# jsonschema. To get around this, we convert the object to and from
@@ -25,6 +20,7 @@ def test_validate():
2520
json.dumps(yaml.safe_load(open(config_filename)), default=str),
2621
)
2722

28-
schema = json.load(open(schema_filename))
23+
with Pause(fs):
24+
schema = json.load(open(schema_filename))
2925

3026
jsonschema.validate(config, schema)

0 commit comments

Comments
 (0)