Ejemplo n.º 1
0
    def test_download(self, tmpdir, capsys, mock_spk_url):
        rsps = mock_spk_url
        # Mock progress file attribute to prevent output to stderr (I had
        # trouble capturing)
        patch_bar = patch.object(DownloadProgressBar, 'file', io.StringIO())
        patch_spinner = patch.object(DownloadProgressSpinner, 'file',
                                     io.StringIO())
        with patch_bar, patch_spinner:
            for data in spk_data:
                download_spk(category=data['category'],
                             kernel=data['kernel'],
                             download_dir=str(tmpdir))

                file = tmpdir.join(data['kernel'] + '.bsp')
                assert file.check()
                with file.open('r') as f:
                    assert f.read() == 'fake data for ' + data['kernel']

                stdout, _ = capsys.readouterr()
                lines = stdout.split('\n')
                assert lines[0].startswith('Downloading')

                headers = rsps.calls[-1].response.headers
                if 'content-length' in headers:
                    length = headers['content-length']
                    assert lines[0].endswith('{}.bsp ({})'.format(
                        data['kernel'], format_size(length)))
                else:
                    assert lines[0].endswith(data['kernel'] + '.bsp')

                assert lines[1].endswith(data['kernel'] + '.bsp')
                capsys.readouterr()
    def test_download(self, tmpdir, capsys, mock_spk_url):
        rsps = mock_spk_url
        # Mock progress file attribute to prevent output to stderr (I had
        # trouble capturing)
        patch_bar = patch.object(DownloadProgressBar, 'file', io.StringIO())
        patch_spinner = patch.object(DownloadProgressSpinner, 'file', io.StringIO())
        with patch_bar, patch_spinner:
            for data in spk_data:
                download_spk(category=data['category'], kernel=data['kernel'],
                             download_dir=str(tmpdir))

                file = tmpdir.join(data['kernel'] + '.bsp')
                assert file.check()
                with file.open('r') as f:
                    assert f.read() == 'fake data for ' + data['kernel']

                stdout, _ = capsys.readouterr()
                lines = stdout.split('\n')
                assert lines[0].startswith('Downloading')

                headers = rsps.calls[-1].response.headers
                if 'content-length' in headers:
                    length = headers['content-length']
                    assert lines[0].endswith('{}.bsp ({})'.format(
                        data['kernel'], format_size(length)))
                else:
                    assert lines[0].endswith(data['kernel'] + '.bsp')

                assert lines[1].endswith(data['kernel'] + '.bsp')
                capsys.readouterr()
Ejemplo n.º 3
0
def test_format_size(args, string):
    if not isinstance(args, tuple):
        args = args,
    assert format_size(*args) == string
def test_format_size(args, string):
    if not isinstance(args, tuple):
        args = args,
    assert format_size(*args) == string