From 94c63bba452089db4ddc680886f6afa266d2873f Mon Sep 17 00:00:00 2001 From: Javier Parada Date: Sun, 11 Apr 2021 10:42:40 +0200 Subject: [PATCH] add more tests. --- tests/unit/deep_get_by_type_test.py | 45 +++++++++++++++++++ ..._test.py => deep_get_find_in_deep_test.py} | 18 +++++++- 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 tests/unit/deep_get_by_type_test.py rename tests/unit/{deep_get_find_test.py => deep_get_find_in_deep_test.py} (64%) diff --git a/tests/unit/deep_get_by_type_test.py b/tests/unit/deep_get_by_type_test.py new file mode 100644 index 0000000..bbb355e --- /dev/null +++ b/tests/unit/deep_get_by_type_test.py @@ -0,0 +1,45 @@ +import unittest + +from deepgetter.deep_get import deep_get + + +class TestGetByType(unittest.TestCase): + def test_with_basic_number(self): + """ + Test basic number + """ + data: int = 39 + result = deep_get(data, '') + self.assertEqual(result, 39) + + def test_with_number_in_dict(self): + """ + Test basic number inside structure + """ + data: dict = { + 'value': 39, + } + result = deep_get(data, 'value') + self.assertEqual(result, 39) + + def test_with_basic_str(self): + """ + Test basic string + """ + data: str = 'test str' + result = deep_get(data, '') + self.assertEqual(result, 'test str') + + def test_with_str_in_dict(self): + """ + Test basic string inside structure + """ + data: dict = { + 'value': 'test str', + } + result = deep_get(data, 'value') + self.assertEqual(result, 'test str') + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/deep_get_find_test.py b/tests/unit/deep_get_find_in_deep_test.py similarity index 64% rename from tests/unit/deep_get_find_test.py rename to tests/unit/deep_get_find_in_deep_test.py index 91f0fdc..459598e 100644 --- a/tests/unit/deep_get_find_test.py +++ b/tests/unit/deep_get_find_in_deep_test.py @@ -3,7 +3,7 @@ from deepgetter.deep_get import deep_get -class TestSum(unittest.TestCase): +class TestFindInDeep(unittest.TestCase): def test_dict_with_0_lvl(self): """ Test basic dictionary with no profundity level. @@ -26,7 +26,7 @@ def test_dict_with_1_lvl(self): def test_dict_with_2_lvl(self): """ - Test basic dictionary with two profundity levels. + Test basic dictionary with 2 profundity levels. """ data: dict = { 'value': { @@ -36,6 +36,20 @@ def test_dict_with_2_lvl(self): result = deep_get(data, 'value.subdata') self.assertEqual(result, 39) + def test_dict_with_3_lvl(self): + """ + Test basic dictionary with 3 profundity levels. + """ + data: dict = { + 'value': { + 'sub-data': { + 'sub-sub-data': 39, + }, + }, + } + result = deep_get(data, 'value.sub-data.sub-sub-data') + self.assertEqual(result, 39) + if __name__ == '__main__': unittest.main()