Esempio n. 1
0
def test_data_dirs():
    with tempdir() as d:
        mod = Mock()
        mod.__name__ = "tests.bar"
        cls = Mock()
        cls.__name__ = "baz"
        fun = Mock()
        fun.__name__ = "blorf"
        mod_cls_fun = d / "tests" / "bar" / "baz" / "blorf"
        mod_cls_fun.mkdir(parents=True)
        data_mod_cls_fun = d / "tests" / "data" / "bar" / "baz" / "blorf"
        data_mod_cls_fun.mkdir(parents=True)

        dd = DataDirs(d / "tests", mod, fun, cls)
        assert dd.paths == [
            mod_cls_fun, d / "tests" / "bar" / "baz", d / "tests" / "bar",
            data_mod_cls_fun, d / "tests" / "data" / "bar" / "baz",
            d / "tests" / "data" / "bar", d / "tests" / "data"
        ]

        mod_cls_fun = d / "tests" / "bar" / "blorf"
        mod_cls_fun.mkdir(parents=True)
        data_mod_cls_fun = d / "tests" / "data" / "bar" / "blorf"
        data_mod_cls_fun.mkdir(parents=True)
        dd = DataDirs(d / "tests", mod, fun)
        assert dd.paths == [
            mod_cls_fun, d / "tests" / "bar", data_mod_cls_fun,
            d / "tests" / "data" / "bar", d / "tests" / "data"
        ]
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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")
Esempio n. 5
0
def workflow_data(request: FixtureRequest,
                  workflow_data_resolver: DataResolver) -> DataManager:
    """
    Provides an accessor for test data files, which may be local or in a remote
    repository.

    Args:
        request: FixtureRequest object
        workflow_data_resolver: Module-level test data configuration

    Examples:
        def workflow_data_descriptor_file():
            return "tests/test_data.json"

        def test_workflow(workflow_data):
            print(workflow_data["myfile"])
    """
    datadirs = DataDirs(
        ensure_path(request.fspath.dirpath(), canonicalize=True),
        request.module, request.function, request.cls)
    return DataManager(workflow_data_resolver, datadirs)