From 4b8eeaf9699ecc9d101336374e20d9a3a709aa8c Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Tue, 25 Jun 2019 15:20:42 -0700 Subject: [PATCH] more tests cases regarding wild functionality modified: README.rst modified: nested_lookup/nested_lookup.py modified: setup.py modified: test_nested_lookup.py --- README.rst | 2 +- nested_lookup/nested_lookup.py | 2 +- setup.py | 2 +- test_nested_lookup.py | 13 +++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 3fef861..b2dfdf6 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/nested_lookup/nested_lookup.py b/nested_lookup/nested_lookup.py index 698718a..1b6d44a 100644 --- a/nested_lookup/nested_lookup.py +++ b/nested_lookup/nested_lookup.py @@ -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): diff --git a/setup.py b/setup.py index ea930e8..b2681db 100644 --- a/setup.py +++ b/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(), diff --git a/test_nested_lookup.py b/test_nested_lookup.py index 32e9a57..cc9e6b5 100644 --- a/test_nested_lookup.py +++ b/test_nested_lookup.py @@ -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