コード例 #1
0
ファイル: test_file.py プロジェクト: alex2/swallow
class GitFileTest(StandardFixturesMixin, TempGitRepoTest):

    def setUp(self):
        super(GitFileTest, self).setUp()
        self._gitrepo = GitRepo(self._temp_repo)

    def test_path(self):
        revision = GitRevision('refs/heads/master', self._gitrepo)
        f = self._gitrepo.file_at_revision('file_1', revision)
        self.assertEquals(
            f.path,
            'file_1'
        )

    def test_type(self):
        f = self._gitrepo.file_at_revision(
            'dir_1/file_3',
            GitRevision(self._commits['Merge branch bugfix into master'], self._gitrepo)
        )
        self.assertEquals(type(f), GitFile)

    def test_latest_revision(self):
        revision = GitRevision(self._commits['commit #6 on topic'], self._gitrepo)
        f = self._gitrepo.file_at_revision('dir_1/file_3', revision)
        self.assertEquals(revision.id, f.last_modified_revision.id)

    def test_mimetype(self):
        revision = GitRevision('refs/heads/master', self._gitrepo)
        f = self._gitrepo.file_at_revision('file_2', revision)
        self.assertEquals(
            f.mimetype[:10],
            'text/plain'
        )

    def test_file_data(self):
        revision = GitRevision('refs/heads/master', self._gitrepo)
        f = self._gitrepo.file_at_revision('file_1', revision)
        self.assertEquals(
            f.data,
            textwrap.dedent('''\
            first line
            second line
            third line''')
        )

    def test_last_modified_message(self):
        """We know that 'file_1' was last modified as part of 'commit #3...'
        but that 'refs/heads/master' points to a more recent commit"""
        revision = GitRevision('refs/heads/master', self._gitrepo)
        f = self._gitrepo.file_at_revision('file_1', revision)
        self.assertEquals(
            f.last_modified_revision.message,
            'commit #3 on master\n'
        )

    def test_file_chunked(self):
        revision = GitRevision('refs/heads/master', self._gitrepo)
        f = self._gitrepo.file_at_revision('file_1', revision)
        self.assertEquals(
            f.chunked,
            ['first line\nsecond line\nthird line',],
        )

    def test_no_file_at_revision(self):
        with self.assertRaises(NoPathAtRevision):
            f = self._gitrepo.file_at_revision(
                'file_3',
                GitRevision(self._commits['commit #1 on master'], self._gitrepo)
            )
            # touch the repo in some way
            f.blob
コード例 #2
0
ファイル: test_repo.py プロジェクト: alex2/swallow
 def test_file_at_revision(self):
     r = GitRepo(self._temp_repo)
     f = r.file_at_revision('file_1', GitRevision('refs/heads/master', r))
     self.assertTrue(isinstance(f, GitFile))