def test_constructors(self):
        '''Constructors'''
        eq = self.assertEqual

        eq(ini().keys(), [])

        i = ini(answer='42', witch='guilty')
        i["foo"] = properties(answer='43')
        i["bar"] = properties(witch='innocent')
        eq(i['foo']['answer'], '43')
        eq(i['bar']['witch'], 'innocent')
        eq(i.get('foo', 'answer'), '43')
        eq(i.get('bar', 'witch'), 'innocent')

        eq(i.get('foo', 'witch'), 'guilty')
        eq(i.get('bar', 'answer'), '42')

        i = ini(self.inifile, answer=43, witch='alwaysguilty')
        eq(i['Foo Bar']['foo'], 'bar')
        eq(i.get('Foo Bar', 'answer'), 43)
        eq(i.get('Internationalized Stuff', 'witch'), 'alwaysguilty')
        eq(i.get('Internationalized Stuff', 'foo'), 'Default')

        i = ini({
            'toto': 'tata',
            'titi': 'toutou'
        },
                answer=43,
                witch='alwaysguilty')
        i['tata'] = properties()
        eq(i.get('tata', 'toto'), 'tata')
        eq(i.get('tata', 'titi'), 'toutou')
        eq(i.get('tata', 'answer'), 43)
示例#2
0
    def test_constructors(self):
        '''Constructors'''
        eq=self.assertEqual

        eq( ini().keys(), [] )

        i=ini( answer='42', witch='guilty' )
        i["foo"]=properties(answer='43')
        i["bar"]=properties(witch='innocent')
        eq( i['foo']['answer'], '43' )
        eq( i['bar']['witch'], 'innocent' )
        eq( i.get('foo', 'answer'), '43' )
        eq( i.get('bar', 'witch'),  'innocent')

        eq( i.get('foo', 'witch'), 'guilty' )
        eq( i.get('bar', 'answer'), '42' )
        
        i=ini( self.inifile, answer=43, witch='alwaysguilty' )
        eq( i['Foo Bar']['foo'], 'bar' )
        eq( i.get('Foo Bar','answer'), 43 )
        eq( i.get('Internationalized Stuff','witch'), 'alwaysguilty' )
        eq( i.get('Internationalized Stuff','foo'), 'Default' )

        i=ini( {'toto':'tata', 'titi':'toutou' }, answer=43, witch='alwaysguilty' )
        i['tata']=properties()
        eq( i.get('tata','toto'), 'tata' )
        eq( i.get('tata','titi'), 'toutou' )
        eq( i.get('tata','answer'), 43 )
示例#3
0
    def test_update(self):
        '''Update'''
        
        properties( {'abc':'bingo', 'titi':'toto'}, abd="Le hip hopppp").write(self.keyvalfile)

        correct="""
abc = bingo  # comment
# commentaire
 abd =   Le hip hopppp   ; Houu its a comment
titi=toto
"""
        self.assertEqual(file(self.keyvalfile).read(),correct)
示例#4
0
    def test_scenario1(self):
        '''Scenario 1.'''

        properties( {'abc':'changed','titi':'toutou'}, abd="Trans go#a").write(self.keyvalfile)

        correct="""
abc = changed  # comment
# commentaire
 abd =   Trans go#a   ; Houu its a comment
titi=toutou
"""
        self.assertEqual(file(self.keyvalfile).read(),correct)
    def test_scenario1(self):
        '''Scenario 1.'''

        properties({
            'abc': 'changed',
            'titi': 'toutou'
        }, abd="Trans go#a").write(self.keyvalfile)

        correct = """
abc = changed  # comment
# commentaire
 abd =   Trans go#a   ; Houu its a comment
titi=toutou
"""
        self.assertEqual(file(self.keyvalfile).read(), correct)
    def test_update(self):
        '''Update'''

        properties({
            'abc': 'bingo',
            'titi': 'toto'
        }, abd="Le hip hopppp").write(self.keyvalfile)

        correct = """
abc = bingo  # comment
# commentaire
 abd =   Le hip hopppp   ; Houu its a comment
titi=toto
"""
        self.assertEqual(file(self.keyvalfile).read(), correct)
示例#7
0
    def test_read(self):
        '''Read'''

        i=properties()
        i.read(self.keyvalfile)
        self.assertEqual(i['abc'], 'val1')
        self.assertEqual(i['abd'], 'le zouuuuk')
    def test_read(self):
        '''Read'''

        i = properties()
        i.read(self.keyvalfile)
        self.assertEqual(i['abc'], 'val1')
        self.assertEqual(i['abd'], 'le zouuuuk')
示例#9
0
    def test_constructors(self):
        '''Constructors'''
        eq=self.assertEqual

        eq( properties().keys(), [] )

        i=properties( answer=42, witch='guilty' )
        eq( i['answer'], '42' )
        eq( i['witch'], 'guilty' )

        i=properties( self.keyvalfile, answer=43, witch='alwaysguilty' )
        eq( i['abc'], 'val1' )
        eq( i['answer'], '43' )
        eq( i['witch'], 'alwaysguilty' )

        i=properties( {'toto':'tata', 'titi':'toutou' }, answer=43, witch='alwaysguilty' )
        eq( i['toto'], 'tata' )
        eq( i['titi'], 'toutou' )
        eq( i['answer'], '43' )
