コード例 #1
0
 def test_default_dir(self, capsys):
     with patch('astrodynamics.utils.web.download_file_with_progress',
                autospec=True) as mock:
         url = SPK_URL.format(category='planets', kernel='de432s')
         download_spk('planets', 'de432s')
         mock.assert_called_once_with(url, str(SPK_DIR / 'de432s.bsp'))
         capsys.readouterr()
コード例 #2
0
 def test_default_dir(self, capsys):
     with patch('astrodynamics.utils.web.download_file_with_progress',
                autospec=True) as mock:
         url = SPK_URL.format(category='planets', kernel='de432s')
         download_spk('planets', 'de432s')
         mock.assert_called_once_with(url, str(SPK_DIR / 'de432s.bsp'))
         capsys.readouterr()
コード例 #3
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()
コード例 #4
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()
コード例 #5
0
    def test_download_failed(self, tmpdir):
        with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
            rsps.add(
                GET, SPK_URL.format(category='planets', kernel='jakku'),
                status=500)
            rsps.add(
                GET, SPK_OLD_URL.format(category='planets', kernel='jakku'),
                status=500)

            with pytest.raises(requests.HTTPError):
                download_spk(category='planets', kernel='jakku',
                             download_dir=str(tmpdir))
コード例 #6
0
    def test_download_failed(self, tmpdir):
        with responses.RequestsMock(
                assert_all_requests_are_fired=False) as rsps:
            rsps.add(GET,
                     SPK_URL.format(category='planets', kernel='jakku'),
                     status=500)
            rsps.add(GET,
                     SPK_OLD_URL.format(category='planets', kernel='jakku'),
                     status=500)

            with pytest.raises(requests.HTTPError):
                download_spk(category='planets',
                             kernel='jakku',
                             download_dir=str(tmpdir))
コード例 #7
0
    def test_kernel_with_extension(self, tmpdir, capsys):
        """Test that kernel can still be downloaded if it has its extension."""
        with patch('astrodynamics.utils.web.download_file_with_progress',
                   autospec=True) as mock_download_file_with_progress:

            download_spk(category='planets', kernel='de432s.bsp',
                         download_dir=str(tmpdir))

            url = SPK_URL.format(category='planets', kernel='de432s')
            filepath = tmpdir.join('de432s.bsp')

            mock_download_file_with_progress.assert_called_once_with(
                url, str(filepath))

            mock_download_file_with_progress.reset_mock()
            assert not mock_download_file_with_progress.called
        capsys.readouterr()
コード例 #8
0
    def test_kernel_with_extension(self, tmpdir, capsys):
        """Test that kernel can still be downloaded if it has its extension."""
        with patch('astrodynamics.utils.web.download_file_with_progress',
                   autospec=True) as mock_download_file_with_progress:

            download_spk(category='planets',
                         kernel='de432s.bsp',
                         download_dir=str(tmpdir))

            url = SPK_URL.format(category='planets', kernel='de432s')
            filepath = tmpdir.join('de432s.bsp')

            mock_download_file_with_progress.assert_called_once_with(
                url, str(filepath))

            mock_download_file_with_progress.reset_mock()
            assert not mock_download_file_with_progress.called
        capsys.readouterr()
コード例 #9
0
 def test_kernel_not_found(self, tmpdir, capsys):
     with pytest.raises(KernelNotFoundError):
         download_spk(category='planets',
                      kernel='tatooine',
                      download_dir=str(tmpdir))
コード例 #10
0
 def test_invalid_category(self, tmpdir):
     with pytest.raises(InvalidCategoryError):
         download_spk(category='nonsense',
                      kernel=spk_data[0]['kernel'],
                      download_dir=str(tmpdir))
コード例 #11
0
 def test_kernel_not_found(self, tmpdir, capsys):
     with pytest.raises(KernelNotFoundError):
         download_spk(category='planets', kernel='tatooine',
                      download_dir=str(tmpdir))
コード例 #12
0
 def test_invalid_category(self, tmpdir):
     with pytest.raises(InvalidCategoryError):
         download_spk(category='nonsense', kernel=spk_data[0]['kernel'],
                      download_dir=str(tmpdir))