Skip to content

Commit

Permalink
lang: fixes for invalid detection on class.property, numeric was also…
Browse files Browse the repository at this point in the history
… taken as a class.property. Closes #34
  • Loading branch information
Mathieu Virbel committed Feb 10, 2011
1 parent fcc1c20 commit d05fb26
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kivy/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def create_handler(element, key, value, idmap):
tmp = re.sub('([\'"][^\'"]*[\'"])', '', value)

# detect key.value inside value
kw = re.findall('([a-zA-Z0-9_.]+\.[a-zA-Z0-9_.]+)', tmp)
kw = re.findall('([a-zA-Z_][a-zA-Z0-9_.]*\.[a-zA-Z0-9_.]+)', tmp)
if not kw:
# look like no reference, just pass it
return eval(value, _eval_globals)
Expand Down
44 changes: 44 additions & 0 deletions kivy/tests/test_lang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'''
Language tests
==============
'''

import unittest

class TestClass(object):
obj = None

class LangTestCase(unittest.TestCase):

def import_builder(self):
from kivy.factory import Factory
from kivy.lang import Builder
Factory.register('TestClass', cls=TestClass)
return Builder

def test_loading_failed_1(self):
# invalid indent
Builder = self.import_builder()
from kivy.lang import ParserError
try:
Builder.load_string('''#:kivy 1.0
<TestClass>:
''')
self.fail('Invalid indentation.')
except ParserError:
pass

def test_parser_numeric_1(self):
Builder = self.import_builder()
Builder.load_string('<TestClass>:\n\tobj: (.5, .5, .5)')
wid = TestClass()
Builder.apply(wid)
self.assertEqual(wid.obj, (0.5, 0.5, 0.5))

def test_parser_numeric_2(self):
Builder = self.import_builder()
Builder.load_string('<TestClass>:\n\tobj: (0.5, 0.5, 0.5)')
wid = TestClass()
Builder.apply(wid)
self.assertEqual(wid.obj, (0.5, 0.5, 0.5))

0 comments on commit d05fb26

Please sign in to comment.