Example #1
0
    def test_multipe_readers(self):
        "Test if reader conflict is resolved"
        # Testing two files with same extensions but have to be read
        # by different readers
        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        reader = registry.get_file_reader(get_example_data('thio3xx.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PolyDataReader')
    def test_multipe_readers(self):
        "Test if reader conflict is resolved"
        # Testing two files with same extensions but have to be read
        # by different readers
        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        reader = registry.get_file_reader(get_example_data('thio3xx.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PolyDataReader')
Example #3
0
 def open(self, filename, scene=None):
     """Open a file given a filename if possible in either the
     current scene or the passed `scene`.
     """
     passed_scene = scene
     reader = registry.get_file_reader(filename)
     if reader is None:
         msg = 'No suitable reader found for the file %s'%filename
         error(msg)
     else:
         src = None
         if scene is None:
             scene = self.current_scene
         if scene is None:
             scene = self.new_scene()
         try:
             sc = scene.scene
             if sc is not None:
                 sc.busy = True
             callable = reader.get_callable()
             if reader.factory is None:
                 src = callable()
                 src.initialize(filename)
             else:
                 # Factory functions are passed the filename and a
                 # reference to the engine.
                 src = callable(filename, self)
             if src is not None:
                 self.add_source(src, passed_scene)
         finally:
             if sc is not None:
                 sc.busy = False
         if src is not None:
             return src
Example #4
0
 def open(self, filename, scene=None):
     """Open a file given a filename if possible in either the
     current scene or the passed `scene`.
     """
     passed_scene = scene
     reader = registry.get_file_reader(filename)
     if reader is None:
         msg = 'No suitable reader found for the file %s'%filename
         error(msg)
     else:
         src = None
         if scene is None:
             scene = self.current_scene
         if scene is None:
             scene = self.new_scene()
         try:
             sc = scene.scene
             if sc is not None:
                 sc.busy = True
             callable = reader.get_callable()
             if reader.factory is None:
                 src = callable()
                 src.initialize(filename)
             else:
                 # Factory functions are passed the filename and a
                 # reference to the engine.
                 src = callable(filename, self)
             if src is not None:
                 self.add_source(src, passed_scene)
         finally:
             if sc is not None:
                 sc.busy = False
         if src is not None:
             return src
    def test_no_valid_reader(self):
        """Test that if there is no reader which can read the file with
        assurity, the registry returns the last one of the readers
        which dont have a can_read_test and claim to read the file with
        the given extension"""
        open_dummy = SourceMetadata(
            id="DummyFile",
            class_name="mayavi.tests.test_registry.DummyReader",
            menu_name="&PLOT3D file",
            tooltip="Open a PLOT3D data data",
            desc="Open a PLOT3D data data",
            help="Open a PLOT3D data data",
            extensions=['xyz'],
            wildcard='PLOT3D files (*.xyz)|*.xyz',
            can_read_test='mayavi.tests.test_registry:DummyReader.check_read',
            output_info=PipelineInfo(datasets=['structured_grid'],
                                     attribute_types=['any'],
                                     attributes=['any']))
        registry.sources.append(open_dummy)

        # Remove the poly data reader.
        for index, src in enumerate(registry.sources[:]):
            if src.id == 'PolyDataFile':
                poly = src
                registry.sources.remove(src)
                break

        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        # Add back the poly data reader.
        registry.sources.insert(index, poly)
        registry.sources.remove(open_dummy)
Example #6
0
    def test_no_valid_reader(self):
        """Test that if there is no reader which can read the file with
        assurity, the registry returns the last one of the readers
        which dont have a can_read_test and claim to read the file with
        the given extension"""
        open_dummy = SourceMetadata(
                id            = "DummyFile",
                class_name    = "mayavi.tests.test_registry.DummyReader",
                menu_name     = "&PLOT3D file",
                tooltip       = "Open a PLOT3D data data",
                desc        = "Open a PLOT3D data data",
                help        = "Open a PLOT3D data data",
                extensions = ['xyz'],
                wildcard = 'PLOT3D files (*.xyz)|*.xyz',
                can_read_test = 'mayavi.tests.test_registry:DummyReader.check_read',
                output_info = PipelineInfo(datasets=['structured_grid'],
                    attribute_types=['any'],
                    attributes=['any'])
                )
        registry.sources.append(open_dummy)

        # Remove the poly data reader.
        for index, src in enumerate(registry.sources[:]):
            if src.id == 'PolyDataFile':
                poly = src
                registry.sources.remove(src)
                break

        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        # Add back the poly data reader.
        registry.sources.insert(index, poly)
        registry.sources.remove(open_dummy)
    def test_multiple_valid_readers(self):
        """Test if the fixture works fine if there are multiple readers
        capable of reading the file properly"""
        # Inserting a dummy reader into the registry also capable of
        # reading files with extension 'xyz'
        open_dummy = SourceMetadata(
                id            = "DummyFile",
                class_name    = "mayavi.tests.test_registry.DummyReader",
                menu_name     = "&PLOT3D file",
                tooltip       = "Open a PLOT3D data data",
                desc        = "Open a PLOT3D data data",
                help        = "Open a PLOT3D data data",
                extensions = ['xyz'],
                wildcard = 'PLOT3D files (*.xyz)|*.xyz',
                can_read_test = 'mayavi.tests.test_registry:DummyReader.check_read',
                output_info = PipelineInfo(datasets=['structured_grid'],
                    attribute_types=['any'],
                    attributes=['any'])
                )
        registry.sources.append(open_dummy)
        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        # Removing existing readers for .xyz extensions to check if the Dummy
        # reader now reads it.
        remove = []
        for index, src in enumerate(registry.sources[:]):
            if 'xyz' in src.extensions and src.id != 'DummyFile':
                remove.append((index, src))
                registry.sources.remove(src)

        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'DummyReader')

        for index, src in remove:
            registry.sources.insert(index, src)
        registry.sources.remove(open_dummy)
 def test_unsupported_file(self):
     "Test if the mechanism to handle unsupported files works fine"
     reader = registry.get_file_reader('junk.abc')
     self.assertEqual(reader, None)
Example #9
0
 def test_unsupported_file(self):
     "Test if the mechanism to handle unsupported files works fine"
     reader = registry.get_file_reader('junk.abc')
     self.assertEqual(reader, None)