Esempio n. 1
0
 def test_acquire_new_install(self):
     item = Item(id='new')
     self.backend.install(item)
     storage = self.backend.acquire(item)
     self.assertEqual(item, storage.context)
     self.assertEqual(storage.rev, '0')
     self.assertEqual(storage.files(), [])
     self.assertEqual(storage.listdir(''), [])
 def test_acquire_new_install(self):
     item = Item(id='new')
     self.backend.install(item)
     storage = self.backend.acquire(item)
     self.assertEqual(item, storage.context)
     self.assertEqual(storage.rev, '0')
     self.assertEqual(storage.files(), [])
     self.assertEqual(storage.listdir(''), [])
Esempio n. 3
0
    def test_acquire_basic(self):
        item = Item(id='dummy_a')
        storage = self.backend.acquire(item)
        self.assertEqual(item, storage.context)
        self.assertEqual(storage.rev, '3')
        self.assertEqual(storage.shortrev, '3')
        self.assertEqual(storage.file('file1'),
                         'file2-rev0\nThis is also a test file.\n')
        self.assertEqual(storage.file('dir1/dir2/f2'), 'second file in dir2\n')
        self.assertEqual(storage.files(), [
            'dir1/dir2/f1',
            'dir1/dir2/f2',
            'dir1/dir3/dir4/dir5/info',
            'dir1/f1',
            'dir1/f2',
            'file1',
            'file3',
        ])

        self.assertEqual(storage.basename('dir1/dir3/dir4/dir5/info'), 'info')
        self.assertEqual(storage.listdir(''), ['dir1', 'file1', 'file3'])
        self.assertEqual(storage.listdir('dir1'), ['dir2', 'dir3', 'f1', 'f2'])
        self.assertEqual(storage.listdir('dir1/dir2'), ['f1', 'f2'])

        with self.assertRaises(PathNotFoundError):
            storage.listdir('dir1/no/such/dir')

        # this implementation will raise an error if trying to access a
        # file as directory.

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

        # acquire the detailed information associated with this path.
        self.assertEqual(
            storage.pathinfo('dir1'), {
                'basename': 'dir1',
                'size': 0,
                'type': 'folder',
                'date': '2005-03-18 23:12:19',
            })

        # ditto for a file
        self.assertEqual(
            storage.pathinfo('file1'), {
                'basename': 'file1',
                'size': 37,
                'type': 'file',
                'date': '2005-03-18 23:12:19',
            })

        # or something nested deeper
        self.assertEqual(
            storage.pathinfo('dir1/dir3/dir4/dir5/info'), {
                'basename': 'info',
                'size': 32,
                'type': 'file',
                'date': '2005-03-18 23:12:19',
            })

        storage.checkout('0')
        self.assertEqual(storage.rev, '0')
        self.assertEqual(storage.file('file1'),
                         'file1-rev0\nThis is a test file.\n')
        self.assertEqual(storage.files(), ['file1', 'file2'])
        self.assertEqual(storage.listdir(''), ['file1', 'file2'])

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

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

        self.assertEqual(
            storage.pathinfo('file1'), {
                'basename': 'file1',
                'size': 32,
                'type': 'file',
                'date': '2005-03-18 14:58:31',
            })
    def test_acquire_basic(self):
        item = Item(id='dummy_a')
        storage = self.backend.acquire(item)
        self.assertEqual(item, storage.context)
        self.assertEqual(storage.rev, '3')
        self.assertEqual(storage.shortrev, '3')
        self.assertEqual(
            storage.file('file1'), 'file2-rev0\nThis is also a test file.\n')
        self.assertEqual(
            storage.file('dir1/dir2/f2'), 'second file in dir2\n')
        self.assertEqual(storage.files(), [
            'dir1/dir2/f1', 'dir1/dir2/f2', 'dir1/dir3/dir4/dir5/info',
            'dir1/f1', 'dir1/f2', 'file1', 'file3',
        ])

        self.assertEqual(storage.basename('dir1/dir3/dir4/dir5/info'), 'info')
        self.assertEqual(storage.listdir(''), ['dir1', 'file1', 'file3'])
        self.assertEqual(storage.listdir('dir1'), ['dir2', 'dir3', 'f1', 'f2'])
        self.assertEqual(storage.listdir('dir1/dir2'), ['f1', 'f2'])

        with self.assertRaises(PathNotFoundError):
            storage.listdir('dir1/no/such/dir')

        # this implementation will raise an error if trying to access a
        # file as directory.

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

        # acquire the detailed information associated with this path.
        self.assertEqual(storage.pathinfo('dir1'), {
            'basename': 'dir1',
            'size': 0,
            'type': 'folder',
            'date': '2005-03-18 23:12:19',
        })

        # ditto for a file
        self.assertEqual(storage.pathinfo('file1'), {
            'basename': 'file1',
            'size': 37,
            'type': 'file',
            'date': '2005-03-18 23:12:19',
        })

        # or something nested deeper
        self.assertEqual(storage.pathinfo('dir1/dir3/dir4/dir5/info'), {
            'basename': 'info',
            'size': 32,
            'type': 'file',
            'date': '2005-03-18 23:12:19',
        })

        storage.checkout('0')
        self.assertEqual(storage.rev, '0')
        self.assertEqual(
            storage.file('file1'), 'file1-rev0\nThis is a test file.\n')
        self.assertEqual(storage.files(), ['file1', 'file2'])
        self.assertEqual(storage.listdir(''), ['file1', 'file2'])

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

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

        self.assertEqual(storage.pathinfo('file1'), {
            'basename': 'file1',
            'size': 32,
            'type': 'file',
            'date': '2005-03-18 14:58:31',
        })