Ejemplo n.º 1
0
 def test_recursive_disabling(self):
     list_of_elements_to_detect = self.setup_crazy_pipe()
     self.hyperpipe._pipe = Branch.prepare_photon_pipe(
         list_of_elements_to_detect)
     Hyperpipe.disable_multiprocessing_recursively(self.hyperpipe._pipe)
     self.assertTrue(
         [i.nr_of_processes == 1 for i in list_of_elements_to_detect])
Ejemplo n.º 2
0
    def test_sanity_check_pipe(self):
        test_branch = Branch('my_test_branch')

        def callback_func(X, y, **kwargs):
            pass

        with self.assertRaises(Warning):
            my_callback = CallbackElement('final_element_callback',
                                          delegate_function=callback_func)
            test_branch += my_callback
            no_callback_pipe = test_branch.prepare_photon_pipe(
                test_branch.elements)
            test_branch.sanity_check_pipeline(no_callback_pipe)
            self.assertFalse(no_callback_pipe[-1] is not my_callback)
Ejemplo n.º 3
0
    def test_prepare_photon_pipeline(self):
        test_branch = Branch('my_test_branch')
        test_branch += PipelineElement('SimpleImputer')
        test_branch += Switch('my_crazy_switch_bitch')
        test_branch += Stack('my_stacking_stack')
        test_branch += PipelineElement('SVC')

        generated_pipe = test_branch.prepare_photon_pipe(test_branch.elements)

        self.assertEqual(len(generated_pipe.named_steps), 4)
        for idx, element in enumerate(test_branch.elements):
            self.assertIs(generated_pipe.named_steps[element.name], element)
            self.assertIs(generated_pipe.elements[idx][1],
                          test_branch.elements[idx])
Ejemplo n.º 4
0
 def test_recursive_cache_folder_propagation(self):
     list_of_elements = self.setup_crazy_pipe()
     self.hyperpipe._pipe = Branch.prepare_photon_pipe(self.hyperpipe.elements)
     self.hyperpipe.recursive_cache_folder_propagation(
         self.hyperpipe._pipe, self.cache_folder_path, "fold_id_123"
     )
     for i, nmbranch in enumerate(list_of_elements):
         if i > 1:
             start_folder = os.path.join(
                 self.cache_folder_path, "branch_" + nmbranch.name
             )
         else:
             start_folder = self.cache_folder_path
         expected_folder = os.path.join(start_folder, nmbranch.name)
         self.assertEqual(nmbranch.base_element.cache_folder, expected_folder)