test_rdb.py :  » Development » Python-X-Library » python-xlib-0.15rc1 » test » 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 » Python X Library 
Python X Library » python xlib 0.15rc1 » test » test_rdb.py
#!/usr/bin/env python

import sys
import os

sys.path.insert(1, os.path.join(sys.path[0], '..'))

import Xlib.rdb

import unittest

resources = """
! Single component

single: name
Single: class
?: wild

! name vs class vs ?

p.first.second: n.n
p.first.Second: n.c
p.first.?: n.w

p.First.second: c.n
p.First.Second: c.c
p.First.?: c.w

p.?.second: w.n
p.?.Second: w.c
p.?.?: w.w

! Tight over loose bindings

b.tight.match: tight
b.tight*match: bad
b.loose*match: loose

! skip matches

s.*end: default
s.foo*end: default foo
s.foo.bar.end: bar foo

! Multiple skip matches

ss.*mid*end: default
ss.foo*mid*end: default foo
ss.foo*mid.bar*end: bar foo

! First component unbound

*fie.fum: skipfirst
fie.fum: matchtwo
feh.fie.fum: matchfirst
"""

queries = (
    # Single component
    ('single', 'Single', 'name'),
    ('noname', 'Single', 'class'),
    ('noname', 'Noclass', 'wild'),

    # Name vs class vs ?

    ('p.first.second', 'P.First.Second', 'n.n'),
    ('p.first.noname', 'P.First.Second', 'n.c'),
    ('p.first.noname', 'P.First.Noclass', 'n.w'),

    ('p.noname.second', 'P.First.Second', 'c.n'),
    ('p.noname.noname', 'P.First.Second', 'c.c'),
    ('p.noname.noname', 'P.First.Noclass', 'c.w'),

    ('p.noname.second', 'P.Noclass.Second', 'w.n'),
    ('p.noname.noname', 'P.Noclass.Second', 'w.c'),
    ('p.noname.noname', 'P.Noclass.Noclass', 'w.w'),

    # Tight over loose bindings

    ('b.tight.match', 'B.Tight.Match', 'tight'),
    ('b.loose.match', 'B.Loose.Match', 'loose'),

    # skip matches

    ('s.bar.end', 'S.Bar.End', 'default'),
    ('s.foo.bar.end', 'S.Foo.Bar.End', 'bar foo'),
    ('s.foo.gazonk.end', 'S.Foo.Gazonk.End', 'default foo'),

    # Multiple skip matches

    ('ss.x.mid.x.end', 'Ss.X.Mid.X.End', 'default'),
    ('ss.foo.x.mid.x.end', 'Ss.Foo.X.Mid.X.End', 'default foo'),
    ('ss.foo.x.mid.bar.x.end', 'Ss.Foo.X.Mid.Bar.X.End', 'bar foo'),
    ('ss.foo.mid.x.mid.bar.x.end', 'Ss.Foo.Mid.X.Mid.Bar.X.End', 'default foo'),
    ('ss.foo.x.mid.x.mid.bar.x.end', 'Ss.Foo.X.Mid.X.Mid.Bar.X.End', 'default foo'),

    # First component unbound
    ('fie.fum', 'Fie.Fum', 'matchtwo'),
    ('noname.fie.fum', 'Noclass.Fie.Fum', 'skipfirst'),
    ('feh.fie.fum', 'Feh.Fie.Fum', 'matchfirst'),
    )

resource_set1 = (
    ('foo.bar', 1,),
    ('foo.bar.gazonk', 2),
    ('*bar*gazonk', 3),
    )

resource_set2 = (
    ('foo.bar', 10,),     # Changing the value of an item
    ('foo.bar.whee', 11), # Adding entries to existing component
    ('foo.bar*whoho', 12),
    ('foo.fie', 13),      # Copy new resources
    ('foo.fie*fum', 14),
    ('*foo.bar', 15),
    )

class TestRDB(unittest.TestCase):
    def testParseAndQuery(self):
        # Test string parsing and querying
        db = Xlib.rdb.ResourceDB(string = resources)
        for name, cls, value in queries:
            try:
                v = db[name, cls]
            except KeyError:
                raise AssertionError('Value not found for %s/%s:\n    expected %s' % (name, cls, value))

            if v != value:
                raise AssertionError('Value mismatch for %s/%s:\n    expected %s, got %s' % (name, cls, value, v))


    def testUpdate(self):
        # Test update.  An update should have the same result as
        # inserting all the resource entries in the manually

        db1 = Xlib.rdb.ResourceDB()
        db2 = Xlib.rdb.ResourceDB()
        db3 = Xlib.rdb.ResourceDB()

        db1.insert_resources(resource_set1)
        db2.insert_resources(resource_set2)

        db1.update(db2)

        db3.insert_resources(resource_set1)
        db3.insert_resources(resource_set2)

        assert db1.db == db3.db


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.