def _pipe_modules(self): """ display modules """ self.project = expipe.require_project('project_test') modules = display_ex.modules_view(self.project) return modules
def module_teardown_setup_project_setup(): try: expipe.delete_project(PROJECT_ID, remove_all_childs=True) except NameError: pass project = expipe.require_project(PROJECT_ID) from expipe_plugin_cinpla.main import CinplaPlugin CinplaPlugin().attach_to_cli(cli) # make surgery action run_command(['register-surgery', pytest.RAT_ID, '--weight', '500', '--birthday', '21.05.2017', '--procedure', 'implantation', '-d', '21.01.2017T14:40', '-a', 'mecl', 1.9, '-a', 'mecr', 1.8]) # init adjusment run_command(['adjust', pytest.RAT_ID, '-a', 'mecl', 50, '-a', 'mecr', 50, '-d', 'now', '--init'], inp='y') yield project
def test_create_delete_project_and_childs(): module_contents = {'species': {'value': 'rat'}} project = expipe.core.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) action_module = action.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=False) project_module = project.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=False) expipe.delete_project(pytest.PROJECT_ID, remove_all_childs=True) with pytest.raises(KeyError): expipe.get_project(pytest.PROJECT_ID) # remake project, then the "old" action and project_module should be deleted project = expipe.require_project(pytest.PROJECT_ID) with pytest.raises(KeyError): project.actions[pytest.ACTION_ID] project.modules[pytest.MODULE_ID] # remake action, then the "old" action_module should be deleted action = project.require_action(pytest.ACTION_ID) with pytest.raises(KeyError): action.modules[pytest.MODULE_ID]
def _pipe_entities(self): """ display entities """ self.project = expipe.require_project('project_test') entities = display_ex.entities_view(self.project) return entities
def _pipe_actions(self): """ display actions """ self.project = expipe.require_project('project_test') actions = display_ex.actions_view(self.project) return actions
def setup_project_action(): project = expipe.require_project(PROJECT_ID) try: project.delete_action(ACTION_ID) except NameError: pass action = project.require_action(ACTION_ID) yield project, action
def teardown_setup_project(): try: expipe.delete_project(PROJECT_ID, remove_all_childs=True) except NameError: pass project = expipe.require_project(PROJECT_ID) action = project.require_action(ACTION_ID) yield project, action
def _add_metadata_to_Expipe(self, type_register, module_name, meta_key): """_add_to_Exdir """ self.project = expipe.require_project('project_test') if type_register == 'module': self.project.require_module( name=module_name, contents={meta_key: {self.metadata[meta_key]}})
def test_module_array(): import numpy as np quan = np.array([1, 2]) module_contents = {'quan': quan} project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) project_module = project.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = project_module.to_dict() assert isinstance(mod_dict['quan'], list) assert all(a == b for a, b in zip(quan, mod_dict['quan']))
def test_module_quantities(): import quantities as pq quan = [1, 2] * pq.s module_contents = {'quan': quan} project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) project_module = project.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = project_module.to_dict() assert isinstance(mod_dict['quan'], pq.Quantity) assert all(a == b for a, b in zip(quan, mod_dict['quan']))
def test_action_attr_list_dtype(): project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) for attr in ['entities', 'users', 'tags']: with pytest.raises(TypeError): setattr(action, attr, ['sub1', 'sub2', 1]) with pytest.raises(TypeError): setattr(action, attr, ['sub1', 'sub2', ['s']]) setattr(action, attr, ['sub1', 'sub2']) prop_list = getattr(action, attr) with pytest.raises(TypeError): prop_list.append(1) with pytest.raises(TypeError): prop_list.extend([1])
def test_action_messages_setter(): from datetime import datetime, timedelta project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) message_manager = action.messages assert len(message_manager) == 0 time = datetime(2017, 6, 1, 21, 42, 20) text = "my message" user = "******" msg_1 = {'text': text, 'user': user, 'datetime': time} messages = [msg_1] msg_object = action.create_message(text=text, user=user, datetime=time) assert isinstance(msg_object, expipe.core.Message) assert msg_object.text == text assert msg_object.user == user assert msg_object.datetime == time assert contain_same(messages, message_manager) text = "my new message" user = "******" msg_2 = {'text': text, 'user': user, 'datetime': time} messages.append(msg_2) msg_object = action.create_message(text=text, user=user, datetime=time) assert isinstance(msg_object, expipe.core.Message) assert msg_object.text == text assert msg_object.user == user assert msg_object.datetime == time assert contain_same(messages, message_manager) text = "updated text" user = "******" time = datetime(2019, 6, 1, 21, 42, 20) msg_object.text = text msg_object.user = user msg_object.datetime = time assert msg_object.text == text assert msg_object.user == user assert msg_object.datetime == time
def _add_file_to_Expipe(self, name, target_dir, level_dir): """_add_to_Exdir """ self.project = expipe.require_project('project_test') self.project.modules['project-module'] = { "environment": { "type": "laboratory" }, "method": { "type": "EM" } } entity = self.project.create_entity('equipment') action = self.project.create_action('acquisition') action.type = 'Collection of dataset'
def test_fill_the_project(): import quantities as pq from datetime import datetime, timedelta module_contents = {'species': {'value': 'rat'}} project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) quan = [1, 2] * pq.s module_contents = {'quan': quan} project_module = project.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = project_module.to_dict() assert isinstance(mod_dict['quan'], pq.Quantity) assert all(a == b for a, b in zip(quan, mod_dict['quan']))
def test_action_messages_dtype(): from datetime import datetime, timedelta project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) time = datetime(2017, 6, 1, 21, 42, 20) # string in date not ok msg = { 'message': 'sub2', 'user': '******', 'datetime': str(time + timedelta(minutes=10)) } with pytest.raises(TypeError): action.create_message(msg) # int not ok msg = { 'message': 'sub2', 'user': 13, 'datetime': time + timedelta(minutes=10) } with pytest.raises(TypeError): action.create_message(msg) # int not ok msg = { 'message': 12, 'user': "******", 'datetime': time + timedelta(minutes=10) } with pytest.raises(TypeError): action.create_message(msg) # None is not ok msg = { 'message': "sub2", 'user': None, 'datetime': time + timedelta(minutes=10) } with pytest.raises(TypeError): action.create_message(msg)
def test_module_list(): project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) list_cont = ['list I am', 1] project_module = project.create_module(pytest.MODULE_ID, contents=list_cont, overwrite=True) mod_dict = project_module.to_dict() assert isinstance(mod_dict, list) assert all(a == b for a, b in zip(list_cont, mod_dict)) module_contents = {'list': list_cont} project_module = project.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = project_module.to_dict() assert isinstance(mod_dict['list'], list) assert all(a == b for a, b in zip(list_cont, mod_dict['list'])) module_contents = {'is_list': {'0': 'df', '1': 'd', '2': 's'}} action_module = action.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = action_module.to_dict() assert isinstance(mod_dict['is_list'], dict) module_contents = {'almost_list1': {'0': 'df', '1': 'd', 'd': 's'}} action_module = action.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = action_module.to_dict() assert isinstance(mod_dict['almost_list1'], dict) assert module_contents == mod_dict, '{}, {}'.format( module_contents, mod_dict) module_contents = {'is_list': {0: 'df', 1: 'd', 2: 's'}} action_module = action.create_module(pytest.MODULE_ID, contents=module_contents, overwrite=True) mod_dict = action_module.to_dict() assert isinstance(mod_dict['is_list'], dict)
def test_change_message(): from datetime import datetime, timedelta project = expipe.require_project(pytest.PROJECT_ID) action = project.require_action(pytest.ACTION_ID) message_manager = action.messages time = datetime(2017, 6, 1, 21, 42, 20) # add two messages msg_1 = {'text': 'sub1', 'user': '******', 'datetime': time} msg_2 = { 'text': 'sub2', 'user': '******', 'datetime': time + timedelta(minutes=10) } action.create_message(text=msg_1["text"], user=msg_1["user"], datetime=msg_1["datetime"]) action.create_message(text=msg_2["text"], user=msg_2["user"], datetime=msg_2["datetime"]) # assert all([m1 == m2.to_dict() for m1, m2 in zip([msg_1, msg_2], message_manager)]) # change one of them msg_3 = { 'text': 'sub3', 'user': '******', 'datetime': time + timedelta(minutes=20) } for i, message in enumerate(message_manager): if message.user == "usr2": message.text = msg_3["text"] message.user = msg_3["user"] message.datetime = msg_3["datetime"] assert contain_same([msg_1, msg_3], message_manager)
# -*- coding: utf-8 -*- """ Created on Wed May 5 12:08:57 2021 @author: Benjamin """ import expipe import os project = expipe.require_project("test") action = project.require_action("something") from datetime import datetime action.tags = ['place cell', 'familiar environment'] action.datetime = datetime.now() action.location = 'here' action.type = 'Recording' action.subjects = ['rat1'] action.users = ['Peter', 'Mary'] tracking = action.require_module("tracking", template="tracking") import quantities as pq tracking_contents = {'box_shape': {'value': 'square'}} tracking_module = action.require_module(name="tracking", contents=tracking_contents) elphys_contents = { 'depth': 2 * pq.um, } elphys_module = action.require_module(name="electrophysiology", contents=elphys_contents)
def test_create_project(): expipe.require_project(pytest.PROJECT_ID)