From 0853c41b9cb6c14cf076971344427c1ac0164597 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 27 Feb 2022 11:38:03 -0800 Subject: [PATCH 1/4] Factored out common logic around our python test wrappers. --- python/pb_unit_tests/BUILD | 261 +++++-------------------------------- 1 file changed, 35 insertions(+), 226 deletions(-) diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index bcea96ecf1..b69e7eab61 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -23,231 +23,40 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +load("//bazel:pyproto_test_wrapper.bzl", "pyproto_test_wrapper") + licenses(["notice"]) -py_test( - name = "descriptor_database_test", - srcs = ["descriptor_database_test_wrapper.py"], - legacy_create_init = False, - main = "descriptor_database_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "descriptor_pool_test", - srcs = ["descriptor_pool_test_wrapper.py"], - legacy_create_init = False, - main = "descriptor_pool_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "descriptor_test", - srcs = ["descriptor_test_wrapper.py"], - legacy_create_init = False, - main = "descriptor_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "generator_test", - srcs = ["generator_test_wrapper.py"], - legacy_create_init = False, - main = "generator_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "json_format_test", - srcs = ["json_format_test_wrapper.py"], - legacy_create_init = False, - main = "json_format_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "keywords_test", - srcs = ["keywords_test_wrapper.py"], - legacy_create_init = False, - main = "keywords_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "message_factory_test", - srcs = ["message_factory_test_wrapper.py"], - legacy_create_init = False, - main = "message_factory_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "message_test", - srcs = ["message_test_wrapper.py"], - data = [ - "@com_google_protobuf//:testdata", - ], - legacy_create_init = False, - main = "message_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "proto_builder_test", - srcs = ["proto_builder_test_wrapper.py"], - legacy_create_init = False, - main = "proto_builder_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "reflection_test", - srcs = ["reflection_test_wrapper.py"], - legacy_create_init = False, - main = "reflection_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "service_reflection_test", - srcs = ["service_reflection_test_wrapper.py"], - legacy_create_init = False, - main = "service_reflection_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "symbol_database_test", - srcs = ["symbol_database_test_wrapper.py"], - legacy_create_init = False, - main = "symbol_database_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "text_encoding_test", - srcs = ["text_encoding_test_wrapper.py"], - legacy_create_init = False, - main = "text_encoding_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "text_format_test", - srcs = ["text_format_test_wrapper.py"], - data = [ - "@com_google_protobuf//:testdata", - ], - legacy_create_init = False, - main = "text_format_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "unknown_fields_test", - srcs = ["unknown_fields_test_wrapper.py"], - legacy_create_init = False, - main = "unknown_fields_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "well_known_types_test", - srcs = ["well_known_types_test_wrapper.py"], - legacy_create_init = False, - main = "well_known_types_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) - -py_test( - name = "wire_format_test", - srcs = ["wire_format_test_wrapper.py"], - legacy_create_init = False, - main = "wire_format_test_wrapper.py", - deps = [ - "//python:message_ext", - "@com_google_protobuf//:python_common_test_protos", - "@com_google_protobuf//:python_specific_test_protos", - "@com_google_protobuf//:python_srcs", - ], -) +pyproto_test_wrapper(name = "descriptor_database_test") + +pyproto_test_wrapper(name = "descriptor_pool_test") + +pyproto_test_wrapper(name = "descriptor_test") + +pyproto_test_wrapper(name = "generator_test") + +pyproto_test_wrapper(name = "json_format_test") + +pyproto_test_wrapper(name = "keywords_test") + +pyproto_test_wrapper(name = "message_factory_test") + +pyproto_test_wrapper(name = "message_test") + +pyproto_test_wrapper(name = "proto_builder_test") + +pyproto_test_wrapper(name = "reflection_test") + +pyproto_test_wrapper(name = "service_reflection_test") + +pyproto_test_wrapper(name = "symbol_database_test") + +pyproto_test_wrapper(name = "text_encoding_test") + +pyproto_test_wrapper(name = "text_format_test") + +pyproto_test_wrapper(name = "unknown_fields_test") + +pyproto_test_wrapper(name = "well_known_types_test") + +pyproto_test_wrapper(name = "wire_format_test") From 97c3de35fe2e3dfd45643a9defd6df62d9cdf0da Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 27 Feb 2022 11:44:08 -0800 Subject: [PATCH 2/4] Added google3 version of test wrapper. --- bazel/pyproto_test_wrapper.bzl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 bazel/pyproto_test_wrapper.bzl diff --git a/bazel/pyproto_test_wrapper.bzl b/bazel/pyproto_test_wrapper.bzl new file mode 100644 index 0000000000..a8b46156b0 --- /dev/null +++ b/bazel/pyproto_test_wrapper.bzl @@ -0,0 +1,31 @@ + +# copybara:strip_for_google3_begin + +def pyproto_test_wrapper(name): + src = name + "_wrapper.py" + native.py_test( + name = name, + srcs = [src], + legacy_create_init = False, + main = src, + data = ["@com_google_protobuf//:testdata"], + deps = [ + "//python:message_ext", + "@com_google_protobuf//:python_common_test_protos", + "@com_google_protobuf//:python_specific_test_protos", + "@com_google_protobuf//:python_srcs", + ], + ) + +# copybara:replace_for_google3_begin +# +# def pyproto_test_wrapper(name): +# src = name + "_wrapper.py" +# native.py_test( +# name = name, +# srcs = [src], +# main = src, +# deps = ["//net/proto2/python/internal:" + name + "_for_deps"], +# ) +# +# copybara:replace_for_google3_end From 61f904efb7a149b8548581e27944580f2389f891 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 27 Feb 2022 11:52:21 -0800 Subject: [PATCH 3/4] Strip out OSS-only test for google3. --- python/pb_unit_tests/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index b69e7eab61..ecb1d7b900 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -33,7 +33,7 @@ pyproto_test_wrapper(name = "descriptor_pool_test") pyproto_test_wrapper(name = "descriptor_test") -pyproto_test_wrapper(name = "generator_test") +pyproto_test_wrapper(name = "generator_test") # copybara:strip_for_google3 pyproto_test_wrapper(name = "json_format_test") From ccf2fa6c92f66e2c84f562330c58b549c7ac64c8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 27 Feb 2022 17:32:55 -0800 Subject: [PATCH 4/4] Added one more dep. --- bazel/pyproto_test_wrapper.bzl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bazel/pyproto_test_wrapper.bzl b/bazel/pyproto_test_wrapper.bzl index a8b46156b0..fb909a1db8 100644 --- a/bazel/pyproto_test_wrapper.bzl +++ b/bazel/pyproto_test_wrapper.bzl @@ -18,14 +18,17 @@ def pyproto_test_wrapper(name): ) # copybara:replace_for_google3_begin -# +# # def pyproto_test_wrapper(name): # src = name + "_wrapper.py" # native.py_test( # name = name, # srcs = [src], # main = src, -# deps = ["//net/proto2/python/internal:" + name + "_for_deps"], +# deps = [ +# "//net/proto2/python/internal:" + name + "_for_deps", +# "//net/proto2/python/public:use_upb_protos", +# ], # ) -# +# # copybara:replace_for_google3_end