-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
parse
extra (optional dependencies).
- Loading branch information
1 parent
521e49a
commit 9f1d5b1
Showing
6 changed files
with
85 additions
and
10 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
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
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import unittest | ||
from datetime import datetime | ||
from decimal import Decimal | ||
from unittest.mock import patch | ||
|
||
from benedict.dicts.parse import ParseDict | ||
from benedict.exceptions import ExtrasRequireModuleNotFoundError | ||
|
||
|
||
class parse_dict_test_case(unittest.TestCase): | ||
|
@@ -185,6 +187,16 @@ def test_get_datetime_without_format(self): | |
r = datetime(2019, 5, 1, 0, 0) | ||
self.assertEqual(b.get_datetime("a"), r) | ||
|
||
@patch("benedict.dicts.parse.parse_util.parse_installed", False) | ||
def test_get_datetime_with_with_extra_not_installed(self): | ||
with self.assertRaises(ExtrasRequireModuleNotFoundError): | ||
d = { | ||
"a": "2019-05-01", | ||
} | ||
b = ParseDict(d) | ||
r = datetime(2019, 5, 1, 0, 0) | ||
self.assertEqual(b.get_datetime("a", format="%Y-%m-%d"), r) | ||
|
||
def test_get_datetime_list(self): | ||
d = { | ||
"a": ["2019-05-01", "2018-12-31", "Hello World"], | ||
|
@@ -335,6 +347,15 @@ def test_get_email(self): | |
# invalid key | ||
self.assertEqual(b.get_email("e"), "") | ||
|
||
@patch("benedict.dicts.parse.parse_util.parse_installed", False) | ||
def test_get_email_with_extra_not_installed(self): | ||
with self.assertRaises(ExtrasRequireModuleNotFoundError): | ||
d = { | ||
"a": "[email protected]", | ||
} | ||
b = ParseDict(d) | ||
b.get_email("a") | ||
|
||
def test_get_int(self): | ||
d = { | ||
"a": 1, | ||
|
@@ -504,6 +525,15 @@ def test_get_phonenumber(self): | |
p = b.get_phonenumber("z") | ||
self.assertEqual(p, {}) | ||
|
||
@patch("benedict.dicts.parse.parse_util.parse_installed", False) | ||
def test_get_phonenumber_with_extra_not_installed(self): | ||
with self.assertRaises(ExtrasRequireModuleNotFoundError): | ||
d = { | ||
"a": "3334445566", | ||
} | ||
b = ParseDict(d) | ||
b.get_phonenumber("a") | ||
|
||
def test_get_slug(self): | ||
d = { | ||
"a": " Hello World ", | ||
|
@@ -550,6 +580,15 @@ def test_get_str(self): | |
self.assertEqual(b.get_str("b"), "Hello World") | ||
self.assertEqual(b.get_str("c"), "1") | ||
|
||
@patch("benedict.dicts.parse.parse_util.parse_installed", False) | ||
def test_get_str_with_extra_not_installed(self): | ||
with self.assertRaises(ExtrasRequireModuleNotFoundError): | ||
d = { | ||
"a": "Hello World", | ||
} | ||
b = ParseDict(d) | ||
b.get_str("a") | ||
|
||
def test_get_str_fix_encoding(self): | ||
d = { | ||
"a": "Sexâ\x80\x99n Drug", | ||
|
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