-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switches to a package structure rather than modules. * Migrates tests to a folder and splits them into several files.
- Loading branch information
1 parent
bca1cc4
commit f21e8af
Showing
11 changed files
with
753 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from jsonref import load, loads, dump, dumps | ||
|
||
|
||
class TestApi(object): | ||
def test_loads(self): | ||
json = """{"a": 1, "b": {"$ref": "#/a"}}""" | ||
assert loads(json) == {"a": 1, "b": 1} | ||
|
||
def test_loads_kwargs(self): | ||
json = """{"a": 5.5, "b": {"$ref": "#/a"}}""" | ||
loaded = loads(json, parse_float=lambda x: int(float(x))) | ||
assert loaded["a"] == loaded["b"] == 5 | ||
|
||
def test_load(self, tmpdir): | ||
json = """{"a": 1, "b": {"$ref": "#/a"}}""" | ||
tmpdir.join("in.json").write(json) | ||
assert load(tmpdir.join("in.json")) == {"a": 1, "b": 1} | ||
|
||
def test_dumps(self): | ||
json = """[1, 2, {"$ref": "#/0"}, 3]""" | ||
loaded = loads(json) | ||
# The string version should load the reference | ||
assert str(loaded) == "[1, 2, 1, 3]" | ||
# Our dump function should write the original reference | ||
assert dumps(loaded) == json | ||
|
||
def test_dump(self, tmpdir): | ||
json = """[1, 2, {"$ref": "#/0"}, 3]""" | ||
loaded = loads(json) | ||
# The string version should load the reference | ||
assert str(loaded) == "[1, 2, 1, 3]" | ||
dump(loaded, tmpdir.join("out.json")) | ||
# Our dump function should write the original reference | ||
assert tmpdir.join("out.json").read() == json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
from unittest import mock | ||
from jsonref import jsonloader | ||
|
||
|
||
class TestJsonLoader(object): | ||
def test_it_retrieves_refs_via_requests(self): | ||
ref = "http://bar" | ||
data = {"baz": 12} | ||
|
||
with mock.patch("jsonref.requests") as requests: | ||
requests.get.return_value.json.return_value = data | ||
result = jsonloader(ref) | ||
assert result == data | ||
requests.get.assert_called_once_with("http://bar") | ||
|
||
def test_it_retrieves_refs_via_urlopen(self): | ||
ref = "http://bar" | ||
data = {"baz": 12} | ||
|
||
with mock.patch("jsonref.requests", None): | ||
with mock.patch("jsonref.urlopen") as urlopen: | ||
urlopen.return_value.__enter__.return_value.read.return_value = ( | ||
json.dumps(data).encode("utf8") | ||
) | ||
result = jsonloader(ref) | ||
assert result == data | ||
urlopen.assert_called_once_with("http://bar") |
Oops, something went wrong.