Files
galaxy/test/unit/data/test_sniff_file_sources.py
T
John Chilton ac197e7f25 Refactor galaxy.files plugin + config handling.
- Downstream I want a way to load plugins from outside the ConfiguredFileSources class.
- Adds some more typing as I went in there and refactored things.
2024-04-25 13:05:02 -04:00

41 lines
1.1 KiB
Python

import os
from galaxy.datatypes import sniff
from galaxy.files.plugins import FileSourcePluginsConfig
from galaxy.files.unittest_utils import (
setup_root,
TestConfiguredFileSources,
write_file_fixtures,
)
def test_posix():
file_sources = _configured_file_sources()
as_dict = file_sources.to_dict()
assert len(as_dict["file_sources"]) == 1
file_source_as_dict = as_dict["file_sources"][0]
assert file_source_as_dict["uri_root"] == "gxfiles://test1"
_download_and_check_file(file_sources)
def _download_and_check_file(file_sources):
tmp_name = sniff.stream_url_to_file("gxfiles://test1/a", file_sources=file_sources)
try:
a_contents = open(tmp_name).read()
assert a_contents == "a\n"
finally:
os.remove(tmp_name)
def _configured_file_sources() -> TestConfiguredFileSources:
tmp, root = setup_root()
file_sources_config = FileSourcePluginsConfig()
plugin = {
"type": "posix",
}
plugin["root"] = root
write_file_fixtures(tmp, root)
file_sources = TestConfiguredFileSources(file_sources_config, conf_dict={"test1": plugin}, test_root=root)
return file_sources