Example #1
0
    def packages_dir(self) -> pathlib.Path:
        """The directory containing packages.

        Packages are extracted on first access
        """
        utils.extract(self.rel_ctx_packages, self.tarball)
        return self.rel_ctx_packages
Example #2
0
def test_util_extract(patches, tarballs):
    patched = patches("nested", "tarfile.open", prefix="tools.base.utils")

    with patched as (m_nested, m_open):
        _extractions = [MagicMock(), MagicMock()]
        m_nested.return_value.__enter__.return_value = _extractions

        if tarballs:
            assert utils.extract("PATH", *tarballs) == "PATH"
        else:

            with pytest.raises(utils.ExtractError) as e:
                utils.extract("PATH", *tarballs) == "PATH"

    if not tarballs:
        assert (
            e.value.args[0] == 'No tarballs specified for extraction to PATH')
        assert not m_nested.called
        assert not m_open.called
        for _extract in _extractions:
            assert not _extract.extractall.called
        return

    for _extract in _extractions:
        assert (list(_extract.extractall.call_args) == [(), dict(path="PATH")])

    assert (list(m_open.call_args_list) == [[(tarb, ), {}]
                                            for tarb in tarballs])
    assert (list(m_nested.call_args) == [
        tuple(m_open.return_value for x in tarballs), {}
    ])
Example #3
0
 def rst_dir(self) -> pathlib.Path:
     """Populates an rst directory with contents of given rst tar,
     and returns the path to the directory
     """
     rst_dir = self.build_dir.joinpath("generated", "rst")
     if self.rst_tar:
         utils.extract(rst_dir, self.rst_tar)
     return rst_dir
Example #4
0
 def rst_dir(self) -> str:
     """Populates an rst directory with contents of given rst tar,
     and returns the path to the directory
     """
     rst_dir = os.path.join(self.build_dir, "generated/rst")
     if self.rst_tar:
         utils.extract(rst_dir, self.rst_tar)
     return rst_dir
Example #5
0
def test_util_extract(patches):
    patched = patches(
        "tempfile.TemporaryDirectory",
        "tarfile.open",
        prefix="tools.base.utils")

    with patched as (m_tmp, m_open):
        assert utils.extract("TARBALL", "PATH") == "PATH"

    assert (
        list(m_open.call_args)
        == [('TARBALL',), {}])
    assert (
        list(m_open.return_value.__enter__.return_value.extractall.call_args)
        == [(), {'path': "PATH"}])