def test_110_storage_subrepo_alt_revision(self):
     # a simple test to check that repodata is available.
     util.extract_archive(self.testdir)
     repodata = DummyItem(join(self.testdir, 'repodata'))
     storage = GitStorage(repodata)
     # checkout a specific rev
     storage.checkout(util.ARCHIVE_REVS[1])
     pathinfo = storage.pathinfo('ext/import1')
     self.assertEqual(pathinfo, {
         'basename': 'import1',
         'date': '',
         'size': 0,
         'type': 'subrepo',
         'obj': {
             '': '_subrepo',
             'location': 'http://models.example.com/w/import1',
             'path': '',
             'rev': '00cf337ef94f882f2585684c1c5c601285312f85',
         },
     })
    def test_011_storage_empty_failures(self):
        emptydir = join(self.testdir, 'empty')
        init_repository(join(emptydir, '.git'), bare=True)
        item = DummyItem(emptydir)
        storage = GitStorage(item)

        pathinfo = storage.pathinfo('')

        with self.assertRaises(RevisionNotFoundError):
            storage.checkout('nowhere')

        pathinfo = storage.pathinfo('')
        self.assertEqual(pathinfo, {
            'basename': '',
            'date': '',
            'size': 0,
            'type': 'folder',
        })

        with self.assertRaises(PathNotFoundError):
            storage.listdir('nowhere')

        with self.assertRaises(RevisionNotFoundError):
            storage.log('nosuchrev', 1)
    def test_010_storage_base(self):
        item = DummyItem(self.testdir)
        revs, fulllist = util.create_demo_git_repo(self.testdir)

        storage = GitStorage(item)
        result = storage.files()
        self.assertEqual(result, fulllist)
        entries = storage.listdir('')
        self.assertEqual(entries, ['file1', 'file2', 'file3', 'nested'])

        self.assertEqual(storage.rev, revs[-1])
        self.assertEqual(storage.shortrev, revs[-1][:12])

        info = storage.pathinfo('nested')
        self.assertEqual(info['size'], 0)
        self.assertEqual(info['type'], 'folder')

        entries = storage.listdir('nested')
        self.assertEqual(entries, ['deep'])

        info = storage.pathinfo('file1')
        self.assertEqual(info['size'], 38)
        self.assertEqual(info['type'], 'file')

        with self.assertRaises(PathNotFoundError):
            storage.pathinfo('nosuchpath')

        with self.assertRaises(PathNotFoundError):
            storage.listdir('nosuchpath')

        with self.assertRaises(PathNotDirError):
            storage.listdir('file1')

        with self.assertRaises(PathNotFileError):
            storage.file('nested')

        with self.assertRaises(PathNotFoundError):
            storage.pathinfo('nested/deep/nosuchpath')

        with self.assertRaises(PathNotFoundError):
            storage.listdir('nested/deep/nosuchpath')

        with self.assertRaises(PathNotDirError):
            storage.listdir('nested/deep/dir/file')

        with self.assertRaises(PathNotFileError):
            storage.file('nested/deep/dir')

        logs = storage.log('HEAD', 10)
        self.assertEqual(len(logs), 4)
        self.assertEqual(logs[0]['author'], u'user3')
        self.assertEqual(logs[1]['author'], u'user3')
        self.assertEqual(logs[2]['author'], u'user2')
        self.assertEqual(logs[3]['author'], u'user1')

        self.assertTrue(isinstance(logs[0]['date'], str))

        logs = storage.log(None, 2)
        self.assertEqual(len(logs), 2)

        storage.checkout(revs[0])
        self.assertEqual(storage.rev, revs[0])

        with self.assertRaises(PathNotFoundError):
            # normally won't be traversed, but for completeness, test
            # that getting an object with a type that is not expected
            # should fail.
            storage._get_obj('file1', DummyItem)