Commit graph

92 commits

Author SHA1 Message Date
Protobuf Team Bot
6cd6ca4116 Auto-format Py Proto python files.
PiperOrigin-RevId: 907755617
2026-04-29 13:40:58 -07:00
Emmanuel Ferdman
b926dd82d1 Resolve testing python library deprecation warnings (#22200)
## Description
This small PR migrates from `unittest.assertEquals` to `unittest.assertEqual` which is deprecated from Python2.7:
```python
/tmp/protobuf/python/google/protobuf/internal/reflection_test.py:3147: DeprecationWarning: Please use assertEqual instead.
```

Closes #22200

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/22200 from emmanuel-ferdman:main 126ddc1825
PiperOrigin-RevId: 771314609
2025-06-13 20:05:48 -07:00
Protobuf Team Bot
f69180a6c1 Remove calls to Label within Protobuf Python.
PiperOrigin-RevId: 756880197
2025-05-09 13:16:44 -07:00
Aaron Jacobs
ac4a50be6c Add Python deprecation warnings for Descriptor Label. Also, minimize calls to Label within Protobuf.
PiperOrigin-RevId: 756720481
2025-05-09 05:15:24 -07:00
Protobuf Team Bot
4f2ccc207d Add Python deprecation warnings for Descriptor Label. Also, minimize calls to Label within Protobuf.
PiperOrigin-RevId: 756631443
2025-05-09 00:09:00 -07:00
Mike Kruskal
823939f5ac Internal changes
PiperOrigin-RevId: 748348689
2025-04-16 10:54:54 -07:00
Jie Luo
da04261f2b Fix segment fault for UPB Pyhon 'in' method of empty repeated extensions
PiperOrigin-RevId: 741359924
2025-03-27 19:31:20 -07:00
Adam Cozzette
0d42a969e3 Replace protobuf_unittest package with proto2_unittest
For historical reasons, our internal copy of the codebase uses
`proto2_unittest` while the open source one uses `protobuf_unittest`. This adds
a lot of friction to syncing between the two, and there's no great reason to
keep maintaining this difference, so let's just go with `proto2_unittest`.

PiperOrigin-RevId: 721951543
2025-01-31 17:06:33 -08:00
Tony Liao
2ec7653fe5 Clean up obsolete api_implementation hacks in reflection_test.
When adding UPB as a backend to to reflection_test, I found that the test had
lots of if-conditions that skip certain sections of the test based on an
assumption that anything where api_implementation.Type() != 'python' is C++.
With UPB in the mix, that's no longer true. So it seemed like a good
opportunity to go in and lock down the nonconformance a bit tighter.

As it turns out, some of the nonconformance has been fixed already over the
past 10 years. :) So we can simply remove some of the if checks and enjoy a
better conformance test coverage across all python backends!

PiperOrigin-RevId: 712945117
2025-01-07 09:56:30 -08:00
Tony Liao
39808bc55d Remove the entire pb_unit_tests/ directory with reflection_test_wrapper.
The test wrappers were another way to document nonconformant behaviour between
different python backends. We can achieve the same by removing the wrapper
script and adding an if-condition in the test itself based on
api_implementation.Type(). Since we already do that for nonconformance between
pure Python vs. C++ backends, this change makes it easier to look for UPB
nonconformance instead of going through another layer of indirection.

Since this is the last remaining test file in the pb_unit_tests directory, I
have removed the entire directory. Future UPB tests will be in the same
directory as C++ and pure python implementations, namely:
//python/google/protobuf/internal.

Temporarily, we will need to hardcode the migrated test name in test_upb.yml
because not all tests under google.protobuf.internal support UPB yet.
(UPB testing for selected tests are added in 21e9aa6cac).

The reflection_test is a slightly more complicated test. In this commit I've
removed exemption of testParsingNestedClass in reflection_test. A follow-up
commit will ensure further conformance within the reflection_test. There are
quite a few if-conditions that were added to skip certain checks due to
nonconformant behavior -- they seem to no longer apply.

PiperOrigin-RevId: 712943652
2025-01-07 09:52:04 -08:00
Mike Kruskal
aa4e50fe78 Replace old branch of absl-py parameterization with a dev dependency
#test-continuous

