laszlocsomor | a654505 | 2019-11-05 05:18:32 -0800 | [diff] [blame] | 1 | # pylint: disable=g-direct-third-party-import |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 2 | # Copyright 2018 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 16 | import io |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 17 | import os |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 18 | import unittest |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 19 | |
laszlocsomor | a654505 | 2019-11-05 05:18:32 -0800 | [diff] [blame] | 20 | # Do not edit this line. Copybara replaces it with PY2 migration helper. |
| 21 | from third_party.py import mock |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 22 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 23 | from src.main.protobuf import analysis_v2_pb2 |
| 24 | from tools.aquery_differ import aquery_differ |
| 25 | |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 26 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 27 | def make_aquery_output(action_objs, artifact_objs, path_fragment_objs): |
| 28 | action_graph = analysis_v2_pb2.ActionGraphContainer() |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 29 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 30 | for path_fragment_obj in path_fragment_objs: |
| 31 | path_fragment = action_graph.path_fragments.add() |
| 32 | path_fragment.id = path_fragment_obj["id"] |
| 33 | path_fragment.label = path_fragment_obj["label"] |
| 34 | if "parent_id" in path_fragment_obj: |
| 35 | path_fragment.parent_id = path_fragment_obj["parent_id"] |
| 36 | |
| 37 | for artifact_obj in artifact_objs: |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 38 | artifact = action_graph.artifacts.add() |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 39 | artifact.id = artifact_obj["id"] |
| 40 | artifact.path_fragment_id = artifact_obj["path_fragment_id"] |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 41 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 42 | for action_obj in action_objs: |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 43 | action = action_graph.actions.add() |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 44 | action.output_ids.extend(action_obj["output_ids"]) |
| 45 | action.arguments.extend(action_obj["arguments"]) |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 46 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 47 | if "input_dep_set_ids" in action_obj: |
| 48 | action.input_dep_set_ids.extend(action_obj["input_dep_set_ids"]) |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 49 | |
| 50 | return action_graph |
| 51 | |
| 52 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 53 | def make_aquery_output_with_dep_set(action_objs, artifact_objs, |
| 54 | path_fragment_objs, dep_set_objs): |
| 55 | action_graph = make_aquery_output(action_objs, artifact_objs, |
| 56 | path_fragment_objs) |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 57 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 58 | for ds in dep_set_objs: |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 59 | dep_set = action_graph.dep_set_of_files.add() |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 60 | dep_set.id = ds["id"] |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 61 | dep_set.direct_artifact_ids.extend(ds["direct_artifact_ids"]) |
| 62 | dep_set.transitive_dep_set_ids.extend(ds["transitive_dep_set_ids"]) |
| 63 | |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 64 | return action_graph |
| 65 | |
| 66 | |
| 67 | class CmdLineDifferTest(unittest.TestCase): |
| 68 | |
| 69 | def test_no_difference(self): |
| 70 | action_graph = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 71 | action_objs=[ |
| 72 | { |
| 73 | "arguments": ["-a", "-b"], |
| 74 | "output_ids": [1, 2] |
| 75 | }, |
| 76 | { |
| 77 | "arguments": ["-c"], |
| 78 | "output_ids": [3] |
| 79 | }, |
| 80 | ], |
| 81 | artifact_objs=[{ |
| 82 | "id": 1, |
| 83 | "path_fragment_id": 2 |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 84 | }, { |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 85 | "id": 2, |
| 86 | "path_fragment_id": 3 |
| 87 | }, { |
| 88 | "id": 3, |
| 89 | "path_fragment_id": 4 |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 90 | }], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 91 | path_fragment_objs=[ |
| 92 | { |
| 93 | "id": 1, |
| 94 | "label": "root" |
| 95 | }, |
| 96 | { |
| 97 | "id": 2, |
| 98 | "label": "foo", |
| 99 | "parent_id": 1 |
| 100 | }, |
| 101 | { |
| 102 | "id": 3, |
| 103 | "label": "bar", |
| 104 | "parent_id": 1 |
| 105 | }, |
| 106 | { |
| 107 | "id": 4, |
| 108 | "label": "baz", |
| 109 | "parent_id": 1 |
| 110 | }, |
| 111 | ]) |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 112 | mock_stdout = io.StringIO() |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 113 | attrs = ["cmdline"] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 114 | with mock.patch("sys.stdout", mock_stdout): |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 115 | aquery_differ._aquery_diff(action_graph, action_graph, attrs, "before", |
| 116 | "after") |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 117 | self.assertEqual(mock_stdout.getvalue(), "No difference\n") |
| 118 | |
| 119 | def test_no_difference_different_output_files_order(self): |
| 120 | first = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 121 | action_objs=[ |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 122 | { |
| 123 | "arguments": ["-a", "-b"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 124 | "output_ids": [1, 2] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 125 | }, |
| 126 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 127 | artifact_objs=[{ |
| 128 | "id": 1, |
| 129 | "path_fragment_id": 2 |
| 130 | }, { |
| 131 | "id": 2, |
| 132 | "path_fragment_id": 3 |
| 133 | }], |
| 134 | path_fragment_objs=[ |
| 135 | { |
| 136 | "id": 1, |
| 137 | "label": "root" |
| 138 | }, |
| 139 | { |
| 140 | "id": 2, |
| 141 | "label": "foo", |
| 142 | "parent_id": 1 |
| 143 | }, |
| 144 | { |
| 145 | "id": 3, |
| 146 | "label": "bar", |
| 147 | "parent_id": 1 |
| 148 | }, |
| 149 | ]) |
| 150 | |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 151 | second = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 152 | action_objs=[ |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 153 | { |
| 154 | "arguments": ["-a", "-b"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 155 | "output_ids": [2, 1] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 156 | }, |
| 157 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 158 | artifact_objs=[{ |
| 159 | "id": 1, |
| 160 | "path_fragment_id": 2 |
| 161 | }, { |
| 162 | "id": 2, |
| 163 | "path_fragment_id": 3 |
| 164 | }], |
| 165 | path_fragment_objs=[ |
| 166 | { |
| 167 | "id": 1, |
| 168 | "label": "root" |
| 169 | }, |
| 170 | { |
| 171 | "id": 2, |
| 172 | "label": "foo", |
| 173 | "parent_id": 1 |
| 174 | }, |
| 175 | { |
| 176 | "id": 3, |
| 177 | "label": "bar", |
| 178 | "parent_id": 1 |
| 179 | }, |
| 180 | ]) |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 181 | |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 182 | mock_stdout = io.StringIO() |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 183 | attrs = ["cmdline"] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 184 | with mock.patch("sys.stdout", mock_stdout): |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 185 | aquery_differ._aquery_diff(first, second, attrs, "before", "after") |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 186 | self.assertEqual(mock_stdout.getvalue(), "No difference\n") |
| 187 | |
| 188 | def test_first_has_extra_output_files(self): |
| 189 | first = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 190 | action_objs=[ |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 191 | { |
| 192 | "arguments": ["-a", "-b"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 193 | "output_ids": [1, 2] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 194 | }, |
| 195 | { |
| 196 | "arguments": ["-c"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 197 | "output_ids": [3] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 198 | }, |
| 199 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 200 | artifact_objs=[{ |
| 201 | "id": 1, |
| 202 | "path_fragment_id": 2 |
| 203 | }, { |
| 204 | "id": 2, |
| 205 | "path_fragment_id": 3 |
| 206 | }, { |
| 207 | "id": 3, |
| 208 | "path_fragment_id": 4 |
| 209 | }], |
| 210 | path_fragment_objs=[ |
| 211 | { |
| 212 | "id": 1, |
| 213 | "label": "root" |
| 214 | }, |
| 215 | { |
| 216 | "id": 2, |
| 217 | "label": "foo", |
| 218 | "parent_id": 1 |
| 219 | }, |
| 220 | { |
| 221 | "id": 3, |
| 222 | "label": "bar", |
| 223 | "parent_id": 1 |
| 224 | }, |
| 225 | { |
| 226 | "id": 4, |
| 227 | "label": "baz", |
| 228 | "parent_id": 1 |
| 229 | }, |
| 230 | ]) |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 231 | second = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 232 | action_objs=[ |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 233 | { |
| 234 | "arguments": ["-a", "-b"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 235 | "output_ids": [1, 2] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 236 | }, |
| 237 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 238 | artifact_objs=[{ |
| 239 | "id": 1, |
| 240 | "path_fragment_id": 2 |
| 241 | }, { |
| 242 | "id": 2, |
| 243 | "path_fragment_id": 3 |
| 244 | }], |
| 245 | path_fragment_objs=[{ |
| 246 | "id": 1, |
| 247 | "label": "root" |
| 248 | }, { |
| 249 | "id": 2, |
| 250 | "label": "foo", |
| 251 | "parent_id": 1 |
| 252 | }, { |
| 253 | "id": 3, |
| 254 | "label": "bar", |
| 255 | "parent_id": 1 |
| 256 | }]) |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 257 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 258 | baz_path = os.path.join("root", "baz") |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 259 | expected_error = ("Aquery output 'before' change contains an action " |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 260 | "that generates the following outputs that aquery " |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 261 | "output 'after' change doesn't:\n{}\n\n".format(baz_path)) |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 262 | mock_stdout = io.StringIO() |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 263 | attrs = ["cmdline"] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 264 | with mock.patch("sys.stdout", mock_stdout): |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 265 | aquery_differ._aquery_diff(first, second, attrs, "before", "after") |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 266 | self.assertEqual(mock_stdout.getvalue(), expected_error) |
| 267 | |
| 268 | def test_different_command_lines(self): |
| 269 | first = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 270 | action_objs=[ |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 271 | { |
| 272 | "arguments": ["-a", "-d"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 273 | "output_ids": [1, 2] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 274 | }, |
| 275 | { |
| 276 | "arguments": ["-c"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 277 | "output_ids": [3] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 278 | }, |
| 279 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 280 | artifact_objs=[{ |
| 281 | "id": 1, |
| 282 | "path_fragment_id": 2 |
| 283 | }, { |
| 284 | "id": 2, |
| 285 | "path_fragment_id": 3 |
| 286 | }, { |
| 287 | "id": 3, |
| 288 | "path_fragment_id": 4 |
| 289 | }], |
| 290 | path_fragment_objs=[ |
| 291 | { |
| 292 | "id": 1, |
| 293 | "label": "root" |
| 294 | }, |
| 295 | { |
| 296 | "id": 2, |
| 297 | "label": "foo", |
| 298 | "parent_id": 1 |
| 299 | }, |
| 300 | { |
| 301 | "id": 3, |
| 302 | "label": "bar", |
| 303 | "parent_id": 1 |
| 304 | }, |
| 305 | { |
| 306 | "id": 4, |
| 307 | "label": "baz", |
| 308 | "parent_id": 1 |
| 309 | }, |
| 310 | ]) |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 311 | second = make_aquery_output( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 312 | action_objs=[ |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 313 | { |
| 314 | "arguments": ["-a", "-b"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 315 | "output_ids": [1, 2] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 316 | }, |
| 317 | { |
| 318 | "arguments": ["-c", "-d"], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 319 | "output_ids": [3] |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 320 | }, |
| 321 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 322 | artifact_objs=[{ |
| 323 | "id": 1, |
| 324 | "path_fragment_id": 2 |
| 325 | }, { |
| 326 | "id": 2, |
| 327 | "path_fragment_id": 3 |
| 328 | }, { |
| 329 | "id": 3, |
| 330 | "path_fragment_id": 4 |
| 331 | }], |
| 332 | path_fragment_objs=[ |
| 333 | { |
| 334 | "id": 1, |
| 335 | "label": "root" |
| 336 | }, |
| 337 | { |
| 338 | "id": 2, |
| 339 | "label": "foo", |
| 340 | "parent_id": 1 |
| 341 | }, |
| 342 | { |
| 343 | "id": 3, |
| 344 | "label": "bar", |
| 345 | "parent_id": 1 |
| 346 | }, |
| 347 | { |
| 348 | "id": 4, |
| 349 | "label": "baz", |
| 350 | "parent_id": 1 |
| 351 | }, |
| 352 | ]) |
| 353 | |
| 354 | foo_path = os.path.join("root", "foo") |
| 355 | bar_path = os.path.join("root", "bar") |
| 356 | baz_path = os.path.join("root", "baz") |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 357 | |
| 358 | expected_error_one = "\n".join([ |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 359 | "Difference in the action that generates the following output(s):", |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 360 | "\t{}".format(baz_path), "--- before", "+++ after", "@@ -1 +1,2 @@", |
| 361 | " -c", "+-d", "\n" |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 362 | ]) |
| 363 | expected_error_two = "\n".join([ |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 364 | "Difference in the action that generates the following output(s):", |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 365 | "\t{}".format(bar_path), "\t{}".format(foo_path), "--- before", |
| 366 | "+++ after", "@@ -1,2 +1,2 @@", " -a", "--d", "+-b", "\n" |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 367 | ]) |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 368 | attrs = ["cmdline"] |
| 369 | |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 370 | mock_stdout = io.StringIO() |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 371 | with mock.patch("sys.stdout", mock_stdout): |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 372 | aquery_differ._aquery_diff(first, second, attrs, "before", "after") |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 373 | self.assertIn(expected_error_one, mock_stdout.getvalue()) |
| 374 | self.assertIn(expected_error_two, mock_stdout.getvalue()) |
| 375 | |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 376 | def test_different_inputs(self): |
| 377 | first = make_aquery_output_with_dep_set( |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 378 | action_objs=[{ |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 379 | "arguments": [], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 380 | "output_ids": [1, 2], |
| 381 | "input_dep_set_ids": [2] |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 382 | }], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 383 | artifact_objs=[{ |
| 384 | "id": 1, |
| 385 | "path_fragment_id": 2 |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 386 | }, { |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 387 | "id": 2, |
| 388 | "path_fragment_id": 3 |
| 389 | }], |
| 390 | path_fragment_objs=[ |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 391 | { |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 392 | "id": 1, |
| 393 | "label": "root" |
| 394 | }, |
| 395 | { |
| 396 | "id": 2, |
| 397 | "label": "foo", |
| 398 | "parent_id": 1 |
| 399 | }, |
| 400 | { |
| 401 | "id": 3, |
| 402 | "label": "bar", |
| 403 | "parent_id": 1 |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 404 | }, |
| 405 | ], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 406 | dep_set_objs=[{ |
| 407 | "id": 1, |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 408 | "transitive_dep_set_ids": [], |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 409 | "direct_artifact_ids": [1] |
| 410 | }, { |
| 411 | "id": 2, |
| 412 | "transitive_dep_set_ids": [1], |
| 413 | "direct_artifact_ids": [2] |
| 414 | }]) |
| 415 | second = make_aquery_output_with_dep_set( |
| 416 | action_objs=[ |
| 417 | { |
| 418 | "arguments": [], |
| 419 | "output_ids": [1, 2], |
| 420 | "input_dep_set_ids": [1] |
| 421 | }, |
| 422 | ], |
| 423 | artifact_objs=[{ |
| 424 | "id": 1, |
| 425 | "path_fragment_id": 2 |
| 426 | }, { |
| 427 | "id": 2, |
| 428 | "path_fragment_id": 3 |
| 429 | }], |
| 430 | path_fragment_objs=[ |
| 431 | { |
| 432 | "id": 1, |
| 433 | "label": "root" |
| 434 | }, |
| 435 | { |
| 436 | "id": 2, |
| 437 | "label": "foo", |
| 438 | "parent_id": 1 |
| 439 | }, |
| 440 | { |
| 441 | "id": 3, |
| 442 | "label": "bar", |
| 443 | "parent_id": 1 |
| 444 | }, |
| 445 | ], |
| 446 | dep_set_objs=[{ |
| 447 | "id": 1, |
| 448 | "transitive_dep_set_ids": [], |
| 449 | "direct_artifact_ids": [1] |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 450 | }]) |
| 451 | |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 452 | foo_path = os.path.join("root", "foo") |
| 453 | bar_path = os.path.join("root", "bar") |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 454 | expected_error_one = "\n".join([ |
| 455 | "Difference in the action that generates the following output(s):", |
leba | 36c5d3d | 2020-12-14 07:09:37 -0800 | [diff] [blame] | 456 | "\t{}".format(bar_path), "\t{}".format(foo_path), "--- before", |
| 457 | "+++ after", "@@ -1,2 +1 @@", "-{}".format(bar_path), |
| 458 | " {}".format(foo_path), "\n" |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 459 | ]) |
| 460 | attrs = ["inputs"] |
| 461 | |
Tony Aiuto | 9a2d367 | 2022-08-24 00:46:17 -0700 | [diff] [blame] | 462 | mock_stdout = io.StringIO() |
leba | 3575797 | 2019-02-08 02:03:12 -0800 | [diff] [blame] | 463 | with mock.patch("sys.stdout", mock_stdout): |
| 464 | aquery_differ._aquery_diff(first, second, attrs, "before", "after") |
| 465 | self.assertIn(expected_error_one, mock_stdout.getvalue()) |
| 466 | |
rosica | 0ec99e7 | 2019-01-03 01:06:47 -0800 | [diff] [blame] | 467 | |
| 468 | if __name__ == "__main__": |
| 469 | unittest.main() |