diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:46:16 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:46:16 +0000 |
commit | 2ce6e8be8e2dd5dbed108e6d5387e4bd21c3d04c (patch) | |
tree | 77dc031614745bb406dbd90cea9a082a1b5cdd54 /cwp/cr-os/fetch_gn_descs_test.py | |
parent | 904b3e949a93a8953db41e41b256a5b27debeed4 (diff) | |
parent | 40214b48188358a80b7478bfff21d4814dd9177c (diff) | |
download | toolchain-utils-android14-mainline-art-release.tar.gz |
Snap for 10453563 from 40214b48188358a80b7478bfff21d4814dd9177c to mainline-art-releaseaml_art_341711000aml_art_341615020aml_art_341514450aml_art_341514410aml_art_341411300aml_art_341311100aml_art_341110110aml_art_341110060aml_art_341010050aml_art_340915060android14-mainline-art-release
Change-Id: Ic798bced996e8800fcd5f3f45be364c0b6d53417
Diffstat (limited to 'cwp/cr-os/fetch_gn_descs_test.py')
-rwxr-xr-x | cwp/cr-os/fetch_gn_descs_test.py | 198 |
1 files changed, 106 insertions, 92 deletions
diff --git a/cwp/cr-os/fetch_gn_descs_test.py b/cwp/cr-os/fetch_gn_descs_test.py index b6fc0eeb..8a88fe3e 100755 --- a/cwp/cr-os/fetch_gn_descs_test.py +++ b/cwp/cr-os/fetch_gn_descs_test.py @@ -1,12 +1,11 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Copyright 2020 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Tests for fetch_gn_descs.py.""" -from __future__ import print_function import io import unittest @@ -17,93 +16,108 @@ import fetch_gn_descs class Test(unittest.TestCase): - """Tests for fetch_gn_descs.""" - - def test_fix_result_removes_uninteresting_items(self): - items = { - '//uninteresting:a': {}, - '//uninteresting:b': { - 'sources': ['whee'], - }, - '//uninteresting:c': { - 'configs': ['whee'], - }, - '//uninteresting:d': { - 'sources': [], - 'configs': [], - }, - '//interesting:a': { - 'sources': ['a'], - 'configs': ['b'], - }, - '//interesting:b': { - 'sources': ['d'], - 'configs': ['c'], - }, - } - - expected_items = { - '//interesting:a': items['//interesting:a'], - '//interesting:b': items['//interesting:b'], - } - - self.assertDictEqual( - fetch_gn_descs._fix_result('/', '/', '/', items), expected_items) - - def test_fix_result_translates_paths_in_out_dir(self): - items = { - '//interesting:a': { - 'sources': ['//out_dir/foo', '//out_dir'], - 'configs': ['b'], - }, - } - - expected_items = { - '//interesting:a': { - 'sources': ['//out_translated/foo', '//out_translated/'], - 'configs': ['b'], - }, - } - - self.assertDictEqual( - fetch_gn_descs._fix_result( - rename_out='//out_translated', - out_dir='/chromium/src/out_dir', - chromium_root='/chromium', - gn_desc=items, - ), - expected_items, - ) - - def test_gn_desc_output_parsing_skips_pre_json_warnings(self): - gn_desc = io.StringIO('\n'.join(( - 'foo', - 'warning: "{" is bad', - '{"bar": "baz",', - ' "qux": true}', - ))) - - warnings, desc_json = fetch_gn_descs._parse_gn_desc_output(gn_desc) - self.assertEqual(warnings, '\n'.join(( - 'foo', - 'warning: "{" is bad', - ))) - self.assertEqual(desc_json, { - 'bar': 'baz', - 'qux': True, - }) - - def test_gn_desc_output_parsing_issues_no_warnings_if_none_are_present(self): - gn_desc = io.StringIO('{"bar": "baz"}') - warnings, desc_json = fetch_gn_descs._parse_gn_desc_output(gn_desc) - self.assertEqual(warnings, '') - self.assertEqual(desc_json, {'bar': 'baz'}) - - gn_desc = io.StringIO('\n \n\t\n{"bar": "baz"}') - warnings, desc_json = fetch_gn_descs._parse_gn_desc_output(gn_desc) - self.assertEqual(warnings, '') - self.assertEqual(desc_json, {'bar': 'baz'}) - - -if __name__ == '__main__': - unittest.main() + """Tests for fetch_gn_descs.""" + + def test_fix_result_removes_uninteresting_items(self): + items = { + "//uninteresting:a": {}, + "//uninteresting:b": { + "sources": ["whee"], + }, + "//uninteresting:c": { + "configs": ["whee"], + }, + "//uninteresting:d": { + "sources": [], + "configs": [], + }, + "//interesting:a": { + "sources": ["a"], + "configs": ["b"], + }, + "//interesting:b": { + "sources": ["d"], + "configs": ["c"], + }, + } + + expected_items = { + "//interesting:a": items["//interesting:a"], + "//interesting:b": items["//interesting:b"], + } + + self.assertDictEqual( + fetch_gn_descs._fix_result("/", "/", "/", items), expected_items + ) + + def test_fix_result_translates_paths_in_out_dir(self): + items = { + "//interesting:a": { + "sources": ["//out_dir/foo", "//out_dir"], + "configs": ["b"], + }, + } + + expected_items = { + "//interesting:a": { + "sources": ["//out_translated/foo", "//out_translated/"], + "configs": ["b"], + }, + } + + self.assertDictEqual( + fetch_gn_descs._fix_result( + rename_out="//out_translated", + out_dir="/chromium/src/out_dir", + chromium_root="/chromium", + gn_desc=items, + ), + expected_items, + ) + + def test_gn_desc_output_parsing_skips_pre_json_warnings(self): + gn_desc = io.StringIO( + "\n".join( + ( + "foo", + 'warning: "{" is bad', + '{"bar": "baz",', + ' "qux": true}', + ) + ) + ) + + warnings, desc_json = fetch_gn_descs._parse_gn_desc_output(gn_desc) + self.assertEqual( + warnings, + "\n".join( + ( + "foo", + 'warning: "{" is bad', + ) + ), + ) + self.assertEqual( + desc_json, + { + "bar": "baz", + "qux": True, + }, + ) + + def test_gn_desc_output_parsing_issues_no_warnings_if_none_are_present( + self, + ): + gn_desc = io.StringIO('{"bar": "baz"}') + warnings, desc_json = fetch_gn_descs._parse_gn_desc_output(gn_desc) + self.assertEqual(warnings, "") + self.assertEqual(desc_json, {"bar": "baz"}) + + gn_desc = io.StringIO('\n \n\t\n{"bar": "baz"}') + warnings, desc_json = fetch_gn_descs._parse_gn_desc_output(gn_desc) + self.assertEqual(warnings, "") + self.assertEqual(desc_json, {"bar": "baz"}) + + +if __name__ == "__main__": + unittest.main() |