コード例 #1
0
    def test_deep_find_all_with_nothing_found(self):
        with self.subTest('With dict'):
            result_list = deep_find_all({'a': 1, 1: 'a'}, 'apple')

            self.assertEqual(result_list, [])

        with self.subTest('With list'):
            result_list = deep_find_all([{'a': 1, 1: 'a'}, 'Anton'], 'apple')

            self.assertEqual(result_list, [])
コード例 #2
0
    def test_deep_find_all_dict_with_nested_lists(self):
        result_list = deep_find_all(self.dict_with_nested_lists, 'apple')

        self.assertEqual(type(result_list), list)
        self.assertEqual(len(result_list), 2)
        self.assertTrue(3 in result_list)
        self.assertTrue(42 in result_list)
コード例 #3
0
 def test_if_a_key_which_is_a_dict_returns_the_result(self):
     example_dict2 = {
         'a': {
             'a1': 3,
             'a2': 5,
             'a3': 6
         },
         'b': {
             'a': {
                 'a4': 'woohoo',
                 'a5': 'C'
             }
         }
     }
     expected_result2 = [{
         'a1': 3,
         'a2': 5,
         'a3': 6
     }, {
         'a4': 'woohoo',
         'a5': 'C'
     }]
     self.assertEqual(deep_find_all(example_dict2, 'a'), expected_result2)
コード例 #4
0
 def test_if_a_dict_with_simple_values_like_int_gives_expected_answer(self):
     example_dict = {'a': 3, 'b': {'a': 5}}
     expected_result = [3, 5]
     self.assertEqual(deep_find_all(example_dict, 'a'), expected_result)
コード例 #5
0
 def test_if_a_simple_dict_returns_expected_answer(self):
     example_dict = {'a': 3, 'b': {'a': 5}}
     expected_dict = {'a': 2, 'b': {'a': 2}}
     deep_find_all(example_dict, 'a', 2)
     self.assertEqual(example_dict, expected_result2)
コード例 #6
0
    def test_deep_find_all_list_with_dicts(self):
        result_list = deep_find_all(self.list_with_dicts, 'apple')

        self.assertEqual(result_list, [42])
コード例 #7
0
 def test_deep_find_all_with_no_key_found(self):
     key = "Z"
     result = []
     self.assertEqual(graphs.deep_find_all(self.data_all, key), result)
コード例 #8
0
 def test_deep_find_all(self):
     key = "b"
     result = [{"a": 20}, [{"a": 30}, {"b": 40}]]
     self.assertEqual(graphs.deep_find_all(self.data_all, key), result)
コード例 #9
0
 def test_deep_find_all_shoud_return_all_values_of_given_key(self):
     key = "a"
     result = [10, 20, 30]
     self.assertEqual(graphs.deep_find_all(self.data_all, key), result)