-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some test and fix default value bug
- Loading branch information
1 parent
b8a98b5
commit a0cbd01
Showing
3 changed files
with
41 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ deps: | |
|
||
# Run tests | ||
.PHONY = test | ||
test: build | ||
test: | ||
python -m unittest discover -s ./tests -p '*_test.py' |
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,33 @@ | ||
import unittest | ||
|
||
from deepfinder import deep_find | ||
|
||
|
||
class TestFindDefault(unittest.TestCase): | ||
def test_with_basic_dict(self): | ||
""" | ||
Return default if attribute is not present | ||
""" | ||
data: dict = {'any': 'any'} | ||
result = deep_find(data, 'some', default_return='default') | ||
self.assertEqual(result, 'default') | ||
|
||
def test_with_list_and_find_all(self): | ||
""" | ||
Return empty list if does not match | ||
""" | ||
data: list = [{'any': 'any'}] | ||
result = deep_find(data, '*.some', default_return='default') | ||
self.assertEqual(result, []) | ||
|
||
def test_with_list_and_find_some(self): | ||
""" | ||
Return default if attribute is not present | ||
""" | ||
data: list = [{'any': 'any'}] | ||
result = deep_find(data, '?.some', default_return='default') | ||
self.assertEqual(result, 'default') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |