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)
Ejemplo n.º 2
0
    def make_fileitem_from_path(
        self, filename, subpath, is_annotation=False, is_shallow=False
    ) -> FileItem:
        if is_annotation and filename.endswith(self.annotation_file_suffix):
            name = filename[: -len(self.annotation_file_suffix)]
            ext = self.annotation_file_suffix
        else:
            name = filename
            ext = ""
        item = FileItem(
            subpath=subpath,
            name=name,
            ext=ext,
            type=ItemType.annotation if is_annotation else ItemType.h5ad,
        )

        if not is_annotation and not is_shallow:
            annotations = self.make_annotations_for_fileitem(item)
            item.annotations = annotations

        return item
Ejemplo n.º 3
0
 def test_GIVEN_path_no_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)
Ejemplo n.º 4
0
 def create_annotation(self, item: FileItem, name: str) -> FileItem:
     annotation = self.make_fileitem_from_path(
         name, self.get_annotations_subpath(item), is_annotation=True)
     item.annotations = (item.annotations or []).append(annotation)
     return annotation
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