Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / dulwich / tests / test_archive.py @ 959

History | View | Annotate | Download (2.17 KB)

1
# test_archive.py -- tests for archive
2
# Copyright (C) 2015 Jelmer Vernooij <jelmer@jelmer.uk>
3
#
4
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
5
# General Public License as public by the Free Software Foundation; version 2.0
6
# or (at your option) any later version. You can redistribute it and/or
7
# modify it under the terms of either of these two licenses.
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
#
15
# You should have received a copy of the licenses; if not, see
16
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
17
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
18
# License, Version 2.0.
19
#
20

    
21
"""Tests for archive support."""
22

    
23
from io import BytesIO
24
import tarfile
25

    
26
from dulwich.archive import tar_stream
27
from dulwich.object_store import (
28
    MemoryObjectStore,
29
    )
30
from dulwich.objects import (
31
    Blob,
32
    Tree,
33
    )
34
from dulwich.tests import (
35
    TestCase,
36
    )
37
from dulwich.tests.utils import (
38
    build_commit_graph,
39
    )
40

    
41

    
42
class ArchiveTests(TestCase):
43

    
44
    def test_empty(self):
45
        store = MemoryObjectStore()
46
        c1, c2, c3 = build_commit_graph(store, [[1], [2, 1], [3, 1, 2]])
47
        tree = store[c3.tree]
48
        stream = b''.join(tar_stream(store, tree, 10))
49
        out = BytesIO(stream)
50
        tf = tarfile.TarFile(fileobj=out)
51
        self.addCleanup(tf.close)
52
        self.assertEqual([], tf.getnames())
53

    
54
    def test_simple(self):
55
        self.skipTest("known to fail on python2.6 and 3.4; needs debugging")
56
        store = MemoryObjectStore()
57
        b1 = Blob.from_string(b"somedata")
58
        store.add_object(b1)
59
        t1 = Tree()
60
        t1.add(b"somename", 0o100644, b1.id)
61
        store.add_object(t1)
62
        stream = b''.join(tar_stream(store, t1, 10))
63
        out = BytesIO(stream)
64
        tf = tarfile.TarFile(fileobj=out)
65
        self.addCleanup(tf.close)
66
        self.assertEqual(["somename"], tf.getnames())