示例#10
0
    def test_dustbin(self):
        '''Deleting values'''
        i=properties()
        del i['tata']
        del i['toto']
        i['toto'] = '45'

        self.assertEqual( i['toto'], '45' )
        self.assertEqual( 'tata' in i.dustbin, True)
        self.assertEqual( 'toto' not in i.dustbin, True)
    def test_dustbin(self):
        '''Deleting values'''
        i = properties()
        del i['tata']
        del i['toto']
        i['toto'] = '45'

        self.assertEqual(i['toto'], '45')
        self.assertEqual('tata' in i.dustbin, True)
        self.assertEqual('toto' not in i.dustbin, True)
    def test_variables(self):
        '''Variables'''
        i = ini()
        i['section'] = properties()
        i['section']['tata'] = 1
        i['section']['toto'] = "$tata"
        i['section']['titi'] = "123$toto"

        self.assertEqual(i['section']['tata'], '1')
        self.assertEqual(i['section'].get('toto'), '1')
        self.assertEqual(i['section'].get('titi'), '1231')
    def test_write(self):
        '''Write'''
        kv = properties()
        kv['answer'], kv['witch'] = 43, 'alwaysguilty'
        kv['tata'] = 3
        del kv['tata']
        del kv['witch']
        kv.write(self.emptyfile)
        correct = '''answer=43
'''
        self.assertEqual(file(self.emptyfile).read(), correct)
示例#14
0
    def test_write(self):
        '''Write'''
        kv=properties()
        kv['answer'], kv['witch'] = 43, 'alwaysguilty'
        kv['tata']=3
        del kv['tata']
        del kv['witch']
        kv.write(self.emptyfile)
        correct='''answer=43
'''
        self.assertEqual(file(self.emptyfile).read(),correct)
示例#15
0
    def test_variables(self):
        '''Variables'''
        i=ini()
        i['section']=properties()
        i['section']['tata']= 1
        i['section']['toto']= "$tata"
        i['section']['titi'] ="123$toto" 

        self.assertEqual( i['section']['tata'], '1' )
        self.assertEqual( i['section'].get('toto'), '1')
        self.assertEqual( i['section'].get('titi'), '1231')
示例#16
0
    def test_write(self):
        '''Write'''
        i=ini()
        i['section']=properties()
        i['section']['answer'], i['section']['witch'] = 43, 'alwaysguilty'
        i['section']['tata']=3
        del i['section']['tata']
        del i['section']['witch']
        i.write(self.emptyfile)
        correct='''[section]\nanswer=43\n
'''
        self.assertEqual(file(self.emptyfile).read(),correct)
    def test_write(self):
        '''Write'''
        i = ini()
        i['section'] = properties()
        i['section']['answer'], i['section']['witch'] = 43, 'alwaysguilty'
        i['section']['tata'] = 3
        del i['section']['tata']
        del i['section']['witch']
        i.write(self.emptyfile)
        correct = '''[section]\nanswer=43\n
'''
        self.assertEqual(file(self.emptyfile).read(), correct)
    def test_constructors(self):
        '''Constructors'''
        eq = self.assertEqual

        eq(properties().keys(), [])

        i = properties(answer=42, witch='guilty')
        eq(i['answer'], '42')
        eq(i['witch'], 'guilty')

        i = properties(self.keyvalfile, answer=43, witch='alwaysguilty')
        eq(i['abc'], 'val1')
        eq(i['answer'], '43')
        eq(i['witch'], 'alwaysguilty')

        i = properties({
            'toto': 'tata',
            'titi': 'toutou'
        },
                       answer=43,
                       witch='alwaysguilty')
        eq(i['toto'], 'tata')
        eq(i['titi'], 'toutou')
        eq(i['answer'], '43')
    def test_scenario2(self):
        '''Scenario 2.'''
        kv = properties(self.keyvalfile, abc="Shakira")
        kv['tata'] = "Mul,\nti,\nPle,\nlines"
        kv['pain'] = 'beurre'
        del kv['pain']
        del kv['abc']
        kv.write()

        correct = """
# commentaire
 abd =   le zouuuuk   ; Houu its a comment
tata=Mul,
	ti,
	Ple,
	lines
"""
        self.assertEqual(file(self.keyvalfile).read(), correct)
示例#20
0
    def test_scenario2(self):
        '''Scenario 2.'''
        kv=properties( self.keyvalfile, abc="Shakira" )
        kv['tata'] = "Mul,\nti,\nPle,\nlines"
        kv['pain']='beurre'
        del kv['pain']
        del kv['abc']
        kv.write()
        
        correct="""
# commentaire
 abd =   le zouuuuk   ; Houu its a comment
tata=Mul,
	ti,
	Ple,
	lines
"""
        self.assertEqual(file(self.keyvalfile).read(),correct)
示例#21
0
    if not os.path.isfile(arg[0]):
        raise Exception, "First argument must be a file"

    if o.set:
        for a in arg[1:]:
            if a.find('=') == -1:
                raise Exception, "Options to be set must follow the format: 'opt=val'"

    return o, arg


if __name__ == '__main__':

    try:
        o, arg = parse_arguments()

        if o.set:
            d = dict([a.split('=') for a in arg[1:]])
            properties(d).apply_to(arg[0])

        elif o.delete:
            properties().delete(arg[1:]).apply_to(arg[0])

        else:
            print "\t".join(properties(arg[0]).get(arg[1:]))

    except Exception, e:
        print >> sys.stderr, "Problem :", e
        sys.exit(-1)
示例#22
0
    if o.set:
        for a in arg[1:]:
            if a.find('=')==-1:
                raise Exception, "Options to be set must follow the format: 'opt=val'"

    return o, arg

if __name__ == '__main__':

    try:
        o, arg = parse_arguments()

        if o.set:
            d=dict( [ a.split('=') for a in arg[1:] ] )
            properties( d ).apply_to( arg[0] )

        elif o.delete:
            properties().delete( arg[1:] ).apply_to( arg[0] )

        else:
            print "\t".join( properties( arg[0] ).get( arg[1:] ) )

    except Exception,e:
        print >> sys.stderr, "Problem :", e
        sys.exit(-1)