|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2010-2014 The pygit2 contributors |
| 4 | +# |
| 5 | +# This file is free software; you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License, version 2, |
| 7 | +# as published by the Free Software Foundation. |
| 8 | +# |
| 9 | +# In addition to the permissions in the GNU General Public License, |
| 10 | +# the authors give you unlimited permission to link the compiled |
| 11 | +# version of this file into combinations with other programs, |
| 12 | +# and to distribute those combinations without any restriction |
| 13 | +# coming from the use of this file. (The General Public License |
| 14 | +# restrictions do apply in other respects; for example, they cover |
| 15 | +# modification of the file, and distribution when not linked into |
| 16 | +# a combined executable.) |
| 17 | +# |
| 18 | +# This file is distributed in the hope that it will be useful, but |
| 19 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | +# General Public License for more details. |
| 22 | +# |
| 23 | +# You should have received a copy of the GNU General Public License |
| 24 | +# along with this program; see the file COPYING. If not, write to |
| 25 | +# the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
| 26 | +# Boston, MA 02110-1301, USA. |
| 27 | + |
| 28 | +"""Tests for Blame objects.""" |
| 29 | + |
| 30 | +from __future__ import absolute_import |
| 31 | +from __future__ import unicode_literals |
| 32 | +import unittest |
| 33 | +import pygit2 |
| 34 | +from pygit2 import Index, Oid, Tree, Object |
| 35 | +import tarfile |
| 36 | +import os |
| 37 | +from . import utils |
| 38 | +from time import time |
| 39 | + |
| 40 | +TREE_HASH = 'fd937514cb799514d4b81bb24c5fcfeb6472b245' |
| 41 | +COMMIT_HASH = '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98' |
| 42 | + |
| 43 | +class ArchiveTest(utils.RepoTestCase): |
| 44 | + |
| 45 | + def check_writing(self, treeish, timestamp=None): |
| 46 | + archive = tarfile.open('foo.tar', mode='w') |
| 47 | + self.repo.write_archive(treeish, archive) |
| 48 | + |
| 49 | + index = Index() |
| 50 | + if isinstance(treeish, Object): |
| 51 | + index.read_tree(treeish.peel(Tree)) |
| 52 | + else: |
| 53 | + index.read_tree(self.repo[treeish].peel(Tree)) |
| 54 | + |
| 55 | + self.assertEqual(len(index), len(archive.getmembers())) |
| 56 | + |
| 57 | + if timestamp: |
| 58 | + fileinfo = archive.getmembers()[0] |
| 59 | + self.assertEqual(timestamp, fileinfo.mtime) |
| 60 | + |
| 61 | + archive.close() |
| 62 | + self.assertTrue(os.path.isfile('foo.tar')) |
| 63 | + os.remove('foo.tar') |
| 64 | + |
| 65 | + def test_write_tree(self): |
| 66 | + self.check_writing(TREE_HASH) |
| 67 | + self.check_writing(Oid(hex=TREE_HASH)) |
| 68 | + self.check_writing(self.repo[TREE_HASH]) |
| 69 | + |
| 70 | + def test_write_commit(self): |
| 71 | + commit_timestamp = self.repo[COMMIT_HASH].committer.time |
| 72 | + self.check_writing(COMMIT_HASH, commit_timestamp) |
| 73 | + self.check_writing(Oid(hex=COMMIT_HASH), commit_timestamp) |
| 74 | + self.check_writing(self.repo[COMMIT_HASH], commit_timestamp) |
0 commit comments