Esempio n. 1
0
def test_call_existing_plugin(tmpfile):
    """Test that calling a reader-plugin returns a Reader instance"""
    package_name = "posetta.readers"
    plugin_name = plugins.list_all(package_name)[0]
    with open(tmpfile, mode="rb") as input_stream:
        reader = plugins.call(package_name, plugin_name, input_stream=input_stream)
    assert isinstance(reader, Reader)
Esempio n. 2
0
def read_stream(
    input_stream: IO[bytes], reader_name: Optional[str] = None, **reader_args: Any
) -> Reader:
    """Read a bytes stream with a given reader

    If the reader is not specified, an attempt to guess at an appropriate
    reader is made. A NoReaderFound error is raised if no such appropriate
    reader is found.

    Args:
        input_stream:  Stream of bytes that should be read.
        reader_name:   Name of reader that should be used.

    Returns:
        Data in stream.
    """
    if reader_name is None:
        reader_name = identify(input_stream)

    reader = plugins.call(
        package_name=__name__,
        plugin_name=reader_name,
        input_stream=input_stream,
        **reader_args,
    )
    reader.read()
    return reader
Esempio n. 3
0
def write(file_path: Union[str, pathlib.Path], writer_name: str,
          cset: CoordSet) -> None:
    """Write data to a file with a given writer

    Args:
        file_path:    Path to file that should be written.
        writer_name:  Name of writer that should be used.
        cset:         Data that should be written as a coordinate dataset.
    """
    writer = plugins.call(package_name=__name__,
                          plugin_name=writer_name,
                          file_path=file_path,
                          cset=cset)
    writer.write()
Esempio n. 4
0
def write_stream(output_stream: IO[bytes], writer_name: str, cset: CoordSet,
                 **writer_args: Any) -> None:
    """Write data to a file with a given writer

    Args:
        output_stream:  Stream of bytes to write to.
        writer_name:    Name of writer that should be used.
        cset:           Data that should be written as a coordinate dataset.
    """
    writer = plugins.call(package_name=__name__,
                          plugin_name=writer_name,
                          output_stream=output_stream,
                          cset=cset,
                          **writer_args)
    writer.write()
Esempio n. 5
0
def read(file_path: Union[str, pathlib.Path],
         reader_name: str = None) -> Reader:
    """Read a file with a given reader

    If the reader is not specified, an attempt to guess at an appropriate reader is
    made. A NoReaderFound error is raised if no such appropriate reader is found.

    Args:
        file_path:    Path to file that should be read.
        reader_name:  Name of reader that should be used.

    Returns:
        Data in file as a coordinate dataset.
    """
    if reader_name is None:
        reader_name = identify(file_path)

    reader = plugins.call(package_name=__name__,
                          plugin_name=reader_name,
                          file_path=file_path)
    reader.read()
    return reader
Esempio n. 6
0
def test_call_non_exising_plugin():
    with pytest.raises(exceptions.UnknownPluginError):
        plugins.call("posetta.lib", "non_existent")
Esempio n. 7
0
def test_call_existing_plugin():
    """Test that calling a reader-plugin returns a Reader instance"""
    package_name = "posetta.readers"
    plugin_name = plugins.list_all(package_name)[0]
    reader = plugins.call(package_name, plugin_name, file_path="test")
    assert isinstance(reader, Reader)