|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 """ |
|
18 Test the configuration |
|
19 """ |
|
20 import string |
|
21 import unittest |
|
22 import os |
|
23 |
|
24 from scripttest_common import get_cmd |
|
25 from testautomation.base_testcase import BaseTestCase |
|
26 |
|
27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
28 TEMP_DIR = os.path.join(ROOT_PATH, 'temp/validate') |
|
29 TESTDATA_DIR = os.path.join(ROOT_PATH, 'testdata/validate') |
|
30 TEST_TEMPLATE = os.path.join(TESTDATA_DIR, 'template.txt') |
|
31 |
|
32 class TestValidate(BaseTestCase): |
|
33 |
|
34 def test_get_help(self): |
|
35 cmd = '%s -h' % get_cmd('validate') |
|
36 out = self.run_command(cmd) |
|
37 lines = out.split(os.linesep) |
|
38 self.assertTrue('Options:' in lines) |
|
39 self.assertTrue(' Validate options:' in lines) |
|
40 |
|
41 def _run_test_validate(self, args, report_file, template=None, report_type=None, assert_file=True): |
|
42 REPORT_FILE = os.path.join(TEMP_DIR, report_file) |
|
43 self.remove_if_exists(REPORT_FILE) |
|
44 |
|
45 cmd = '%(cmd)s %(args)s --report "%(report)s"' \ |
|
46 % {'cmd' : get_cmd('validate'), |
|
47 'args' : args, |
|
48 'report' : REPORT_FILE} |
|
49 if template: |
|
50 cmd = cmd + ' --template "%s"' % template |
|
51 if report_type: |
|
52 cmd = cmd + ' --report-type %s' % report_type |
|
53 out = self.run_command(cmd) |
|
54 |
|
55 EXPECTED_FILE = os.path.join(TESTDATA_DIR, 'expected', report_file) |
|
56 if assert_file: |
|
57 self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE) |
|
58 return out |
|
59 |
|
60 def test_validate_templates(self): |
|
61 PROJECT = os.path.join(TESTDATA_DIR, 'project') |
|
62 CONFIG = 'errors_root.confml' |
|
63 self._run_test_validate( |
|
64 args = '-p "%s" -c %s' % (PROJECT, CONFIG), |
|
65 report_type = 'xml', |
|
66 report_file = 'report.xml') |
|
67 |
|
68 def test_validate_invalid_configuration(self): |
|
69 PROJECT = os.path.join(TESTDATA_DIR, 'project') |
|
70 CONFIG = 'errors_root.confml' |
|
71 self._run_test_validate( |
|
72 args = '-p "%s" -c %s' % (PROJECT, CONFIG), |
|
73 report_file = 'invalid_config_report.txt', |
|
74 template = TEST_TEMPLATE) |
|
75 |
|
76 def test_validate_valid_configuration(self): |
|
77 PROJECT = os.path.join(TESTDATA_DIR, 'project') |
|
78 CONFIG = 'no_errors_root.confml' |
|
79 self._run_test_validate( |
|
80 args = '-p "%s" -c %s' % (PROJECT, CONFIG), |
|
81 report_file = 'valid_config_report.txt', |
|
82 template = TEST_TEMPLATE) |
|
83 |
|
84 def test_validate_invalid_file(self): |
|
85 orig_workdir = os.getcwd() |
|
86 os.chdir(ROOT_PATH) |
|
87 try: |
|
88 FILE = 'testdata/validate/project/assets/invalid/confml/invalid_type.confml' |
|
89 self._run_test_validate( |
|
90 args = '--confml-file %s' % FILE, |
|
91 report_file = 'invalid_file_report.txt', |
|
92 template = TEST_TEMPLATE) |
|
93 finally: |
|
94 os.chdir(orig_workdir) |
|
95 |
|
96 def test_dump_schema_files(self): |
|
97 OUTPUT_DIR = os.path.join(TEMP_DIR, 'schema_file_dump') |
|
98 self.remove_if_exists(OUTPUT_DIR) |
|
99 |
|
100 cmd = '%(cmd)s --dump-schema-files "%(output)s"' \ |
|
101 % {'cmd' : get_cmd('validate'), |
|
102 'output' : OUTPUT_DIR} |
|
103 self.run_command(cmd) |
|
104 |
|
105 def check(path): |
|
106 path = os.path.normpath(os.path.join(OUTPUT_DIR, path)) |
|
107 self.assert_exists_and_contains_something(path) |
|
108 check('confml/confml.xsd') |
|
109 check('confml/confml2.xsd') |
|
110 check('implml/implml.xsd') |
|
111 |
|
112 def _run_filtering_test(self, args, report_file): |
|
113 PROJECT = os.path.join(TESTDATA_DIR, 'project') |
|
114 CONFIG = 'errors_root.confml' |
|
115 return self._run_test_validate( |
|
116 args = '-p "%s" -c %s %s' % (PROJECT, CONFIG, args), |
|
117 report_file = report_file, |
|
118 template = TEST_TEMPLATE) |
|
119 |
|
120 def test_validate_only_confml(self): |
|
121 out = self._run_filtering_test( |
|
122 args = '--include-filter *.confml', |
|
123 report_file = 'report_only_confml.txt') |
|
124 self.assertTrue('Performing XML schema validation on ConfML files...' in out) |
|
125 self.assertTrue('Validating ConfML model...' in out) |
|
126 self.assertFalse('Performing XML schema validation on ImplML files...' in out) |
|
127 self.assertFalse('Validating implementations...' in out) |
|
128 |
|
129 def test_validate_multiple_confml(self): |
|
130 out = self._run_test_validate( |
|
131 args = '--confml-file "%s" --confml-file "%s"' % (os.path.join(TESTDATA_DIR, 'project/assets/invalid/confml/broken.confml'), |
|
132 os.path.join(TESTDATA_DIR, 'project/assets/invalid/confml/invalid_element.confml')), |
|
133 report_type = 'xml', |
|
134 report_file = 'report.xml', |
|
135 assert_file = False) |
|
136 out = "".join(out) |
|
137 self.assertTrue(string.find(out,"broken.confml")!=-1) |
|
138 self.assertTrue(string.find(out,"invalid_element.confml")!=-1) |
|
139 |
|
140 def test_validate_only_implml(self): |
|
141 out = self._run_filtering_test( |
|
142 args = '--include-filter *.implml', |
|
143 report_file = 'report_only_implml.txt') |
|
144 self.assertFalse('Performing XML schema validation on ConfML files...' in out) |
|
145 self.assertFalse('Validating ConfML model...' in out) |
|
146 self.assertTrue('Performing XML schema validation on ImplML files...' in out) |
|
147 self.assertTrue('Validating implementations...' in out) |
|
148 |
|
149 def test_validate_multiple_implml(self): |
|
150 out = self._run_test_validate( |
|
151 args = '--implml-file "%s" --implml-file "%s"' % (os.path.join(TESTDATA_DIR, 'project/assets/invalid/implml/broken.implml'), |
|
152 os.path.join(TESTDATA_DIR, 'project/assets/invalid/implml/invalid_attribute.implml')), |
|
153 report_type = 'xml', |
|
154 report_file = 'report.xml', |
|
155 assert_file = False) |
|
156 out = "".join(out) |
|
157 self.assertTrue(string.find(out,"broken.implml")!=-1) |
|
158 self.assertTrue(string.find(out,"invalid_attribute.implml")!=-1) |
|
159 |
|
160 def test_validate_only_model(self): |
|
161 out = self._run_filtering_test( |
|
162 args = '--include-filter model', |
|
163 report_file = 'report_only_model.txt') |
|
164 self.assertFalse('Performing XML schema validation on ConfML files...' in out) |
|
165 self.assertTrue('Validating ConfML model...' in out) |
|
166 self.assertFalse('Performing XML schema validation on ImplML files...' in out) |
|
167 self.assertTrue('Validating implementations...' in out) |
|
168 |
|
169 def test_validate_only_schema(self): |
|
170 out = self._run_filtering_test( |
|
171 args = '--include-filter schema', |
|
172 report_file = 'report_only_schema.txt') |
|
173 self.assertTrue('Performing XML schema validation on ConfML files...' in out) |
|
174 self.assertFalse('Validating ConfML model...' in out) |
|
175 self.assertTrue('Performing XML schema validation on ImplML files...' in out) |
|
176 self.assertFalse('Parsing implementations...' in out) |
|
177 self.assertFalse('Validating implementations...' in out) |
|
178 |
|
179 def test_validate_multiple_filters(self): |
|
180 self._run_filtering_test( |
|
181 args = '--include-filter schema --include-filter model.confml ' |
|
182 '--exclude-filter schema.confml ' |
|
183 '--exclude-filter model.confml.missing_feature_for_data', |
|
184 report_file = 'report_multiple_filters.txt') |
|
185 |
|
186 if __name__ == '__main__': |
|
187 unittest.main() |