Example #1
0
    def test_get_brain_info_from_storage_user_model(self, mock_get_brain_info,
                                                    mock_get_all_neurons_as_dict, mock_tempfile):

        dummy_dir = "/my/temp/dir"
        mock_tempfile.mkdtemp.return_value = dummy_dir

        self.mock_storageClient_instance.clone_file.return_value = os.path.join(
            dummy_dir, "brain.py")

        bibi_original_path = os.path.join(os.path.split(
            __file__)[0], "experiments", "experiment_data", "bibi_4.bibi")
        bibi_temp_path = os.path.join(tempfile.mkdtemp(), "bibi_test.xml")
        shutil.copyfile(bibi_original_path, bibi_temp_path)

        exp_temp_path = os.path.join(os.path.split(
            __file__)[0], "experiments", "experiment_data", "test_5.exc")

        def fake_get(*args, **kwargs):
            if args[2] == 'experiment_configuration.exc':
                with open(exp_temp_path) as exp_xml:
                    return exp_xml.read()
            with open(bibi_temp_path) as bibi_xml:
                return bibi_xml.read()
        self.mock_storageClient_instance.get_file = fake_get

        dummy_populations = {'pop1': slice(0, 1, 1), 'pop2': slice(1, 2, 1)}
        mock_get_all_neurons_as_dict.return_value = dummy_populations
        with patch('hbp_nrp_backend.rest_server.__SimulationResetStorage.open', mock_open(read_data='Fake_data'), create=True) as m:
            data_from_storage, populations, _ = SimulationResetStorage._get_brain_info_from_storage(
                self.experiment_id, None)

        self.assertEqual(
            '[name: pop2\ntype: 1\nids: []\nstart: 1\nstop: 2\nstep: 1, name: pop1\ntype: 1\nids: []\nstart: 0\nstop: 1\nstep: 1]',
            str(populations).replace('\"', ''))
Example #2
0
    def test_get_brain_info_from_storage(self, mock_get_brain_info,
                                         mock_get_all_neurons_as_dict):

        dummy_dir = "/my/temp/dir"

        self.mock_storage_client.clone_file.return_value = os.path.join(
            dummy_dir, "brain.py")

        bibi_original_path = os.path.join(
            os.path.split(__file__)[0], "experiments", "experiment_data",
            "bibi_1.bibi")
        bibi_temp_path = os.path.join(tempfile.mkdtemp(), "bibi_test.xml")
        shutil.copyfile(bibi_original_path, bibi_temp_path)

        exp_temp_path = os.path.join(
            os.path.split(__file__)[0], "experiments", "experiment_data",
            "test_1.exc")

        def fake_get(*args, **kwargs):
            if args[2] == 'experiment_configuration.exc':
                with open(exp_temp_path) as exp_xml:
                    return exp_xml.read()
            with open(bibi_temp_path) as bibi_xml:
                return bibi_xml.read()

        self.mock_storage_client.get_file = fake_get

        dummy_populations = {'pop1': slice(0, 1, 1), 'pop2': slice(1, 2, 1)}
        mock_get_all_neurons_as_dict.return_value = dummy_populations

        data_from_storage, populations, _ = SimulationResetStorage._get_brain_info_from_storage(
            self.experiment_id, None)

        self.assertEqual(data_from_storage,
                         os.path.join(dummy_dir, 'brain.py'))
        self.assertEqual(
            '[name: pop2\ntype: 1\nids: []\nstart: 1\nstop: 2\nstep: 1, name: pop1\ntype: 1\nids: []\nstart: 0\nstop: 1\nstep: 1]',
            str(populations).replace('\"', ''))