本文整理汇总了Python中tvb.tests.framework.core.test_factory.TestFactory类的典型用法代码示例。如果您正苦于以下问题:Python TestFactory类的具体用法?Python TestFactory怎么用?Python TestFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
"""
Set up the context needed by the tests.
"""
self.files_helper = FilesHelper()
self.test_user = TestFactory.create_user()
self.test_project = TestFactory.create_project(self.test_user, self.PROJECT_NAME)
示例2: test_happy_flow_surface_import
def test_happy_flow_surface_import(self):
"""
Verifies the happy flow for importing a surface.
"""
dt_count_before = TestFactory.get_entity_count(self.test_project, ProjectionSurfaceEEG())
group = dao.find_group(
"tvb.adapters.uploaders.projection_matrix_importer", "ProjectionMatrixSurfaceEEGImporter"
)
importer = ABCAdapter.build_adapter(group)
file_path = os.path.join(
os.path.abspath(os.path.dirname(dataset.__file__)), "projection_eeg_65_surface_16k.npy"
)
args = {
"projection_file": file_path,
"dataset_name": "ProjectionMatrix",
"sensors": self.sensors.gid,
"surface": self.surface.gid,
DataTypeMetaData.KEY_SUBJECT: DataTypeMetaData.DEFAULT_SUBJECT,
}
FlowService().fire_operation(importer, self.test_user, self.test_project.id, **args)
dt_count_after = TestFactory.get_entity_count(self.test_project, ProjectionSurfaceEEG())
self.assertEqual(dt_count_before + 1, dt_count_after)
示例3: setUp
def setUp(self):
""" Prepare some entities to work with during tests:"""
self.flow_service = FlowService()
self.test_user = TestFactory.create_user()
self.test_project = TestFactory.create_project(admin=self.test_user)
### Insert some starting data in the database.
categ1 = model.AlgorithmCategory('one', True)
self.categ1 = dao.store_entity(categ1)
categ2 = model.AlgorithmCategory('two', rawinput=True)
self.categ2 = dao.store_entity(categ2)
group1 = model.AlgorithmGroup("test_module1", "classname1", categ1.id)
self.algo_group1 = dao.store_entity(group1)
group2 = model.AlgorithmGroup("test_module2", "classname2", categ2.id)
self.algo_group2 = dao.store_entity(group2)
group3 = model.AlgorithmGroup("test_module3", "classname3", categ1.id)
self.algo_group3 = dao.store_entity(group3)
group_v = model.AlgorithmGroup(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS, categ2.id)
self.algo_group_v = dao.store_entity(group_v)
algo_v = model.Algorithm(self.algo_group_v.id, 'ident', name='', req_data='', param_name='', output='')
self.algorithm_v = dao.store_entity(algo_v)
algo1 = model.Algorithm(self.algo_group1.id, 'id', name='', req_data='', param_name='', output='')
self.algorithm1 = dao.store_entity(algo1)
示例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:
self.assertTrue(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:
self.assertTrue(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]
self.assertEqual(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]
self.assertEqual(len(linkable), 2, "Wrong count of link-able projects!")
proj_names = [project.name for project in linkable]
self.assertTrue(test_proj[1].name in proj_names)
self.assertTrue(test_proj[2].name in proj_names)
self.assertFalse(test_proj[3].name in proj_names)
示例6: 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)
self.assertTrue(len(stored_datatypes) == 3, "DataType from all step were not stored.")
for result_row in stored_datatypes:
self.assertTrue(result_row.type in ['Datatype1', 'Datatype2'], "Wrong type was stored.")
finished, started, error, _, _ = dao.get_operation_numbers(self.test_project.id)
self.assertEqual(finished, 3, "Didn't start operations for both adapters in workflow.")
self.assertEqual(started, 0, "Some operations from workflow didn't finish.")
self.assertEqual(error, 0, "Some operations finished with error status.")
示例7: 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)
self.assertTrue(len(stored_datatypes) == 2, "DataType from second step was not stored.")
self.assertTrue(stored_datatypes[0].type == 'Datatype1', "Wrong type was stored.")
self.assertTrue(stored_datatypes[1].type == 'Datatype1', "Wrong type was stored.")
finished, started, error, _, _ = dao.get_operation_numbers(self.test_project.id)
self.assertEqual(finished, 3, "Didnt start operations for both adapters in workflow.")
self.assertEqual(started, 0, "Some operations from workflow didnt finish.")
self.assertEqual(error, 0, "Some operations finished with error status.")
示例8: test_happy_flow_import
def test_happy_flow_import(self):
"""
Test that importing a CFF generates at least one DataType in DB.
"""
ConnectivityZipTest.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())
self.assertEqual(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
self.assertTrue((reference_connectivity.centres == imported_connectivity.centres).all())
self.assertTrue((reference_connectivity.orientations == imported_connectivity.orientations).all())
self.assertEqual(reference_connectivity.number_of_regions, imported_connectivity.number_of_regions)
self.assertTrue((reference_connectivity.region_labels == imported_connectivity.region_labels).all())
self.assertFalse((reference_connectivity.weights == imported_connectivity.weights).all())
self.assertFalse((reference_connectivity.tract_lengths == imported_connectivity.tract_lengths).all())
示例9: 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)
self.assertRaises(OperationException, self._import_csv_test_connectivity,
bad_reference_connectivity.gid, TEST_SUBJECT_A)
示例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)
self.assertEqual(len(projects), 1, "Initializations failed!")
self.assertRaises(ProjectServiceException, self.project_service.remove_project, 99)
示例11: setUp
def setUp(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)
示例12: setUp
def setUp(self):
"""
Set up any additionally needed parameters.
"""
self.clean_database()
super(GenshiTestNDimensionArray, self).setUp()
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)
示例13: _import_connectivity
def _import_connectivity(self):
importer = TestFactory.create_adapter('tvb.adapters.uploaders.zip_connectivity_importer',
'ZIPConnectivityImporter')
### Launch Operation
FlowService().fire_operation(importer, self.test_user, self.test_project.id,
uploaded=self.connectivity_path, Data_Subject='QL')
self.connectivity = TestFactory.get_entity(self.test_project, Connectivity())
示例14: 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)
self.assertEqual(len(projects), (PROJECTS_PAGE_SIZE + 3) % PROJECTS_PAGE_SIZE, "Pagination inproper.")
self.assertEqual(pages, 2, 'Wrong number of pages retrieved.')
示例15: setUp
def setUp(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)