objectdbtest.py :  » Development » Rope » rope-0.9.2 » ropetest » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Rope 
Rope » rope 0.9.2 » ropetest » objectdbtest.py
import unittest

from rope.base.oi import objectdb,memorydb
from ropetest import testutils


def _do_for_all_dbs(function):
    def called(self):
        for db in self.dbs:
            function(self, db)
    return called


class _MockValidation(object):

    def is_value_valid(self, value):
        return value != -1

    def is_more_valid(self, new, old):
        return new != -1

    def is_file_valid(self, path):
        return path != 'invalid'

    def is_scope_valid(self, path, key):
        return path != 'invalid' and key != 'invalid'


class _MockFileListObserver(object):

    log = ''

    def added(self, path):
        self.log += 'added %s ' % path

    def removed(self, path):
        self.log += 'removed %s ' % path


class ObjectDBTest(unittest.TestCase):

    def setUp(self):
        super(ObjectDBTest, self).setUp()
        self.project = testutils.sample_project()
        validation = _MockValidation()
        self.dbs = [
            objectdb.ObjectDB(memorydb.MemoryDB(self.project), validation)]

    def tearDown(self):
        for db in self.dbs:
            db.write()
        testutils.remove_project(self.project)
        super(ObjectDBTest, self).tearDown()

    @_do_for_all_dbs
    def test_simple_per_name(self, db):
        db.add_pername('file', 'key', 'name', 1)
        self.assertEqual(1, db.get_pername('file', 'key', 'name'))

    @_do_for_all_dbs
    def test_simple_per_name_does_not_exist(self, db):
        self.assertEquals(None, db.get_pername('file', 'key', 'name'))

    @_do_for_all_dbs
    def test_simple_per_name_after_syncing(self, db):
        db.add_pername('file', 'key', 'name', 1)
        db.write()
        self.assertEquals(1, db.get_pername('file', 'key', 'name'))

    @_do_for_all_dbs
    def test_getting_returned(self, db):
        db.add_callinfo('file', 'key', (1, 2), 3)
        self.assertEquals(3, db.get_returned('file', 'key', (1, 2)))

    @_do_for_all_dbs
    def test_getting_returned_when_does_not_match(self, db):
        db.add_callinfo('file', 'key', (1, 2), 3)
        self.assertEquals(None, db.get_returned('file', 'key', (1, 1)))

    @_do_for_all_dbs
    def test_getting_call_info(self, db):
        db.add_callinfo('file', 'key', (1, 2), 3)

        call_infos = list(db.get_callinfos('file', 'key'))
        self.assertEquals(1, len(call_infos))
        self.assertEquals((1, 2), call_infos[0].get_parameters())
        self.assertEquals(3, call_infos[0].get_returned())

    @_do_for_all_dbs
    def test_invalid_per_name(self, db):
        db.add_pername('file', 'key', 'name', -1)
        self.assertEquals(None, db.get_pername('file', 'key', 'name'))

    @_do_for_all_dbs
    def test_overwriting_per_name(self, db):
        db.add_pername('file', 'key', 'name', 1)
        db.add_pername('file', 'key', 'name', 2)
        self.assertEquals(2, db.get_pername('file', 'key', 'name'))

    @_do_for_all_dbs
    def test_not_overwriting_with_invalid_per_name(self, db):
        db.add_pername('file', 'key', 'name', 1)
        db.add_pername('file', 'key', 'name', -1)
        self.assertEquals(1, db.get_pername('file', 'key', 'name'))

    @_do_for_all_dbs
    def test_getting_invalid_returned(self, db):
        db.add_callinfo('file', 'key', (1, 2), -1)
        self.assertEquals(None, db.get_returned('file', 'key', (1, 2)))

    @_do_for_all_dbs
    def test_not_overwriting_with_invalid_returned(self, db):
        db.add_callinfo('file', 'key', (1, 2), 3)
        db.add_callinfo('file', 'key', (1, 2), -1)
        self.assertEquals(3, db.get_returned('file', 'key', (1, 2)))

    @_do_for_all_dbs
    def test_get_files(self, db):
        db.add_callinfo('file1', 'key', (1, 2), 3)
        db.add_callinfo('file2', 'key', (1, 2), 3)
        self.assertEquals(set(['file1', 'file2']), set(db.get_files()))

    @_do_for_all_dbs
    def test_validating_files(self, db):
        db.add_callinfo('invalid', 'key', (1, 2), 3)
        db.validate_files()
        self.assertEquals(0, len(db.get_files()))

    @_do_for_all_dbs
    def test_validating_file_for_scopes(self, db):
        db.add_callinfo('file', 'invalid', (1, 2), 3)
        db.validate_file('file')
        self.assertEquals(1, len(db.get_files()))
        self.assertEquals(0, len(list(db.get_callinfos('file', 'invalid'))))

    @_do_for_all_dbs
    def test_validating_file_moved(self, db):
        db.add_callinfo('file', 'key', (1, 2), 3)

        db.file_moved('file', 'newfile')
        self.assertEquals(1, len(db.get_files()))
        self.assertEquals(1, len(list(db.get_callinfos('newfile', 'key'))))

    @_do_for_all_dbs
    def test_using_file_list_observer(self, db):
        db.add_callinfo('invalid', 'key', (1, 2), 3)
        observer = _MockFileListObserver()
        db.add_file_list_observer(observer)
        db.validate_files()
        self.assertEquals('removed invalid ', observer.log)


def suite():
    result = unittest.TestSuite()
    result.addTests(unittest.makeSuite(ObjectDBTest))
    return result


if __name__ == '__main__':
    unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.