-
Notifications
You must be signed in to change notification settings - Fork 216
Fix vast majority of outstanding Python 3 issues #1761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
peternewman
merged 79 commits into
OpenLightingProject:0.10
from
peternewman:0.10-c11-compat
Feb 26, 2023
Merged
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
6a0c334
Fix more Python 3 issues
peternewman 7be0001
Merge branch '0.10' into 0.10-c11-compat
peternewman ed10398
Encode JSON output in RDM test server for Python 3 compatibility
peternewman de7c3ee
Merge branch '0.10-c11-compat' of https://github.com/peternewman/ola …
peternewman 260b12d
Add tests for TestRunner.GetTestClasses
peternewman f3f6704
Cause rdm_responder_test to die if there were no tests found
peternewman ef7494d
Change how we do the import to try and fix the tests
peternewman 19663da
Another way to try and work round the path issues for the Python test
peternewman 8996884
Fix the flake8 errors, try fixing the build on Travis
peternewman 370ebe6
Fix the TestRunnerTest on Python 2.7
peternewman be2f809
Merge branch '0.10' into 0.10-c11-compat
peternewman ce29794
Merge branch '0.10' into 0.10-c11-compat
peternewman f6de4c2
Add test cases for ExpectedResults classes.
peternewman f9131dd
Merge branch '0.10-c11-compat' of https://github.com/peternewman/ola …
peternewman 97c4b21
Make more build steps verbose so we hopefully see test failures when …
peternewman 67a5a9d
Short-circuit the main build while we're troubleshooting
peternewman c2ab8fc
Build more files to fix the testing
peternewman c92bf06
Add more missing symlinks to try and fix the tests
peternewman 6a56b54
Add another Python symlink for the tests
peternewman c90596a
Ignore any distcheck folders
peternewman 5af94cd
Also clean compiled pyc files from testing folder
peternewman 322d41e
Add a comment about one of the test hacks
peternewman 621c75d
More NEWS
peternewman 81b0e45
Revert "Short-circuit the main build while we're troubleshooting"
peternewman 7d84bbe
Merge branch '0.10' into 0.10-c11-compat
peternewman cd8bce9
Merge branch '0.10' of https://github.com/openlightingproject/ola int…
peternewman 15eb5aa
Merge branch '0.10-c11-compat' of https://github.com/peternewman/ola …
peternewman 1bf606a
Fix the RDM test suite discovery code to work with Python 3
peternewman 1cf9e36
Try and fix more encoding issues for further RDM tests
peternewman 8b6441b
Clean more pycache files
peternewman fa23506
Fix a few more RDM bugs in both the PidStore and a TestMixin
peternewman 2bdfa82
Add a test for packing non-ascii characters, currently fails on Python 3
peternewman ec0fe8a
Fix the new non-ASCII PidStore test on Python 2
peternewman 1781894
Switch back to the same non-ascii as the responder test
peternewman d0e772b
Fix even more tests on Python 3
peternewman f0c0b8d
Add a StringEscape function wrapper
peternewman f340f99
Switch ContainsUnprintable to use our new StringEscape function
peternewman 3c7f6de
Catch and raise an exception if StringEscape is used on things other …
peternewman 4f1da3f
Catch and raise an exception if ContainsUnprintable is used on things…
peternewman c8c6ee5
Fix string escaping on Python 3 too
peternewman fcb9fa6
Fix StringEscape so it still returns a string in Python 3, also add s…
peternewman 7dfe971
Fix the ContainsUnprintable test given our StringEscape changes
peternewman 9d0c68b
Use our escape function and write the pickle data as binary
peternewman fc9db0d
Use our new StringEscape function rather than duplicating code
peternewman 6451ad5
Encode more response data and decode the post data so it behaves as i…
peternewman e5cefeb
Use our StringEscape function everywhere else
peternewman aedf7ec
Make the exception more useful
peternewman 315f071
Software version doesn't need escaping as it's just an int
peternewman de53080
Escape using our function. Add separate non-printable and non-ASCII t…
peternewman a405bb2
Fix a syntax issue
peternewman 63a3105
Fix the flake8 issues
peternewman 02af38e
Switch to some alternative test characters for the String PID test co…
peternewman c4ca6ca
Handle utf8 throughout the Python string class. Conversely it will no…
peternewman 00a273d
Fix the UTF-8 related tests on both Python versions, also sort unpack
peternewman abf91a5
Fix our SetNonAsciiDeviceLabel test so it sends the expected bytes
peternewman 1342f57
Catch, and test, for Unicode decode errors on incoming data
peternewman ecf842c
Add a basic null handling test
peternewman 73d2f39
Sort the Python imports with isort
peternewman 5ba1615
Switch to fully qualified imports for Python
peternewman 9f50218
Keep GitHub Actions up to date with Dependabot
peternewman 46476ee
Simplify the test discovery code now we've changed the imports and go…
peternewman d4cf464
Fix the licence for the new test
peternewman 05a5945
Symlink more files required for the distcheck build
peternewman a95d4fa
Hopefully add the last hacky symlink
peternewman dfe877f
Simplify the ContainsUnprintable logic
peternewman b69d424
Fix a copyright year
peternewman 84ffa62
Improve some comments and exception messages
peternewman 85da44b
Simplify some of the RDM unit testing
peternewman 1ca6d30
Remove some errant whitespace
peternewman eab7a44
Sort the imports as isort likes
peternewman d870219
Merge branch '0.10' of https://github.com/openlightingproject/ola int…
peternewman 80e1aeb
Merge branch '0.10-c11-compat' of https://github.com/peternewman/ola …
peternewman 45145ba
Comment out the SetNonAsciiDeviceLabel test for now as it breaks when…
peternewman a8bfb32
Merge branch '0.10' of https://github.com/openlightingproject/ola int…
peternewman 40e8910
Merge branch '0.10' of https://github.com/openlightingproject/ola int…
peternewman c41589d
Revert "Remove some statements that won't be true until another PR ha…
peternewman 7a55db7
Remove some duplicate codespell ignore lines
peternewman f917588
Ignore more codespell lines
peternewman f5be4e7
Fix a comment
peternewman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
# | ||
# StringUtils.py | ||
# Copyright (C) 2022 Peter Newman | ||
|
||
"""Common utils for OLA Python string handling""" | ||
|
||
import sys | ||
|
||
if sys.version_info >= (3, 0): | ||
try: | ||
unicode | ||
except NameError: | ||
unicode = str | ||
|
||
__author__ = '[email protected] (Simon Newton)' | ||
|
||
|
||
def StringEscape(s): | ||
"""Escape unprintable characters in a string.""" | ||
# TODO(Peter): How does this interact with the E1.20 Unicode flag? | ||
# We don't use sys.version_info.major to support Python 2.6. | ||
if sys.version_info[0] == 2 and type(s) == str: | ||
return s.encode('string-escape') | ||
elif sys.version_info[0] == 2 and type(s) == unicode: | ||
return s.encode('unicode-escape') | ||
elif type(s) == str: | ||
# All strings in Python 3 are unicode | ||
# This encode/decode pair gets us an escaped string | ||
return s.encode('unicode-escape').decode(encoding="ascii", | ||
errors="backslashreplace") | ||
else: | ||
raise TypeError('Only strings are supported not %s' % type(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
# | ||
# StringUtilsTest.py | ||
# Copyright (C) 2022 Peter Newman | ||
|
||
import unittest | ||
|
||
from ola.StringUtils import StringEscape | ||
|
||
"""Test cases for StringUtils utilities.""" | ||
|
||
__author__ = '[email protected] (Simon Newton)' | ||
|
||
|
||
class StringUtilsTest(unittest.TestCase): | ||
def testStringEscape(self): | ||
# Test we escape properly | ||
self.assertEqual('foo', StringEscape("foo")) | ||
self.assertEqual('bar', StringEscape("bar")) | ||
self.assertEqual('bar[]', StringEscape("bar[]")) | ||
self.assertEqual('foo-bar', StringEscape(u'foo-bar')) | ||
self.assertEqual('foo\\x00bar', StringEscape("foo\x00bar")) | ||
# TODO(Peter): How does this interact with the E1.20 Unicode flag? | ||
self.assertEqual('caf\\xe9', StringEscape(u'caf\xe9')) | ||
self.assertEqual('foo\\u2014bar', StringEscape(u'foo\u2014bar')) | ||
|
||
# Test that we display nicely in a string | ||
self.assertEqual('foo', ("%s" % StringEscape("foo"))) | ||
self.assertEqual('bar[]', ("%s" % StringEscape("bar[]"))) | ||
self.assertEqual('foo-bar', ("%s" % StringEscape(u'foo-bar'))) | ||
self.assertEqual('foo\\x00bar', ("%s" % StringEscape("foo\x00bar"))) | ||
# TODO(Peter): How does this interact with the E1.20 Unicode flag? | ||
self.assertEqual('caf\\xe9', ("%s" % StringEscape(u'caf\xe9'))) | ||
self.assertEqual('foo\\u2014bar', ("%s" % StringEscape(u'foo\u2014bar'))) | ||
|
||
# Confirm we throw an exception if we pass in a number or something else | ||
# that's not a string | ||
with self.assertRaises(TypeError): | ||
result = StringEscape(42) | ||
self.assertNone(result) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to not using your name as the author? you got it in line 16 as well