コード例 #1
0
 def test_create_api_from_dictionary(self):
     """Test creating the processor instance with properties parameter
     instead of api.
     """
     processor = VizualTaskProcessor(
         properties={
             PROPERTY_API:
             ClassLoader.to_dict(
                 module_name='vizier.engine.packages.vizual.api.fs',
                 class_name='DefaultVizualApi')
         })
     fh = self.filestore.upload_file(CSV_FILE)
     cmd = vizual.load_dataset(dataset_name=DATASET_NAME,
                               file={pckg.FILE_ID: fh.identifier},
                               validate=True)
     result = processor.compute(command_id=cmd.command_id,
                                arguments=cmd.arguments,
                                context=TaskContext(
                                    project_id=5,
                                    datastore=self.datastore,
                                    filestore=self.filestore,
                                    artifacts={}))
     self.assertIsNotNone(result.provenance.write)
     self.assertTrue(DATASET_NAME in result.provenance.write)
     dataset_id = result.provenance.write[DATASET_NAME].identifier
     self.assertTrue(result.provenance.read is None
                     or len(result.provenance.read) == 0)
     self.assertIsNotNone(result.provenance.resources)
     self.assertEqual(result.provenance.resources[RESOURCE_DATASET],
                      dataset_id)
コード例 #2
0
 def test_serialize_and_create(self):
     """Test creating a class loader instance from a dictionary."""
     loader = ClassLoader(
         values=ClassLoader.to_dict(
             module_name='ABC',
             class_name='DEF',
             properties={'A': 1}
         )
     )
     self.assertEqual(loader.module_name, 'ABC')
     self.assertEqual(loader.class_name, 'DEF')
     self.assertEqual(loader.properties['A'], 1)
     # No properties given
     loader = ClassLoader(
         values=ClassLoader.to_dict(
             module_name='ABC',
             class_name='DEF'
         )
     )
     self.assertEqual(loader.module_name, 'ABC')
     self.assertEqual(loader.class_name, 'DEF')
     self.assertIsNone(loader.properties)
     # Errors for invalid dictionaries
     values = ClassLoader.to_dict(
         module_name='ABC',
         class_name='DEF',
         properties={'A': 1}
     )
     del values['moduleName']
     with self.assertRaises(ValueError):
         ClassLoader(values=values)
     values = ClassLoader.to_dict(
         module_name='ABC',
         class_name='DEF',
         properties={'A': 1}
     )
     del values['className']
     with self.assertRaises(ValueError):
         ClassLoader(values=values)
コード例 #3
0
 def test_create_instance(self):
     """Test creating an instance from a class loader."""
     # Create instance of plot processor
     loader = ClassLoader(
         values=ClassLoader.to_dict(
             module_name='vizier.engine.packages.plot.processor',
             class_name='PlotProcessor'
         )
     )
     engine = loader.get_instance()
     from vizier.engine.packages.plot.processor import PlotProcessor
     self.assertTrue(isinstance(engine, PlotProcessor))
     with self.assertRaises(ValueError):
         engine.compute(command_id='ABC', arguments=None, context=None)
     loader = ClassLoader(
         values=ClassLoader.to_dict(
             module_name='vizier.core.loader',
             class_name='DummyClass',
             properties={'A': 1}
         )
     )
     dummy = loader.get_instance(names=['X', 'Y', 'Z'])
     self.assertEqual(dummy.properties['A'], 1)
     self.assertEqual(dummy.names, ['X', 'Y', 'Z'])