本文整理汇总了Python中tvb.tests.framework.core.factory.TestFactory类的典型用法代码示例。如果您正苦于以下问题:Python TestFactory类的具体用法?Python TestFactory怎么用?Python TestFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_workflow_dynamic_params
def test_workflow_dynamic_params(self):
"""
A simple test just for the fact that dynamic parameters are passed properly
between two workflow steps:
step1 - tvb.tests.framework.adapters.testadapter1.TestAdapter1
step2 - tvb.tests.framework.adapters.testadapter3.TestAdapter3
The first adapter returns a tvb.datatypes.datatype1.Datatype1 instance.
The second adapter has this passed as a dynamic workflow parameter.
We check that the steps are actually ran by checking that two operations
are created and that two dataTypes are stored.
"""
workflow_step_list = [TestFactory.create_workflow_step("tvb.tests.framework.adapters.testadapter1",
"TestAdapter1", step_index=1,
static_kwargs={"test1_val1": 1, "test1_val2": 1}),
TestFactory.create_workflow_step("tvb.tests.framework.adapters.testadapter3",
"TestAdapter3", step_index=2,
dynamic_kwargs={
"test": {wf_cfg.DATATYPE_INDEX_KEY: 0,
wf_cfg.STEP_INDEX_KEY: 1}})]
self.__create_complex_workflow(workflow_step_list)
stored_datatypes = dao.get_datatypes_in_project(self.test_project.id)
assert len(stored_datatypes) == 3, "DataType from all step were not stored."
for result_row in stored_datatypes:
assert result_row.type in ['Datatype1', 'Datatype2'], "Wrong type was stored."
finished, started, error, _, _ = dao.get_operation_numbers(self.test_project.id)
assert finished == 3, "Didn't start operations for both adapters in workflow."
assert started == 0, "Some operations from workflow didn't finish."
assert error == 0, "Some operations finished with error status."
示例2: test_workflow_generation
def test_workflow_generation(self):
"""
A simple test just for the fact that a workflow is created an ran,
no dynamic parameters are passed. In this case we create a two steps
workflow: step1 - tvb.tests.framework.adapters.testadapter2.TestAdapter2
step2 - tvb.tests.framework.adapters.testadapter1.TestAdapter1
The first adapter doesn't return anything and the second returns one
tvb.datatypes.datatype1.Datatype1 instance. We check that the steps
are actually ran by checking that two operations are created and that
one dataType is stored.
"""
workflow_step_list = [TestFactory.create_workflow_step("tvb.tests.framework.adapters.testadapter2",
"TestAdapter2", step_index=1,
static_kwargs={"test2": 2}),
TestFactory.create_workflow_step("tvb.tests.framework.adapters.testadapter1",
"TestAdapter1", step_index=2,
static_kwargs={"test1_val1": 1, "test1_val2": 1})]
self.__create_complex_workflow(workflow_step_list)
stored_datatypes = dao.get_datatypes_in_project(self.test_project.id)
assert len(stored_datatypes) == 2, "DataType from second step was not stored."
assert stored_datatypes[0].type == 'Datatype1', "Wrong type was stored."
assert stored_datatypes[1].type == 'Datatype1', "Wrong type was stored."
finished, started, error, _, _ = dao.get_operation_numbers(self.test_project.id)
assert finished == 3, "Didnt start operations for both adapters in workflow."
assert started == 0, "Some operations from workflow didnt finish."
assert error == 0, "Some operations finished with error status."
示例3: test_happy_flow_import
def test_happy_flow_import(self):
"""
Test that importing a CFF generates at least one DataType in DB.
"""
TestConnectivityZip.import_test_connectivity96(self.test_user,
self.test_project,
subject=TEST_SUBJECT_A)
field = FilterChain.datatype + '.subject'
filters = FilterChain('', [field], [TEST_SUBJECT_A], ['=='])
reference_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters)
dt_count_before = TestFactory.get_entity_count(self.test_project, Connectivity())
self._import_csv_test_connectivity(reference_connectivity.gid, TEST_SUBJECT_B)
dt_count_after = TestFactory.get_entity_count(self.test_project, Connectivity())
assert dt_count_before + 1 == dt_count_after
filters = FilterChain('', [field], [TEST_SUBJECT_B], ['like'])
imported_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters)
# check relationship between the imported connectivity and the reference
assert (reference_connectivity.centres == imported_connectivity.centres).all()
assert (reference_connectivity.orientations == imported_connectivity.orientations).all()
assert reference_connectivity.number_of_regions == imported_connectivity.number_of_regions
assert (reference_connectivity.region_labels == imported_connectivity.region_labels).all()
assert not (reference_connectivity.weights == imported_connectivity.weights).all()
assert not (reference_connectivity.tract_lengths == imported_connectivity.tract_lengths).all()
示例4: test_launch
def test_launch(self):
"""
Check that all required keys are present in output from BrainViewer launch.
"""
zip_path = os.path.join(os.path.dirname(sensors_dataset.__file__), 'eeg_unitvector_62.txt.bz2')
TestFactory.import_sensors(self.test_user, self.test_project, zip_path, 'EEG Sensors')
sensors = TestFactory.get_entity(self.test_project, SensorsEEG())
time_series = self.datatypeFactory.create_timeseries(self.connectivity, 'EEG', sensors)
viewer = EegMonitor()
result = viewer.launch(time_series)
expected_keys = ['tsNames', 'groupedLabels', 'tsModes', 'tsStateVars', 'longestChannelLength',
'label_x', 'entities', 'page_size', 'number_of_visible_points',
'extended_view', 'initialSelection', 'ag_settings', 'ag_settings']
for key in expected_keys:
assert key in result, "key not found %s" % key
expected_ag_settings = ['channelsPerSet', 'channelLabels', 'noOfChannels', 'translationStep',
'normalizedSteps', 'nan_value_found', 'baseURLS', 'pageSize',
'nrOfPages', 'timeSetPaths', 'totalLength', 'number_of_visible_points',
'extended_view', 'measurePointsSelectionGIDs']
ag_settings = json.loads(result['ag_settings'])
for key in expected_ag_settings:
assert key in ag_settings, "ag_settings should have the key %s" % key
示例5: test_get_linkable_projects
def test_get_linkable_projects(self):
"""
Test for retrieving the projects for a given user.
"""
initial_projects = self.project_service.retrieve_projects_for_user(self.test_user.id)[0]
assert len(initial_projects) == 0, "Database was not reset!"
test_proj = []
user1 = TestFactory.create_user("another_user")
for i in range(4):
test_proj.append(TestFactory.create_project(self.test_user if i < 3 else user1, 'test_proj' + str(i)))
project_storage = self.structure_helper.get_project_folder(test_proj[0])
operation = TestFactory.create_operation(test_user=self.test_user, test_project=test_proj[0])
project_storage = os.path.join(project_storage, str(operation.id))
os.makedirs(project_storage)
datatype = dao.store_entity(model.DataType(module="test_data", subject="subj1",
state="test_state", operation_id=operation.id))
linkable = self.project_service.get_linkable_projects_for_user(self.test_user.id, str(datatype.id))[0]
assert len(linkable) == 2, "Wrong count of link-able projects!"
proj_names = [project.name for project in linkable]
assert test_proj[1].name in proj_names
assert test_proj[2].name in proj_names
assert not test_proj[3].name in proj_names
示例6: test_bad_reference
def test_bad_reference(self):
TestFactory.import_cff(test_user=self.test_user, test_project=self.test_project)
field = FilterChain.datatype + '.subject'
filters = FilterChain('', [field], [TEST_SUBJECT_A], ['!='])
bad_reference_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters)
with pytest.raises(OperationException):
self._import_csv_test_connectivity(bad_reference_connectivity.gid, TEST_SUBJECT_A)
示例7: transactional_setup_method
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user and a test project, saves old configuration and imports a CFF data-set
"""
self.test_user = TestFactory.create_user()
self.test_project = TestFactory.create_project(self.test_user)
TestFactory.import_cff(test_user=self.test_user, test_project=self.test_project)
示例8: setup_method
def setup_method(self):
"""
Set up any additionally needed parameters.
"""
self.clean_database()
super(TestGenshiNDimensionArray, self).setup_method()
self.test_user = TestFactory.create_user()
self.test_project = TestFactory.create_project(self.test_user)
self.operation = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
示例9: _store_users_happy_flow
def _store_users_happy_flow(self, n_users, prefix=""):
"""
Store users in happy flow. In this case the transaction should just be commited properly and changes
should be visible in database.
:param n_users: number of users to be stored by this method
"""
for idx in range(n_users):
TestFactory.create_user(prefix + 'test_user' + str(idx), 'pass', '[email protected]', True, 'test')
示例10: test_remove_project_wrong_id
def test_remove_project_wrong_id(self):
"""
Flow for deleting a project giving an un-existing id.
"""
TestFactory.create_project(self.test_user, 'test_proj')
projects = dao.get_projects_for_user(self.test_user.id)
assert len(projects) == 1, "Initializations failed!"
with pytest.raises(ProjectServiceException):
self.project_service.remove_project(99)
示例11: setup_method
def setup_method(self):
"""
Reset the database before each test.
"""
self.clean_database()
self.flow_service = FlowService()
self.test_user = TestFactory.create_user()
self.test_project = TestFactory.create_project(admin=self.test_user)
self.operation = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
示例12: test_retrieve_projects_page2
def test_retrieve_projects_page2(self):
"""
Test for retrieving the second page projects for a given user.
"""
for i in range(PROJECTS_PAGE_SIZE + 3):
TestFactory.create_project(self.test_user, 'test_proj' + str(i))
projects, pages = self.project_service.retrieve_projects_for_user(self.test_user.id, 2)
assert len(projects) == (PROJECTS_PAGE_SIZE + 3) % PROJECTS_PAGE_SIZE, "Pagination inproper."
assert pages == 2, 'Wrong number of pages retrieved.'
示例13: transactional_setup_method
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user("UserRM")
self.test_project = TestFactory.import_default_project(self.test_user)
self.connectivity = self._get_entity(Connectivity)
self.surface = self._get_entity(CorticalSurface)
示例14: setup_method
def setup_method(self):
"""
Reset the database before each test.
"""
self.clean_database()
initialize_storage()
self.test_user = TestFactory.create_user()
self.test_project = TestFactory.create_project(self.test_user)
self.operation_service = OperationService()
self.backup_hdd_size = TvbProfile.current.MAX_DISK_SPACE
示例15: _store_users_raises_exception
def _store_users_raises_exception(self, n_users):
"""
Store users but at the end raise an exception. In case the exception is not handled up until the
transactional decorator, all changes should be rolled back.
:param n_users: number of users to be stored by this method
"""
for idx in range(n_users):
TestFactory.create_user('test_user' + str(idx), 'pass', '[email protected]', True, 'test')
raise Exception("This is just so transactional kicks in and a rollback should be done.")