Skip to content

TDD Py3 merge: Commits up to test_accessor.py: Test reading binary data from http and file #25

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

Closed
wants to merge 19 commits into from

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Apr 25, 2023

This is based on #17 with the WIP commits reworked.

Including this fixes to pass the testsuite with Python3 as well, I was able to reduce the commit count to 19! :-)

Could be ready for merge, open TODOs:

  • I want to cleanup commit 1 of the series and
  • Enable the Py3 tests in the GitHub action too like Testsuite driven py3 #17 does, with the NodeJS 12 deprecation warnings fixed using newer action-repos.

ydirson and others added 19 commits January 20, 2023 17:45
Use of `unicode` needed to be immediately handled, but a few checks
relying on `str` could become insufficient in python2 with the larger
usage of unicode strings.

Signed-off-by: Yann Dirson <[email protected]>
…s to

open() as ths is considered best practice.

(cherry picked from cpython commit 6cef076ba5edbfa42239924951d8acbb087b3b19)

Signed-off-by: Yann Dirson <[email protected]>
Running tests on python3 did reveal some of them.

Signed-off-by: Yann Dirson <[email protected]>
There is no guaranty about ordering of dict elements, and tests compare
results derived from enumerating a dict element.  We could have used an
OrderedDict to store the formulae and get a predictible output order, but
just considering the output as a set seems better.

Only applying this to rules expected to hold more than one element.

Signed-off-by: Yann Dirson <[email protected]>
Caught by extended test.

Signed-off-by: Yann Dirson <[email protected]>
hashlib came with python 2.5, and old md5 module disappears in 3.0

Originally by Yann Dirson, changed to not add .encode() for md5
creation, because encoding changes are dealt with in other commits.

Co-authored-by: Yann Dirson <[email protected]>
Signed-off-by: Bernhard Kaindl <[email protected]>
Reported under python3 for members created on-the-fly in `setUp()`

Signed-off-by: Yann Dirson <[email protected]>
With python3, pylint complains about `else: raise()` constructs.
This rework avoids them and reduces cyclomatic complexity by using
the error-out-first idiom.

Signed-off-by: Yann Dirson <[email protected]>
This is supposed to be just a module renaming to conform to PEP8, see
https://docs.python.org/3/whatsnew/3.0.html#library-changes

The SafeConfigParser class has been renamed to ConfigParser in Python
3.2, and backported as addon package.  The `readfp` method now
triggers a deprecation warning to replace it with `read_file`.

FIXME: With python3 some Accessor implementations (e.g. FileAccessor)
provide a text stream for repository config (and with python2 all
implementations), while others (e.g. HTTPAccessor) provide a binary
stream.  But on python3 ConfigParser will bomb out if given a binary
stream, so use a TextIOWrapper to access the config.  This is a hack,
which cannot be used when it is binary data which has to be read (see
later commits), so I don't consider this commit to be correct in that
respect.
xcp.xmlunwrap extracts XML Elements from XML, and for Python2,
the unwrapped unicode is encoded into Py2:str(bytes).

Python3 unwraps XML Text elements as the Py3:str type which is
likewise Unicode, but since Py3:str is the native type, we don't
want to encode the Py3:str to Py3:bytes as that would break the
API for use on Python3.

BEcause binary data is not legal XML content and XML Text elements
are defined to be encoded text, UTF-8 is the standard encoding,
which Python converts to.

It this fine to only encode() to Py2:str(=bytes) on Python2 as
a legacy operation which can be removed once we drop Python2.

Signed-off-by: Bernhard Kaindl <[email protected]>
Fix issue xenserver#19 based on the description and progress from PR xenserver#24.
Allows for opening text and binary files in text and binary modes.

Mode, encoding and error handling can be set by passing the parameters
"encoding" and "errors" using the kwargs parameters from openAddress()
and writeFile() to open(mode, **kwargs) and ftp.makefile(mode, **kwargs).

Signed-off-by: Bernhard Kaindl <[email protected]>
Add and enable a parameterized test to read binary data
from a file- and an HTTP based accessor.

Originally authored by Yann Dirson. Extracted, refactored
and squashed for a single considated and concise commit by me.

Co-authored-by: Yann Dirson <[email protected]>
Signed-off-by: Bernhard Kaindl <[email protected]>
@bernhardkaindl bernhardkaindl added Will be fixed by other PRs Leave until as issues in it are fixed by other PRs bug labels May 15, 2023
@bernhardkaindl
Copy link
Collaborator Author

Obsoleted by now merged #27

bernhardkaindl added a commit to rosslagerwall/python-libs that referenced this pull request May 8, 2024
…/pytest-integration-testframework

Add new Implementation of the Xen-Bugtool Test Environment using pytest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Will be fixed by other PRs Leave until as issues in it are fixed by other PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants