Ejemplo n.º 1
0
def test_data_file_class():
    dd = DataResolver(data_descriptors={"foo": {
        "class": "bar",
        "value": 1
    }},
                      user_config=UserConfiguration())
    assert dd.resolve("foo") == 1
Ejemplo n.º 2
0
def test_data_resolver_create_from_url():
    with tempdir() as d:
        resolver = DataResolver(
            {"foo": {
                "url": GOOD_URL,
                "path": "dir1/dir2/sample.vcf"
            }}, UserConfiguration(None, cache_dir=d))
        foo = resolver.resolve("foo")
        assert foo.path == d / "dir1" / "dir2" / "sample.vcf"
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"

    with tempdir() as d:
        resolver = DataResolver(
            {"foo": {
                "url": GOOD_URL,
                "name": "sample.vcf"
            }}, UserConfiguration(None, cache_dir=d))
        foo = resolver.resolve("foo")
        assert foo.path == d / "sample.vcf"
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"

    with tempdir() as d:
        resolver = DataResolver({"foo": {
            "url": GOOD_URL
        }}, UserConfiguration(None, cache_dir=d))
        foo = resolver.resolve("foo")
        assert foo.path == d / "test_file"
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"
Ejemplo n.º 3
0
def test_data_resolver_create_from_contents():
    with tempdir() as d:
        resolver = DataResolver(
            {"foo": {
                "path": "dir1/dir2/foo.txt",
                "contents": "foo"
            }}, UserConfiguration(None, cache_dir=d))
        parent = d / "dir1" / "dir2"
        foo = resolver.resolve("foo")
        assert foo.path == parent / "foo.txt"
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"

    with tempdir() as d:
        resolver = DataResolver(
            {"foo": {
                "name": "foo.txt",
                "contents": "foo"
            }}, UserConfiguration(None, cache_dir=d))
        foo = resolver.resolve("foo")
        assert foo.path == d / "foo.txt"
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"

    with tempdir() as d:
        resolver = DataResolver({"foo": {
            "contents": "foo"
        }}, UserConfiguration(None, cache_dir=d))
        foo = resolver.resolve("foo")
        assert foo.path.parent == d
        assert foo.path.exists()
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"
Ejemplo n.º 4
0
    def runtest(self):
        # Get/create DataManager
        if self._data:
            config = self._fixture_request.getfixturevalue("user_config")
            data_resolver = DataResolver(self._data, config)
            data_dirs = DataDirs(
                ensure_path(self._fixture_request.fspath.dirpath(),
                            canonicalize=True),
                function=self.name,
                module=None,  # TODO: support a top-level key for module name
                cls=None,  # TODO: support test groupings
            )
            workflow_data = DataManager(data_resolver, data_dirs)
        else:
            workflow_data = self._fixture_request.getfixturevalue(
                "workflow_data")

        # Build the arguments to workflow_runner
        workflow_runner_kwargs = self._workflow_runner_kwargs

        # Resolve test data requests in the inputs and outputs

        if self._inputs:
            workflow_runner_kwargs["inputs"] = _resolve_test_data(
                self._inputs, workflow_data)

        if self._expected:
            workflow_runner_kwargs["expected"] = _resolve_test_data(
                self._expected, workflow_data)

        # Run the test
        workflow_runner = self._fixture_request.getfixturevalue(
            "workflow_runner")

        return workflow_runner(self._wdl, **workflow_runner_kwargs)
Ejemplo n.º 5
0
def workflow_data_resolver(workflow_data_descriptors: dict,
                           user_config: UserConfiguration) -> DataResolver:
    """
    Provides access to test data files for tests in a module.

    Args:
        workflow_data_descriptors: workflow_data_descriptors fixture.
        user_config:
    """
    return DataResolver(workflow_data_descriptors, user_config)
Ejemplo n.º 6
0
def test_data_manager():
    dm = DataManager(data_resolver=DataResolver(
        {
            "foo": {
                "class": "x",
                "value": 1
            },
            "bar": {
                "class": "x",
                "value": 2
            }
        }, UserConfiguration()),
                     datadirs=None)
    assert [1, 2] == dm.get_list("foo", "bar")
    assert {"foo": 1, "bork": 2} == dm.get_dict("foo", bork="bar")
Ejemplo n.º 7
0
def test_data_resolver_create_from_datadir():
    with tempdir() as d, tempdir() as d1:
        mod = Mock()
        mod.__name__ = "foo.bar"
        cls = Mock()
        cls.__name__ = "baz"
        fun = Mock()
        fun.__name__ = "blorf"
        mod_cls_fun = d / "foo" / "bar" / "baz" / "blorf"
        mod_cls_fun.mkdir(parents=True)
        data_mod_cls_fun = d / "data" / "foo" / "bar" / "baz" / "blorf"
        data_mod_cls_fun.mkdir(parents=True)
        dd = DataDirs(d / "foo", mod, fun, cls)

        resolver = DataResolver(
            {
                "boink": {
                    "name": "boink.txt",
                },
                "bobble": {
                    "name": "bobble.txt"
                },
                "burp": {
                    "name": "burp.txt",
                    "path": "burp.txt"
                }
            }, UserConfiguration(None, cache_dir=d1))
        boink = d / "foo" / "bar" / "boink.txt"
        with open(boink, "wt") as out:
            out.write("boink")
        assert boink == resolver.resolve("boink", dd).path

        with pytest.raises(FileNotFoundError):
            resolver.resolve("bobble", dd)

        burp = d / "foo" / "bar" / "burp.txt"
        with open(burp, "wt") as out:
            out.write("burp")
        burp_resolved = resolver.resolve("burp", dd).path
        assert burp_resolved == d1 / "burp.txt"
        assert burp_resolved.is_symlink()

        with pytest.raises(FileNotFoundError):
            resolver.resolve("bobble")
Ejemplo n.º 8
0
def test_data_resolver_local_path():
    with tempdir() as d:
        path = d / "foo.txt"
        with open(path, "wt") as out:
            out.write("foo")
        resolver = DataResolver({"foo": {
            "path": "foo.txt"
        }}, UserConfiguration(None, cache_dir=d))
        assert resolver.resolve("foo").path == path

        with setenv({"MYPATH": str(d)}):
            resolver = DataResolver({"foo": {
                "path": "${MYPATH}/foo.txt"
            }}, UserConfiguration(None, cache_dir=d))
            assert resolver.resolve("foo").path == path
Ejemplo n.º 9
0
def test_http_header_set_in_workflow_data():
    """
    Test that workflow data file can define the HTTP Headers. This is
    important because the URLs referenced can be from different hosts and
    require different headers, so setting them at this level allows that
    fine-grained control.
    """
    with tempdir() as d:
        config = UserConfiguration(cache_dir=d)
        assert not config.default_http_headers
        resolver = DataResolver(
            {
                "foo": {
                    "url": GOOD_URL,
                    "path": "sample.vcf",
                    "http_headers": {
                        "Auth-Header-Token": "TOKEN"
                    }
                }
            }, config)
        foo = resolver.resolve("foo")
        assert foo.path == d / "sample.vcf"
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"

    with setenv({"TOKEN": "this_is_the_token"}), tempdir() as d:
        config = UserConfiguration(cache_dir=d)
        assert not config.default_http_headers
        resolver = DataResolver(
            {
                "foo": {
                    "url": GOOD_URL,
                    "path": "sample.vcf",
                    "http_headers": {
                        "Auth-Header-Token": "TOKEN"
                    }
                }
            }, config)
        foo = resolver.resolve("foo")
        assert foo.path == d / "sample.vcf"
        assert isinstance(foo.localizer, UrlLocalizer)
        assert cast(UrlLocalizer, foo.localizer).http_headers == {
            "Auth-Header-Token": "this_is_the_token"
        }
        with open(foo.path, "rt") as inp:
            assert inp.read() == "foo"
Ejemplo n.º 10
0
def test_data_resolver_env():
    with tempdir() as d:
        path = d / "foo.txt"
        with open(path, "wt") as out:
            out.write("foo")
        with setenv({"FOO": str(path)}):
            resolver = DataResolver({"foo": {
                "env": "FOO"
            }}, UserConfiguration(None, cache_dir=d))
            assert resolver.resolve("foo").path == path

            bar = d / "bar.txt"
            resolver = DataResolver({"foo": {
                "env": "FOO",
                "path": bar
            }}, UserConfiguration(None, cache_dir=d))
            assert resolver.resolve("foo").path == bar
Ejemplo n.º 11
0
def test_data_resolver():
    with tempdir() as d:
        test_data = {"foo": {"name": "foo.txt"}, "bar": 1}
        foo_txt = d / "data" / "foo.txt"
        foo_txt.parent.mkdir()
        with open(foo_txt, "wt") as out:
            out.write("bar")
        mod = Mock()
        mod.__name__ = ""
        fun = Mock()
        fun.__name__ = "test_foo"
        dd = DataDirs(d, mod, fun)
        resolver = DataResolver(test_data, UserConfiguration(None,
                                                             cache_dir=d))
        with pytest.raises(FileNotFoundError):
            resolver.resolve("bork", dd)
        assert resolver.resolve("foo", dd).path == foo_txt
        assert resolver.resolve("bar", dd) == 1