Пример #1
0
def test_get_source(shared_datadir, test_urls, test_repo):
    """should return correct subclass"""
    test_path = shared_datadir / 'esp8266_test_stub'
    local_stub = source.get_source(test_path)
    assert isinstance(local_stub, source.LocalStubSource)
    remote_stub = source.get_source('esp8266-test-stub')
    assert isinstance(remote_stub, source.RemoteStubSource)
    stub_source = source.get_source(test_urls['valid'])
    print(str(stub_source))
    assert str(stub_source) == f"<RemoteStubSource@{stub_source.location}>"
Пример #2
0
    def add(self, location, dest=None, force=False):
        """Add stub(s) from source.

        Args:
            source (str): path to stub(s)
            dest (str, optional): path to copy stubs to.
                Defaults to self.resource
            force (bool, optional): overwrite existing stubs.
                Defaults to False.

        Raises:
            TypeError: No resource or destination provided

        """
        _dest = dest or self.resource
        if not _dest:
            raise TypeError("No Stub Destination Provided!")
        dest = Path(str(_dest)).resolve()
        stubs = [s for s in self._check_existing(location) if s is not None]
        if any(stubs):
            for stub in stubs:
                if not force:
                    self.log.info(f"$[{stub}] is already installed!")
                    return stub
                self.log.info(f"Uninstalling $[{stub.name}]...")
                shutil.rmtree(stub.path)
        if self._should_recurse(location):
            return self.load_from(location, strict=False, copy_to=dest)
        self.log.info(f"\nResolving stub...")
        stub_source = source.get_source(location, log=self.log)
        return self._load(stub_source, copy_to=dest)
Пример #3
0
def test_source_ready(shared_datadir, test_urls, tmp_path, mocker,
                      test_archive, test_repo):
    """should prepare and resolve stub"""
    # Test LocalStub ready
    test_path = shared_datadir / 'esp8266_test_stub'
    local_stub = source.get_source(test_path)
    expected_path = local_stub.location.resolve()
    with local_stub.ready() as source_path:
        assert source_path == expected_path

    # Setup RemoteStub
    test_parent = tmp_path / 'tmpdir'
    test_parent.mkdir()
    expected_path = (test_parent / 'archive_test_stub').resolve()
    mocker.patch.object(source.tempfile, "mkdtemp", return_value=test_parent)
    mocker.patch.object(source.utils, "stream_download",
                        return_value=test_archive)
    # Test Remote Stub
    remote_stub = source.get_source(test_urls['download'])
    with remote_stub.ready() as source_path:
        print(list(source_path.parent.iterdir()))
        assert (source_path / 'info.json').exists()
        assert len(list(source_path.iterdir())) == 3
Пример #4
0
    def load_from(self, directory, *args, **kwargs):
        """Recursively loads stubs from a directory

        Args:
            directory (str): Path to load from

        Returns:
            [DeviceStub]: List of loaded Stubs
        """
        dir_path = Path(str(directory)).resolve()
        dirs = dir_path.iterdir()
        sources = [source.get_source(d) for d in dirs]
        stubs = []
        for stub in sources.copy():
            if self.is_valid(stub.location):
                stub_type = self._get_stubtype(stub.location)
                if stub_type is FirmwareStub:
                    sources.remove(stub)
                    self._load(stub, *args, **kwargs)
        stubs.extend([self._load(s, *args, **kwargs) for s in sources])
        return stubs