0
  C   aˆl–äY>”ÊeJeA3p\eÅ1hß�þ\�m¬Ü¢|2—¤t þï„Àqÿî_ŠI|¥�+Wé3ž¯Åì ?÷     a# test_object_store.py -- tests for object_store.py
# Copyright (C) 2008 Jelmer Vernooij <jelmer@jelmer.uk>
#
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
# General Public License as public by the Free Software Foundation; version 2.0
# or (at your option) any later version. You can redistribute it and/or
# modify it under the terms of either of these two licenses.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# You should have received a copy of the licenses; if not, see
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
# License, Version 2.0.
#

"""Tests for the object store interface."""


from contextlib import closing
from io import BytesIO
from unittest import skipUnless
import os
import shutil
import stat
import sys
import tempfile

from dulwich.index import (
    commit_tree,
)
from dulwich.errors import (
    NotTreeError,
)
from dulwich.objects import (
    sha_to_hex,
    Blob,
    Tree,
    TreeEntry,
    EmptyFileException,
    SubmoduleEncountered,
    S_IFGITLINK,
)
from dulwich.object_store import (
    DiskObjectStore,
    MemoryObjectStore,
    OverlayObjectStore,
    ObjectStoreGraphWalker,
    commit_tree_changes,
    iter_tree_contents,
    peel_sha,
    read_packs_file,
    tree_lookup_path,
)
from dulwich.pack import (
    REF_DELTA,
    write_pack_objects,
)
from dulwich.protocol import DEPTH_INFINITE
from dulwich.tests import (
    TestCase,
)
from dulwich.tests.utils import (
    make_object,
    make_tag,
    build_pack,
)

try:
    from unittest.mock import patch
except ImportError:
    patch = None  # type: ignore


testobject = make_object(Blob, data=b"yummy data")


class ObjectStoreTests:
    def test_determine_wants_all(self):
        self.assertEqual(
            [b"1" * 40],
            self.store.determine_wants_all({b"refs/heads/foo": b"1" * 40}),
        )

    def test_determine_wants_all_zero(self):
        self.assertEqual(
            [], self.store.determine_wants_all({b"refs/heads/foo": b"0" * 40})
        )

    @skipUnless(patch, "Required mock.patch")
    def test_determine_wants_all_depth(self):
        self.store.add_object(testobject)
        refs = {b"refs/heads/foo": testobject.id}
        with patch.object(self.store, "_get_depth", return_value=1) as m:
            self.assertEqual(
                [], self.store.determine_wants_all(refs, depth=0)
            )
            self.assertEqual(
                [testobject.id],
                self.store.determine_wants_all(refs, depth=DEPTH_INFINITE),
            )
            m.assert_not_called()

            self.assertEqual(
                [], self.store.determine_wants_all(refs, depth=1)
            )
            m.assert_called_with(testobject.id)
            self.assertEqual(
                [testobject.id], self.store.determine_wants_all(refs, depth=2)
            )

    def test_get_depth(self):
        self.assertEqual(
            0, self.store._get_depth(testobject.id)
        )

        self.store.add_object(testobject)
        self.assertEqual(
            1, self.store._get_depth(testobject.id, get_parents=lambda x: [])
        )

        parent = make_object(Blob, data=b"parent data")
        self.store.add_object(parent)
        self.assertEqual(
            2,
            self.store._get_depth(
                testobject.id,
                get_parents=lambda x: [parent.id] if x == testobject else [],
            ),
        )

    def test_iter(self):
        self.assertEqual([], list(self.store))

    def test_get_nonexistant(self):
        self.assertRaises(KeyError, lambda: self.store[b"a" * 40])

    def test_con