Skip to content

Instantly share code, notes, and snippets.

@gazpachoking
Created February 22, 2013 04:05
Show Gist options
  • Save gazpachoking/02c741d436a0a1b4546c to your computer and use it in GitHub Desktop.
Save gazpachoking/02c741d436a0a1b4546c to your computer and use it in GitHub Desktop.
Index: tests.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tests.py (revision c327a3f81366eac3aed49e30f74676a06061d648)
+++ tests.py (revision )
@@ -6,6 +6,7 @@
import re
import sys
import json
+import subprocess
if sys.version_info[:2] < (2, 7): # pragma: no cover
import unittest2 as unittest
@@ -27,17 +28,38 @@
Draft3Validator, FormatChecker, RefResolver, validate
)
+JSONSCHEMA_SUITE_BIN = os.path.join(os.path.dirname(__file__),
+ "json", "bin", "jsonschema_suite")
+process = subprocess.Popen(
+ ["python", JSONSCHEMA_SUITE_BIN, "remotes"], stdout=subprocess.PIPE)
+output, _ = process.communicate()
+SUITE_REMOTES = json.loads(output)
+
+class MockResolver(RefResolver):
+
+ def resolve_remote(self, uri):
+ for path in SUITE_REMOTES:
+ if uri == "http://localhost:1234/" + path:
+ with mock.patch("jsonschema.requests") as requests:
+ requests.get.return_value.json.return_value = (
+ SUITE_REMOTES[path])
+ return super(MockResolver, self).resolve_remote(uri)
+
+
def make_case(schema, data, valid):
+ resolver = MockResolver.from_schema(schema)
if valid:
def test_case(self):
kwargs = getattr(self, "validator_kwargs", {})
- validate(data, schema, cls=self.validator_class, **kwargs)
+ validate(data, schema, cls=self.validator_class,
+ resolver=resolver, **kwargs)
else:
def test_case(self):
kwargs = getattr(self, "validator_kwargs", {})
with self.assertRaises(ValidationError):
- validate(data, schema, cls=self.validator_class, **kwargs)
+ validate(data, schema, cls=self.validator_class,
+ resolver=resolver, **kwargs)
return test_case
@@ -132,6 +154,8 @@
with self.assertRaises(ValidationError):
validator.validate("bar")
+
+
@load_json_cases("json/tests/draft3/*.json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment