From ab780b65bf0c072f42cf7d0fdaf84d098212a7c2 Mon Sep 17 00:00:00 2001 From: Simon Toens Date: Sat, 11 Apr 2020 21:48:04 +0900 Subject: [PATCH] Add test for misc/extdeps_pomgen (#28) --- misc/BUILD | 13 +++++++- misc/extdeps_pomgen.py | 24 ++++++++------ misc/tests/extdeps_pomgentest.py | 54 ++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 misc/tests/extdeps_pomgentest.py diff --git a/misc/BUILD b/misc/BUILD index e83c3f6..cb9c087 100644 --- a/misc/BUILD +++ b/misc/BUILD @@ -1,4 +1,4 @@ -python_version = 'PY2' +python_version = 'PY3' py_binary( name = "extdeps", @@ -6,3 +6,14 @@ py_binary( main = "extdeps_pomgen.py", python_version = python_version, ) + +py_test( + name = "extdeps_pomgentest", + srcs = ["//:pomgen_files", + "extdeps_pomgen.py", + "tests/extdeps_pomgentest.py"], + imports = ["."], + size = "small", + python_version = python_version, +) + diff --git a/misc/extdeps_pomgen.py b/misc/extdeps_pomgen.py index fb9ce36..7991472 100755 --- a/misc/extdeps_pomgen.py +++ b/misc/extdeps_pomgen.py @@ -57,14 +57,14 @@ def _starts_with_ignored_prefix(line): return True return False -if __name__ == "__main__": - args = _parse_arguments(sys.argv[1:]) +def main(args): + args = _parse_arguments(args) repo_root = common.get_repo_root(args.repo_root) cfg = config.load(repo_root) - workspace = workspace.Workspace(repo_root, - cfg.external_dependencies, - cfg.excluded_dependency_paths, - cfg.all_src_exclusions) + ws = workspace.Workspace(repo_root, + cfg.external_dependencies, + cfg.excluded_dependency_paths, + cfg.all_src_exclusions) group_id = "all_ext_deps_group" if args.group_id is None else args.group_id artifact_id = "all_ext_deps_art" if args.artifact_id is None else args.artifact_id @@ -88,12 +88,16 @@ def _starts_with_ignored_prefix(line): if _starts_with_ignored_prefix(line): continue dep_labels.append(line) - unique_dependencies = set(workspace.parse_dep_labels(dep_labels)) + unique_dependencies = set(ws.parse_dep_labels(dep_labels)) dependencies = list(unique_dependencies) else: - dependencies = list(workspace.name_to_external_dependencies.values()) + dependencies = list(ws.name_to_external_dependencies.values()) dependencies.sort() - pomgen = ThirdPartyDepsPomGen(workspace, artifact_def, dependencies, cfg.pom_template) + pomgen = ThirdPartyDepsPomGen(ws, artifact_def, dependencies, + cfg.pom_template) pomgen.process_dependencies() - print(pomgen.gen()) + return pomgen.gen() + +if __name__ == "__main__": + print(main(sys.argv[1:])) diff --git a/misc/tests/extdeps_pomgentest.py b/misc/tests/extdeps_pomgentest.py new file mode 100644 index 0000000..e3ad873 --- /dev/null +++ b/misc/tests/extdeps_pomgentest.py @@ -0,0 +1,54 @@ +""" +Copyright (c) 2018, salesforce.com, inc. +All rights reserved. +SPDX-License-Identifier: BSD-3-Clause +For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause +""" + +import extdeps_pomgen +import os +import tempfile +import unittest + +class ExtDepsPomgenTest(unittest.TestCase): + + def test1(self): + self._setup_workspace() + args = ("--repo_root", self.repo_root_path,) + + pom = extdeps_pomgen.main(args) + + self.assertIn("com.google.guava", pom) + self.assertIn("guava", pom) + self.assertIn("23.0