Ejemplo n.º 1
0
 def test_path_not_found_set_default(self):
     result_c = getp({"test": {
         "test2": [{
             "test3": 7
         }]
     }}, "test/test.2/0/test3", "/", 1)
     self.assertEqual(result_c, 1)
Ejemplo n.º 2
0
 def test_get_from_path_with_list(self):
     result_c = getp({"test": {
         "test2": [{
             "test3": 1
         }]
     }}, "test.test2.0.test3")
     self.assertEqual(result_c, 1)
Ejemplo n.º 3
0
 def test_get_from_path_with_different_separator(self):
     result_c = getp({"test": {
         "test.2": [{
             "test3": 1
         }]
     }}, "test/test.2/0/test3", "/")
     self.assertEqual(result_c, 1)
Ejemplo n.º 4
0
    def test_both_versions_give_the_same_results_and_display_speed_comparison(
            self):
        nested_dict = {}
        path = self.nest_dict(nested_dict, 100, "path", "")

        now = time.time()
        result_c = getp(nested_dict, path)
        c_ext_time = time.time() - now

        now = time.time()
        result_python = getfp(nested_dict, path)
        python_time = time.time() - now

        logger.error(f"C extension is {python_time / c_ext_time} times faster")
        self.assertEqual(result_python, result_c)
Ejemplo n.º 5
0
 def test_get_integer_from_path(self):
     result_c = getp({"test": 1}, "test")
     self.assertEqual(result_c, 1)
Ejemplo n.º 6
0
 def test_one_argument_raises_exception(self):
     with self.assertRaises(Exception):
         getp({"test": 2})
Ejemplo n.º 7
0
 def test_no_arguments_raises_exception(self):
     with self.assertRaises(Exception):
         getp()