Skip to content

Commit a901635

Browse files
RomainTTRomain Taprest
authored andcommitted
[tests] remove external files for CLI tests
1 parent ef8c46b commit a901635

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

jsonschema/tests/json_files/instance1.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

jsonschema/tests/json_files/instance2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

jsonschema/tests/json_files/schema1.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

jsonschema/tests/json_files/schema2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

jsonschema/tests/test_cli.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from jsonschema.compat import NativeIO
99
from jsonschema.exceptions import SchemaError
1010

11-
JSON_DIR_PATH = os.path.join(os.path.dirname(__file__), "json_files")
1211

1312
def fake_validator(*errors):
1413
errors = list(reversed(errors))
@@ -70,15 +69,40 @@ def test_find_validator_in_jsonschema(self):
7069

7170

7271
class TestCLI(TestCase):
72+
instance_file_1 = "foo1.json"
73+
instance_file_2 = "foo2.json"
74+
schema_file = "schema.json"
75+
76+
def setUp(self):
77+
cli.open = self.fake_open
78+
self.addCleanup(delattr, cli, "open")
79+
80+
def fake_open(self, path):
81+
if path == self.instance_file_1:
82+
contents = "1"
83+
elif path == self.instance_file_2:
84+
contents = "25"
85+
elif path == self.schema_file:
86+
contents = """
87+
{
88+
"anyOf": [
89+
{"minimum": 20},
90+
{"type": "string"},
91+
{"required": true}
92+
]
93+
}
94+
"""
95+
else: # pragma: no cover
96+
self.fail("What is {!r}".format(path))
97+
return NativeIO(contents)
98+
7399
def test_draft3_schema_draft4_validator(self):
74100
stdout, stderr = NativeIO(), NativeIO()
75101
exit_code = cli.run(
76102
{
77103
"validator": Draft4Validator,
78-
"schema": os.path.join(JSON_DIR_PATH, "schema1.json"),
79-
"instances": [
80-
os.path.join(JSON_DIR_PATH, "instance1.json"),
81-
],
104+
"schema": "schema.json",
105+
"instances": ["foo1.json"],
82106
"error_format": "{error.message}",
83107
"output": "plain",
84108
},
@@ -94,10 +118,8 @@ def test_successful_validation(self):
94118
exit_code = cli.run(
95119
{
96120
"validator": fake_validator(),
97-
"schema": os.path.join(JSON_DIR_PATH, "schema2.json"),
98-
"instances": [
99-
os.path.join(JSON_DIR_PATH, "instance2.json"),
100-
],
121+
"schema": "schema.json",
122+
"instances": ["foo2.json"],
101123
"error_format": "{error.message}",
102124
"output": "plain",
103125
},
@@ -114,10 +136,8 @@ def test_unsuccessful_validation(self):
114136
exit_code = cli.run(
115137
{
116138
"validator": fake_validator([error]),
117-
"schema": os.path.join(JSON_DIR_PATH, "schema2.json"),
118-
"instances": [
119-
os.path.join(JSON_DIR_PATH, "instance1.json"),
120-
],
139+
"schema": "schema.json",
140+
"instances": ["foo1.json"],
121141
"error_format": "{error.instance} - {error.message}",
122142
"output": "plain",
123143
},
@@ -138,11 +158,8 @@ def test_unsuccessful_validation_multiple_instances(self):
138158
exit_code = cli.run(
139159
{
140160
"validator": fake_validator(first_errors, second_errors),
141-
"schema": os.path.join(JSON_DIR_PATH, "schema2.json"),
142-
"instances": [
143-
os.path.join(JSON_DIR_PATH, "instance1.json"),
144-
os.path.join(JSON_DIR_PATH, "instance2.json"),
145-
],
161+
"schema": "schema.json",
162+
"instances": ["foo1.json", "foo2.json"],
146163
"error_format": "{error.instance} - {error.message}",
147164
"output": "plain",
148165
},
@@ -173,7 +190,7 @@ def test_piping(self):
173190
exit_code = cli.run(
174191
{
175192
"validator": fake_validator(),
176-
"schema": os.path.join(JSON_DIR_PATH, "schema2.json"),
193+
"schema": "schema.json",
177194
"instances": [],
178195
"error_format": "{error.message}",
179196
"output": "plain",

0 commit comments

Comments
 (0)