Exemplo n.º 1
0
    def test_file_cache_construction(self, tmpdir):
        base_path = Path(str(tmpdir))
        builder_path = base_path / '.builder'

        assert not builder_path.exists()

        # Make sure the directory is properly created.
        cache = FileCache(base_path)

        # noinspection PyProtectedMember
        assert cache._base_file_cache_path == builder_path
        assert builder_path.exists()

        # Make sure no errors occur if the directory already exists.
        cache = FileCache(base_path)

        # noinspection PyProtectedMember
        assert cache._base_file_cache_path == builder_path
        assert builder_path.exists()
Exemplo n.º 2
0
    def test_resolve_file_handles_http_error(self, tmpdir):
        base_path = Path(str(tmpdir))
        the_file = Path('the.file')
        cache = FileCache(base_path)
        mock_download = MagicMock(side_effect=HTTPError('Bad HTTP call!'))

        cache._download_file = mock_download
        mock_download.return_value = True

        with pytest.raises(ValueError) as info:
            _ = cache.resolve_file('the-url', the_file)

        assert info.value.args[0] == 'Could not cache the.file: Bad HTTP call!'
Exemplo n.º 3
0
    def test_resolve_file_existing_file_no_force(self, tmpdir):
        base_path = Path(str(tmpdir))
        the_file = Path('the.file')
        path = base_path / '.builder' / the_file

        # Make sure the path already exists.
        path.parent.mkdir()
        path.touch()

        cache = FileCache(base_path)

        with patch('builder.file_cache.global_options.force_remote_fetch'
                   ) as mock_frf:
            mock_frf.return_value = False

            assert cache.resolve_file('the-url', the_file) == path
Exemplo n.º 4
0
    def test_resolve_file_missing_file_works(self, tmpdir):
        base_path = Path(str(tmpdir))
        the_file = Path('the.file')
        path = base_path / '.builder' / the_file
        mock_download = MagicMock()

        cache = FileCache(base_path)

        cache._download_file = mock_download
        mock_download.return_value = True

        with patch('builder.file_cache.global_options.force_remote_fetch'
                   ) as mock_frf:
            mock_frf.return_value = False

            assert cache.resolve_file('the-url', the_file) == path
            assert mock_download.mock_calls == [call('the-url', path)]
Exemplo n.º 5
0
    def test_resolve_file_existing_file_with_force_works(self, tmpdir):
        base_path = Path(str(tmpdir))
        the_file = Path('the.file')
        path = base_path / '.builder' / the_file
        mock_download = MagicMock()

        # Make sure the path already exists.
        path.parent.mkdir()
        path.touch()

        cache = FileCache(base_path)

        cache._download_file = mock_download
        mock_download.return_value = True

        with patch('builder.file_cache.global_options.force_remote_fetch'
                   ) as mock_frf:
            mock_frf.return_value = True

            assert cache.resolve_file('the-url', the_file) == path
            assert mock_download.mock_calls == [call('the-url', path)]