more tests cases regarding wild functionality
modified: README.rst modified: nested_lookup/nested_lookup.py modified: setup.py modified: test_nested_lookup.py
This commit is contained in:
parent
b6acaca980
commit
4b8eeaf969
4 changed files with 14 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
nested_lookup
|
||||
#############
|
||||
|
||||
.. image:: https://img.shields.io/badge/pypi-0.2.16-green.svg
|
||||
.. image:: https://img.shields.io/badge/pypi-0.2.17-green.svg
|
||||
:target: https://pypi.python.org/pypi/nested-lookup
|
||||
.. image:: https://travis-ci.org/rameshrvr/nested-lookup.svg?branch=master
|
||||
:target: https://travis-ci.org/rameshrvr/nested-lookup
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ def nested_lookup(key, document, wild=False, with_keys=False):
|
|||
|
||||
def _is_case_insensitive_substring(a, b):
|
||||
"""return True if `a` is a case insensitive substring of `b`, else False"""
|
||||
return isinstance(a, str) and isinstance(b, str) and a.lower() in b.lower()
|
||||
return str(a).lower() in str(b).lower()
|
||||
|
||||
|
||||
def _nested_lookup(key, document, wild=False, with_keys=False):
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -17,7 +17,7 @@ with open("requirements.txt", "r") as f:
|
|||
|
||||
setup(
|
||||
name="nested-lookup",
|
||||
version="0.2.16",
|
||||
version="0.2.17",
|
||||
description="Python functions for working with deeply nested documents (lists and dicts) ",
|
||||
keywords="nested document dictionary dict list lookup schema json xml yaml",
|
||||
long_description=open("README.rst").read(),
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TestNestedLookup(TestCase):
|
|||
"name": "Test",
|
||||
"date": "YYYY-MM-DD HH:MM:SS",
|
||||
}
|
||||
self.subject_dict4 = {1: "a", 2: {"b": 44, "C": 55}, 3: "d", 4: "e"}
|
||||
self.subject_dict4 = {1: "a", 2: {"b": 44, "C": 55}, 3: "d", 4: "e", "6776": "works"}
|
||||
|
||||
def test_nested_lookup(self):
|
||||
results = nested_lookup("d", self.subject_dict)
|
||||
|
|
@ -68,6 +68,10 @@ class TestNestedLookup(TestCase):
|
|||
self.assertIn(200, results)
|
||||
self.assertSetEqual({100, 200}, set(results))
|
||||
|
||||
def test_nested_lookup_key_is_non_str(self):
|
||||
results = nested_lookup(key=4, document=self.subject_dict4)
|
||||
self.assertIn("e", results)
|
||||
|
||||
def test_wild_nested_lookup(self):
|
||||
results = nested_lookup(key="mail", document=self.subject_dict2, wild=True)
|
||||
self.assertEqual(4, len(results))
|
||||
|
|
@ -75,10 +79,15 @@ class TestNestedLookup(TestCase):
|
|||
self.assertIn("test2@example.com", results)
|
||||
self.assertIn("test3@example.com", results)
|
||||
|
||||
# test that wild works with a document that has integers as keys.
|
||||
def test_wild_nested_lookup_integer_keys_in_document(self):
|
||||
results = nested_lookup(key="c", document=self.subject_dict4, wild=True)
|
||||
self.assertIn(55, results)
|
||||
|
||||
def test_wild_nested_lookup_integer_key_as_substring(self):
|
||||
# test that wild works converts integers into strings before substring matching.
|
||||
results = nested_lookup(key=77, document=self.subject_dict4, wild=True)
|
||||
self.assertIn("works", results)
|
||||
|
||||
def test_wild_with_keys_nested_lookup(self):
|
||||
matches = nested_lookup(
|
||||
key="mail", document=self.subject_dict2, wild=True, with_keys=True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue