26 try: |
26 try: |
27 from xml.etree import cElementTree as ElementTree |
27 from xml.etree import cElementTree as ElementTree |
28 except ImportError: |
28 except ImportError: |
29 from xml.etree import ElementTree |
29 from xml.etree import ElementTree |
30 |
30 |
31 import __init__ |
|
32 |
|
33 from ruleplugin import ruleml, relations |
31 from ruleplugin import ruleml, relations |
34 from cone.public import api, exceptions, utils, plugin |
32 from cone.public import api, exceptions, utils, plugin |
35 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
33 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
36 |
34 |
37 ruleml_string = \ |
35 ruleml_string = \ |
38 '''<?xml version="1.0" encoding="UTF-8"?> |
36 '''<?xml version="1.0" encoding="UTF-8"?> |
39 <ruleml xmlns="http://www.s60.com/xml/ruleml/2"> |
37 <ruleml xmlns="http://www.s60.com/xml/ruleml/3"> |
40 <rule>imaker.imagetarget configures imakerapi.outputLocation = imaker.imagetarget</rule> |
38 <rule>${imaker.imagetarget} configures ${imakerapi.outputLocation} = ${imaker.imagetarget}</rule> |
41 <rule>imaker.imagename configures imakerapi.outputLocation = imaker.imagename</rule> |
39 <rule>${imaker.imagename} configures ${imakerapi.outputLocation} = ${imaker.imagename}</rule> |
42 </ruleml> |
40 </ruleml> |
43 ''' |
41 ''' |
44 |
42 |
45 class TestParseRuleimpl(unittest.TestCase): |
43 class TestParseRuleimpl(unittest.TestCase): |
46 def setUp(self): relations.register() |
|
47 def tearDown(self): relations.unregister() |
|
48 |
44 |
49 def test_parse_rules(self): |
45 def test_parse_rules(self): |
50 etree = ElementTree.fromstring(ruleml_string) |
46 etree = utils.etree.fromstring(ruleml_string) |
51 reader = ruleml.RuleImplReader2(None, None) |
47 reader = ruleml.RuleImplReader(None, None) |
52 rules = reader.parse_rules(etree) |
48 rules = reader.parse_rules("", etree) |
53 self.assertTrue(isinstance(rules[0],relations.ConfigureRelation)) |
49 self.assertTrue(isinstance(rules[0],relations.ConfigureRelation)) |
54 self.assertTrue(isinstance(rules[1],relations.ConfigureRelation)) |
50 self.assertTrue(isinstance(rules[1],relations.ConfigureRelation)) |
55 self.assertTrue(rules[0].has_ref('imaker.imagetarget')) |
51 self.assertTrue(rules[0].has_ref('imaker.imagetarget')) |
56 self.assertFalse(rules[0].has_ref('imakerapi.imagename')) |
52 self.assertFalse(rules[0].has_ref('imakerapi.imagename')) |
57 self.assertTrue(rules[0].has_ref('imakerapi.outputLocation')) |
53 self.assertTrue(rules[0].has_ref('imakerapi.outputLocation')) |
58 |
54 |
59 |
55 |
60 class TestRulemlFromFile(unittest.TestCase): |
56 class TestRulemlFromFile(unittest.TestCase): |
61 def setUp(self): pass |
|
62 def tearDown(self): relations.unregister() |
|
63 |
57 |
64 def test_create_from_file(self): |
58 def test_create_from_file(self): |
65 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
59 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
66 config = project.get_configuration('root.confml') |
60 config = project.get_configuration('root.confml') |
67 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/rules.ruleml', config)[0] |
61 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/rules.ruleml', config)[0] |
68 relation_container = ruleimpl.get_relation_container() |
62 relation_container = ruleimpl.get_relation_container() |
69 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
63 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
70 self.assertEquals(relation_container.get_relation_count(), 17) |
64 self.assertEquals(relation_container.get_relation_count(), 19) |
71 |
65 self.assertEquals(len(relation_container.get_relations()), 19) |
|
66 self.assertEquals(relation_container.get_relations()[0].get_refs(),[u'imaker.imagetarget']) |
|
67 self.assertEquals(relation_container.get_relations()[0].implml.ref, 'implml/rules.ruleml') |
|
68 |
72 def test_create_from_file_with_common_container(self): |
69 def test_create_from_file_with_common_container(self): |
73 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
70 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
74 config = project.get_configuration('root.confml') |
71 config = project.get_configuration('root.confml') |
75 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/container_with_rules.ruleml', config)[0] |
72 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/container_with_rules.ruleml', config)[0] |
76 relation_container = ruleimpl.get_relation_container() |
73 relation_container = ruleimpl.get_relation_container() |
77 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
74 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
78 self.assertEquals(relation_container.get_relation_count(), 7) |
75 self.assertEquals(relation_container.get_relation_count(), 8) |
79 |
76 |
80 def test_create_from_file_filename(self): |
77 def test_create_from_file_filename(self): |
81 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
78 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
82 config = project.get_configuration('root.confml') |
79 config = project.get_configuration('root.confml') |
83 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/filename_rules.ruleml', config)[0] |
80 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/filename_rules.ruleml', config)[0] |