40 SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..')) |
40 SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..')) |
41 assert os.path.split(SOURCE_ROOT)[1] == 'source' |
41 assert os.path.split(SOURCE_ROOT)[1] == 'source' |
42 cmd = 'python "%s" %s' % (os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts/cone_tool.py')), action) |
42 cmd = 'python "%s" %s' % (os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts/cone_tool.py')), action) |
43 return cmd |
43 return cmd |
44 |
44 |
|
45 def get_uses_layer_test_project(): |
|
46 # If running from the working copy |
|
47 dir1 = os.path.normpath(os.path.join(ROOT_PATH, '../ConeRulePlugin/ruleplugin/evals/tests/layer_filtering_project')) |
|
48 if os.path.isdir(dir1): return dir1 |
|
49 |
|
50 # If running from standalone |
|
51 dir2 = os.path.normpath(os.path.join(ROOT_PATH, 'testdata/uses_layer_test_project')) |
|
52 if os.path.isdir(dir2): return dir2 |
|
53 |
|
54 raise RuntimeError("layers_used() test project found neither in '%s' nor '%s'!" % (dir1, dir2)) |
|
55 |
45 class TestCommonGenerateAllImplsOnLastLayer(BaseTestCase): |
56 class TestCommonGenerateAllImplsOnLastLayer(BaseTestCase): |
46 |
57 |
47 def _prepare_workdir(self, workdir): |
58 def _prepare_workdir(self, workdir): |
48 workdir = os.path.join(ROOT_PATH, workdir) |
59 workdir = os.path.join(ROOT_PATH, workdir) |
49 self.recreate_dir(workdir) |
60 self.recreate_dir(workdir) |
65 self.remove_if_exists(project_zip) |
76 self.remove_if_exists(project_zip) |
66 zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN]) |
77 zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN]) |
67 self.assert_exists_and_contains_something(project_zip) |
78 self.assert_exists_and_contains_something(project_zip) |
68 |
79 |
69 self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip) |
80 self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip) |
|
81 |
|
82 def test_uses_layers_rule(self): |
|
83 project_dir = get_uses_layer_test_project() |
|
84 self.assert_exists_and_contains_something(project_dir) |
|
85 |
|
86 orig_workdir = os.getcwd() |
|
87 workdir = self._prepare_workdir("temp/uses_layers_test") |
|
88 os.chdir(workdir) |
|
89 |
|
90 try: |
|
91 cmd = '%s -p "%s" --output output --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project_dir) |
|
92 self.run_command(cmd) |
|
93 |
|
94 self.assert_file_contents_equal( |
|
95 os.path.join(ROOT_PATH, "testdata/uses_layers_test_expected.txt"), |
|
96 "output/uses_layers_test.txt", |
|
97 ignore_endline_style=True) |
|
98 finally: |
|
99 os.chdir(orig_workdir) |
|
100 |
|
101 def test_override_templateml_outputattribs_from_cmd_line(self): |
|
102 project_dir = os.path.join(ROOT_PATH, 'testdata', 'templateml_test_project') |
|
103 |
|
104 #Added because of known bug #1018 (test data missing) |
|
105 # Remove after fix -> |
|
106 if os.path.isdir(project_dir): |
|
107 if len(os.listdir(project_dir)) == 0: |
|
108 self.fail("Path '%s' exists (is a directory) but does not contain anything)" % project_dir) |
|
109 elif os.path.isfile(project_dir): |
|
110 if os.stat(project_dir).st_size == 0: |
|
111 self.fail("Path '%s' exists (is a file) but does not contain anything)" % project_dir) |
|
112 else: |
|
113 self.fail("Known bug #1018: Test data missing. Path '%s' does not exist" % project_dir) |
|
114 # Remove after fix <- |
|
115 |
|
116 self.assert_exists_and_contains_something(project_dir) |
|
117 |
|
118 workdir = os.getcwd() |
|
119 workdir = self._prepare_workdir(os.path.join('temp','gen_tmplml_out_from_cmd_line')) |
|
120 |
|
121 logfile = os.path.join(workdir, 'cone.log') |
|
122 |
|
123 file1 = os.path.join(workdir,'setdir','setfile1.txt') |
|
124 file2 = os.path.join(workdir,'setdir','setfile2.txt') |
|
125 |
|
126 cmd = ['%(cone_cmd)s', |
|
127 '-p "%(project)s"', |
|
128 '-c root.confml', |
|
129 '--output "%(output)s"', |
|
130 '--log-file="%(log_file)s"', |
|
131 '--all-layers', |
|
132 '--set=Tempfeature.Outputfile1=setfile1.txt', |
|
133 '--set=Tempfeature.Outputfile2=setfile2.txt', |
|
134 '--set=Tempfeature.Outputdir=setdir', |
|
135 '--set=Tempfeature.Encoding=UTF-16', |
|
136 '--set=Tempfeature.BOM=false', |
|
137 '--set=Tempfeature.Newline=unix',] |
|
138 cmd = ' '.join(cmd) % {'cone_cmd': get_cmd(), |
|
139 'project': project_dir, |
|
140 'output': workdir, |
|
141 'log_file': logfile} |
|
142 |
|
143 self.run_command(cmd) |
|
144 |
|
145 self.assert_exists_and_contains_something(os.path.join(workdir,'setdir')) |
|
146 self.assert_file_contains(file1, ['TempFeature.Outputfile1: setfile1.txt', |
|
147 'TempFeature.Outputdir: setdir', |
|
148 'TempFeature.Encoding: UTF-16', |
|
149 'TempFeature.BOM: false', |
|
150 'TempFeature.Newline: unix'], |
|
151 encoding='UTF-16') |
|
152 self.assert_file_contains(file2, ['TempFeature.Outputfile2: setfile2.txt', |
|
153 'TempFeature.Outputdir: setdir', |
|
154 'TempFeature.Encoding: UTF-8', |
|
155 'TempFeature.BOM: true', |
|
156 'TempFeature.Newline: win']) |
|
157 |
|
158 |
|
159 def test_set_tempvariables_as_templateml_outputattribs(self): |
|
160 project_dir = os.path.join(ROOT_PATH, 'testdata', 'templateml_test_project') |
|
161 |
|
162 #Added because of known bug #1018 (test data missing) |
|
163 # Remove after fix -> |
|
164 if os.path.isdir(project_dir): |
|
165 if len(os.listdir(project_dir)) == 0: |
|
166 self.fail("Path '%s' exists (is a directory) but does not contain anything)" % project_dir) |
|
167 elif os.path.isfile(project_dir): |
|
168 if os.stat(project_dir).st_size == 0: |
|
169 self.fail("Path '%s' exists (is a file) but does not contain anything)" % project_dir) |
|
170 else: |
|
171 self.fail("Known bug #1018: Test data missing. Path '%s' does not exist" % project_dir) |
|
172 # Remove after fix <- |
|
173 |
|
174 self.assert_exists_and_contains_something(project_dir) |
|
175 |
|
176 workdir = os.getcwd() |
|
177 workdir = self._prepare_workdir(os.path.join('temp','gen_tmplml_out_from_ref')) |
|
178 |
|
179 logfile = os.path.join(workdir, 'cone.log') |
|
180 |
|
181 file1 = os.path.join(workdir,'origdir','orig1.txt') |
|
182 file2 = os.path.join(workdir,'origdir','orig2.txt') |
|
183 |
|
184 cmd = ['%(cone_cmd)s', |
|
185 '-p "%(project)s"', |
|
186 '-c root.confml', |
|
187 '--output "%(output)s"', |
|
188 '--log-file="%(log_file)s"', |
|
189 '--all-layers',] |
|
190 cmd = ' '.join(cmd) % {'cone_cmd': get_cmd(), |
|
191 'project': project_dir, |
|
192 'output': workdir, |
|
193 'log_file': logfile} |
|
194 |
|
195 self.run_command(cmd) |
|
196 |
|
197 self.assert_exists_and_contains_something(os.path.join(workdir,'origdir')) |
|
198 self.assert_file_contains(file1, ['TempFeature.Outputfile1: orig1.txt', |
|
199 'TempFeature.Outputdir: origdir', |
|
200 'TempFeature.Encoding: ASCII', |
|
201 'TempFeature.BOM: true', |
|
202 'TempFeature.Newline: win']) |
|
203 self.assert_file_contains(file2, ['TempFeature.Outputfile2: orig2.txt', |
|
204 'TempFeature.Outputdir: origdir', |
|
205 'TempFeature.Encoding: UTF-8', |
|
206 'TempFeature.BOM: true', |
|
207 'TempFeature.Newline: win']) |
70 |
208 |
71 def _run_test_generate_all_impls_on_last_layer(self, workdir, project): |
209 def _run_test_generate_all_impls_on_last_layer(self, workdir, project): |
72 # Create a temp workdir and go there to run the test |
210 # Create a temp workdir and go there to run the test |
73 orig_workdir = os.getcwd() |
211 orig_workdir = os.getcwd() |
74 workdir = self._prepare_workdir(workdir) |
212 workdir = self._prepare_workdir(workdir) |