PiperOrigin-RevId: 706910739
2024-12-16 18:57:05 -08:00
Nathan Baulch
e4cbc79ab4 Fix minor typos (#17682)
Just thought I'd contribute some typo fixes that keep tripping up CI/CD checks in my projects. Nothing controversial (hopefully), just 174 simple fixes.

Use the following command to get a quick and dirty summary of the specific corrections made:
```shell
git diff HEAD^! --word-diff-regex='\w+' -U0 \
  | grep -E '\[\-.*\-\]\{\+.*\+\}' \
  | sed -r 's/.*\[\-(.*)\-\]\{\+(.*)\+\}.*/\1 \2/' \
  | sort | uniq -c | sort -n
```

FWIW, the top typos are:
* trimed → trimmed (37)
* substract → subtract (7)
* qualifed → qualified (7)
* extesion → extension (6)
* mising → missing (5)
* btye → byte (4)
* likey → likely (4)
* candicate → candidate (3)
* decriptor → descriptor (3)
* inherting → inheriting (3)
* colletion → collection (3)
* caluclated → calculated (3)
* unititialized → uninitialized (3)
* implemting → implementing (3)
* binrary → binary (3)
* descripor → descriptor (3)
* negitive → negative (3)

Closes #17682

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/17682 from NathanBaulch:typos d41762d137
PiperOrigin-RevId: 677074418
2024-09-20 20:50:06 -07:00
Mike Kruskal
4c923285a3 Fix packed reflection handling bug in edition 2023.
This is a very narrow edge case where touching a packed extension via generated APIs first, and then doing so reflectively will trigger a DCHECK.  Otherwise, reflective APIs will work but not use packed encoding for the extension.  This was likely a pre-existing bug dating back to proto3, where it would only be visible on custom options (the only extensions allowed in proto3).

To help qualify this and uncover similar issues, unittest.proto was migrated to editions.  This turned up some other minor issues in DebugString and python.

PiperOrigin-RevId: 675785611
2024-09-17 18:41:26 -07:00
Jie Luo
b9f46b822e Remove deprecated reflection.py usages from test
PiperOrigin-RevId: 662703556
2024-08-13 17:09:31 -07:00
Protobuf Team Bot
b3e7a00774 Add unit test enum showing allocation in repeated enum lists
TestPackedTypes' field is unused, it's just there to make the messages symmetric between packed and unpacked versions.

PiperOrigin-RevId: 628913968
2024-04-28 17:27:02 -07:00
Joshua Haberman
b9e4894462 Fixed a SEGV when deep copying a non-reified sub-message.
PiperOrigin-RevId: 600951523
2024-01-23 17:13:47 -08:00
Mike Kruskal
88249acbfd Internal change
PiperOrigin-RevId: 578290521
2023-10-31 13:48:51 -07:00
Protobuf Team Bot
73b7f06faf Verify closed enums rather than fallback to eager parsing.
PiperOrigin-RevId: 567666569
2023-09-22 11:03:19 -07:00
Sandy Zhang
81068e8e8c Internal change
PiperOrigin-RevId: 566426899
2023-09-18 15:17:56 -07:00
Joshua Haberman
9ef8f5cffc Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full.
PiperOrigin-RevId: 563897888
2023-09-08 18:50:27 -07:00
Jie Luo
abf5dfbfbc Fix a bug that strips options from descriptor.proto in Pure Python.
GetOptions on fields (which parse the _serialized_options) will be called for the first time of parse or serialize instead of Build time.

Note: GetOptions on messages are still called in Build time because of message_set_wire_format. If message options are needed in descriptor.proto, a parse error will be raised in GetOptions(). We can check the file to not invoke GetOptions() for descriptor.proto as long as message_set_wire_format not needed in descriptor.proto.

Other options except message options do not invoke GetOptions() in Build time

PiperOrigin-RevId: 560741182
2023-08-28 10:00:45 -07:00
Mike Kruskal
27d42c5ba7 Fix a bug that strips options from descriptor.proto in Python.
This fixes Python/C++ and upb, and pushes the buggy behavior to pure python.  There, it's very difficult to handle options on the bootstrapped proto with the current architecture.  Future changes will attempt to address this more isolated issue.

PiperOrigin-RevId: 559450900
2023-08-23 09:34:39 -07:00
Jie Luo
b9eb6bf759 Internal change only
PiperOrigin-RevId: 493742523
2022-12-07 16:39:19 -08:00
Mike Kruskal
e19c2606b3 Internal changes
PiperOrigin-RevId: 487447243
2022-11-09 23:45:35 -08:00
Mike Kruskal
d934383117 Internal changes
PiperOrigin-RevId: 485912044
2022-11-03 10:39:56 -07:00
Mike Kruskal
91c1e7c058 Sync from Piper @483688977
PROTOBUF_SYNC_PIPER
2022-10-25 09:19:55 -07:00
David L. Jones
9e09343a49 Sync from Piper @441896533
PROTOBUF_SYNC_PIPER
2022-04-14 17:36:14 -07:00
Mike Kruskal
a29e0e3f44 Sync from Piper @439400376
PROTOBUF_SYNC_PIPER
2022-04-04 13:42:37 -07:00
Adam Cozzette
63f952b987
Fix Python 3.10 C++ tests (#9128)
The first change is to make sure we always define PY_SSIZE_T_CLEAN
before including Python.h. Starting from Python 3.10 this is required.
Otherwise we get errors like this:

SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

The second change is to update reflection_test.py to account for the
fact that with Python 3.10, we get a TypeError even with the C++
implementation when trying to assign a float to a bool field. I'm not
sure why this changed with Python 3.10, but it seems like a good thing
since this is the desired behavior anyway.
2021-10-20 14:51:07 -07:00
Adam Cozzette
454778d011
Python: fix usages of deprecated assertRaisesRegxp (#9098)
assertRaisesRegexp has been deprecated in favor of the slightly
different spelling assertRaisesRegex. Let's fix this just to clean up a
bunch of deprecation warnings in the tests.
2021-10-15 19:00:04 -07:00
Joshua Haberman
e5c570bb57 Sync from Piper @395706834
PROTOBUF_SYNC_PIPER
2021-09-09 08:21:42 -07:00
Joshua Haberman
5c028d6cf4 Sync from Piper @343521567
PROTOBUF_SYNC_PIPER
2020-11-20 10:44:58 -08:00
Peter Newman
e2cc2de304
Fix lots of spelling errors (#7751)
* Fix a typo

* Fix lots of spelling errors

* Fix a few more spelling mistakes

* s/parsable/parseable/

* Don't touch the third party files

* Cloneable is the preferred C# term

* Copyable is the preferred C++ term

* Revert "s/parsable/parseable/"

This reverts commit 534ecf7675.

* Revert unparseable->unparsable corrections
2020-08-10 11:08:25 -07:00
Joshua Haberman
b99994d994 Sync from Piper @304070343
PROTOBUF_SYNC_PIPER
2020-03-31 16:25:37 -07:00
Rafi Kamal
58d4420e2d Down Integrate Internal Changes 2019-11-12 13:38:58 -08:00
Rafi Kamal
4f02f056b5 Down integrate to GitHub 2019-08-22 17:33:01 -07:00
Hao Nguyen
176f7db11d Down integrate to Github 2019-04-09 06:23:32 -07:00
Oliver Bristow
0de6577b7d Add EnumTypeWrapper.__getattr__ to access values (#5234) 2019-02-27 16:39:51 -08:00
Josh Haberman
d61aede89c Down-integrate from google3. 2018-09-04 10:58:54 -07:00
Feng Xiao
6bbe197e9c Down-integrate from google3. 2018-08-08 17:00:41 -07:00
Adam Cozzette
13fd045dbb Integrated internal changes from Google 2017-09-14 10:03:57 -07:00
Jie Luo
f5817b3056 PY26 tests compatibility
1, Some tests in reflection_test PY26 raise TypeError but other versions raise ValueError for convert negative long to unsigned
2, Change compare exception type to compare exception str for testDuplicateExtensionNumber. Original code raise 'Double registration of Extensions' is not an instance of (<type 'exceptions.AssertionError'>, <type 'exceptions.ValueError'>) for PY26 cpp implementation

t
2017-08-04 15:25:11 -07:00
Feng Xiao
d36c0c538a Down-integrate from google3. 2017-03-29 14:33:05 -07:00
Adam Cozzette
5a76e633ea Integrated internal changes from Google 2016-11-17 16:59:59 -08:00
Bo Yang
cc8ca5b6a5 Integrate internal changes 2016-10-10 11:23:36 -07:00
Jonathon Love
64958cdb1d Fix to typo/oversight in python tests
Fix to typo/oversight in python tests, only affecting python 3
2016-09-02 12:36:11 +10:00
Feng Xiao
9086d96439 Integrate from internal code base. 2016-07-13 13:48:40 -07:00
Jisi Liu
cf14183bcd Down integrate from Google internal. 2016-04-28 14:34:59 -07:00
Jisi Liu
3b3c8abb96 Integrate google internal changes. 2016-03-30 11:39:59 -07:00
Feng Xiao
e841bac4fc Down-integrate from internal code base. 2015-12-11 17:10:28 -08:00