def test_make_fileitem_from_path_GIVEN_annotation_file_THEN_name_lacks_csv(
     self, ):
     source = FileItemSource(tempfile.gettempdir(), "local")
     item = source.make_fileitem_from_path("customanno.csv",
                                           "someh5ad_annotations", True)
     self.assertEqual(item.name, "customanno")
     self.assertEqual(item.descriptor,
                      "someh5ad_annotations/customanno.csv")
    def test_launch_GIVEN_no_stdout_THEN_throw_ProcessException(self, popen):
        subprocess = MagicMock()
        subprocess.stdout.readline().decode.return_value = ""
        subprocess.stderr.read().decode.return_value = "An unexpected error"
        popen.return_value = subprocess

        key = CacheKey(
            FileItem("/czi/", name="pbmc3k.h5ad", type=ItemType.h5ad),
            FileItemSource("/tmp", "local"),
        )
        entry = CacheEntry.for_key(key, 8000)
        from cellxgene_gateway.subprocess_backend import SubprocessBackend

        backend = SubprocessBackend()
        cellxgene_loc = "/some/cellxgene"
        scripts = [
            "http://example.com/script.js", "http://example.com/script2.js"
        ]

        with self.assertRaises(ProcessException) as context:
            backend.launch(cellxgene_loc, scripts, entry)
        popen.assert_called_once_with(
            [
                "yes | /some/cellxgene launch /tmp/czi/pbmc3k.h5ad --port 8000 --host 127.0.0.1 --disable-annotations --scripts http://example.com/script.js --scripts http://example.com/script2.js"
            ],
            shell=True,
            stderr=-1,
            stdout=-1,
        )
        self.assertEqual("An unexpected error", context.exception.stderr)
def main():
    cellxgene_data = os.environ.get("CELLXGENE_DATA", None)
    cellxgene_bucket = os.environ.get("CELLXGENE_BUCKET", None)
    #global default_item_source

    if cellxgene_bucket is not None:
        from cellxgene_gateway.items.s3.s3item_source import S3ItemSource

        item_sources.append(S3ItemSource(cellxgene_bucket, name="s3"))
        default_item_source = "s3"

    if cellxgene_data is not None:
        from cellxgene_gateway.items.file.fileitem_source import FileItemSource

        item_sources.append(FileItemSource(cellxgene_data, name="local"))
        default_item_source = "local"

    if len(item_sources) == 0:
        raise Exception("Please specify CELLXGENE_DATA or CELLXGENE_BUCKET")

    flask_util.include_source_in_url = len(item_sources) > 1

    launch()
Пример #4
0
def main():
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s:%(name)s:%(levelname)s:%(message)s",
    )
    cellxgene_data = os.environ.get("CELLXGENE_DATA", None)
    cellxgene_bucket = os.environ.get("CELLXGENE_BUCKET", None)

    if cellxgene_bucket is not None:
        from cellxgene_gateway.items.s3.s3item_source import S3ItemSource

        item_sources.append(S3ItemSource(cellxgene_bucket, name="s3"))
        default_item_source = "s3"
    if cellxgene_data is not None:
        from cellxgene_gateway.items.file.fileitem_source import FileItemSource

        item_sources.append(FileItemSource(cellxgene_data, name="local"))
        default_item_source = "local"
    if len(item_sources) == 0:
        raise Exception("Please specify CELLXGENE_DATA or CELLXGENE_BUCKET")
    flask_util.include_source_in_url = len(item_sources) > 1

    launch()
Пример #5
0
import unittest
from unittest.mock import MagicMock, patch

from cellxgene_gateway.filecrawl import render_item
from cellxgene_gateway.items.file.fileitem import FileItem
from cellxgene_gateway.items.file.fileitem_source import FileItemSource
from cellxgene_gateway.items.item import ItemType

source = FileItemSource("/tmp")


class TestRenderEntry(unittest.TestCase):
    def test_GIVEN_path_both_slash_THEN_view_has_single_slash(self):
        entry = FileItem(subpath="/somepath/",
                         name="entry",
                         type=ItemType.h5ad)
        rendered = render_item(entry, source)
        self.assertIn("view/somepath/entry/'", rendered)

    def test_GIVEN_path_starts_slash_THEN_view_has_single_slash(self):
        entry = FileItem(subpath="/somepath", name="entry", type=ItemType.h5ad)
        rendered = render_item(entry, source)
        self.assertIn("view/somepath/entry/'", rendered)

    def test_GIVEN_path_ends_slash_THEN_view_has_single_slash(self):
        entry = FileItem(subpath="somepath/", name="entry", type=ItemType.h5ad)
        rendered = render_item(entry, source)
        self.assertIn("view/somepath/entry/'", rendered)

    def test_GIVEN_path_no_slash_THEN_view_has_single_slash(self):
        entry = FileItem(subpath="somepath", name="entry", type=ItemType.h5ad)
Пример #6
0
 def test_make_fileitem_from_path_GIVEN_h5ad_file_THEN_returns_name(self):
     source = FileItemSource(tempfile.gettempdir(), "local")
     item = source.make_fileitem_from_path("someanalysis.h5ad", "studydir")
     self.assertEqual(item.name, "someanalysis.h5ad")
     self.assertEqual(item.descriptor, "studydir/someanalysis.h5ad")
import unittest

from flask import Flask

from cellxgene_gateway import flask_util
from cellxgene_gateway.cache_entry import CacheEntry, CacheEntryStatus
from cellxgene_gateway.cache_key import CacheKey
from cellxgene_gateway.gateway import app
from cellxgene_gateway.items.file.fileitem import FileItem
from cellxgene_gateway.items.file.fileitem_source import FileItemSource
from cellxgene_gateway.items.item import ItemType

key = CacheKey(
    FileItem("/czi/", name="pbmc3k.h5ad", type=ItemType.h5ad),
    FileItemSource("/tmp", "local"),
)


class TestRenderEntry(unittest.TestCase):
    def setUp(self):
        self.app = app
        self.app_context = self.app.test_request_context()
        self.app_context.push()
        self.client = self.app.test_client()

    def test_GIVEN_key_and_port_THEN_returns_loading_CacheEntry(self):
        entry = CacheEntry.for_key("some-key", 1)
        self.assertEqual(entry.status, CacheEntryStatus.loading)

    def test_GIVEN_absolute_static_url_THEN_include_path(self):
        flask_util.include_source_in_url = False
 def test_list_items_GIVEN_subpath_THEN_checks_subpath(self, listdir, path):
     stub_join(path)
     source = FileItemSource("/tmp/unittest", "local")
     source.list_items("foo")
     path.exists.assert_called_once_with("/tmp/unittest/foo")