-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JSONTop() == 1 and JSONbot() == 0
The == operator in `is_top` and `is_bot` causes type confusion when comparing `JSONTop()` and `JSONbot()` values. Fix it by using identity test instead of equality.
- Loading branch information
1 parent
8c85130
commit f6dbeb7
Showing
2 changed files
with
37 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from jsonsubschema._canonicalization import simplify_schema_and_embed_checkers | ||
from jsonsubschema._checkers import JSONbot, JSONtop, is_bot, is_top | ||
import unittest | ||
|
||
|
||
class TestIsTop(unittest.TestCase): | ||
def test_true_is_top(self) -> None: | ||
self.assertTrue(is_top(True)) | ||
|
||
def test_empty_object_is_top(self) -> None: | ||
self.assertTrue(is_top({})) | ||
|
||
def test_json_top_is_top(self) -> None: | ||
self.assertTrue(is_top(JSONtop())) | ||
|
||
def test_one_is_not_top(self) -> None: | ||
self.assertFalse(is_top(1)) | ||
|
||
|
||
class TestIsBot(unittest.TestCase): | ||
def test_false_is_bot(self) -> None: | ||
self.assertTrue(is_bot(False)) | ||
|
||
def test_not_empty_object_is_bot(self) -> None: | ||
self.assertTrue(is_bot({"not": {}})) | ||
|
||
def test_json_bot_is_bot(self) -> None: | ||
self.assertTrue(is_bot(JSONbot())) | ||
|
||
def test_uninhabited_schema_is_bot(self) -> None: | ||
uninhabited_schema = simplify_schema_and_embed_checkers({"type": "integer", "minimum": 2, "maximum": 1}) | ||
self.assertTrue(is_bot(uninhabited_schema)) | ||
|
||
def test_zero_is_not_bot(self) -> None: | ||
self.assertFalse(is_bot(0)) |