Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return instances of the right type when calling
clone
or casting it…
…ems in a `benedict` subclass. #115
- Loading branch information
1 parent
7a10e2c
commit 5185978
Showing
2 changed files
with
44 additions
and
3 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,39 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from benedict import benedict | ||
|
||
import unittest | ||
|
||
|
||
class subbenedict(benedict): | ||
pass | ||
|
||
|
||
class benedict_subclass_test_case(unittest.TestCase): | ||
""" | ||
This class describes a benedict subclass test case. | ||
""" | ||
|
||
def test_cast(self): | ||
d = subbenedict( | ||
{ | ||
"a": { | ||
"b": { | ||
"c": { | ||
"d": True, | ||
}, | ||
} | ||
} | ||
} | ||
) | ||
c = d["a.b.c"] | ||
self.assertTrue(issubclass(type(c), benedict)) | ||
self.assertTrue(isinstance(c, subbenedict)) | ||
self.assertEqual(c, {"d": True}) | ||
|
||
def test_clone(self): | ||
d = subbenedict({"a": True}) | ||
c = d.clone() | ||
self.assertTrue(issubclass(type(c), benedict)) | ||
self.assertTrue(isinstance(c, subbenedict)) | ||
self.assertEqual(c, {"a": True}) |