Python3 port for test_networkgroup.py, test_protocol.py #1792
No reviewers
Labels
No Label
bug
build
dependencies
developers
documentation
duplicate
enhancement
formatting
invalid
legal
mobile
obsolete
packaging
performance
protocol
question
refactoring
regression
security
test
translation
usability
wontfix
No Milestone
No project
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Bitmessage/PyBitmessage-2024-11-28#1792
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "v0.6-test-networkgroup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fix Imports
Contains changes from #1786 for protocol.py as it needed to run test_networkgroup
Handled bytes to string comparison/concatenation cases
Python 2/3 compatibility
I'm not sure about this. Need to think about it.
I'm also not sure about these imports.
This isn't needed, use
six.PY2
.@ -101,3 +101,3 @@
host.split(".")[0], True)
elif host.find(':') == -1:
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
return b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
Here I would refactor the original code. Create new constants for the raw strings ,and then you can keep the old codepath inside the function. Like this:
@ -164,3 +164,3 @@
if hostStandardFormat == "":
if hostStandardFormat:
# This can happen on Windows systems which are
# not 64-bit compatible so let us drop the IPv6 address.
Same as with
encodeHost
: refactor to use a constant andsix
. The constants are the same as withencodeHost
, no need to duplicate.Same as above, refactor using constants and
six
.@ -284,3 +287,4 @@
def CreatePacket(command, payload=b''):
"""Construct and return a packet"""
payload_length = len(payload)
checksum = hashlib.sha512(payload).digest()[0:4]
I don't know if this is ok as there are no tests for this. So you need to write a test.
Again I'm not sure about this.
You don't need
sys
, usesix
instead.Again not sure, I need to think about it.
Use constants or class variables.
same here.
@ -284,3 +287,4 @@
def CreatePacket(command, payload=b''):
"""Construct and return a packet"""
payload_length = len(payload)
checksum = hashlib.sha512(payload).digest()[0:4]
Okay, I'll write one
You don't need this, please look into #1788
However in tests the imports gonna be like these. See: a8c79c3832e2e3081ebdcb0373f6b4c0057906f7.
Okay, got it
@ -284,3 +287,4 @@
def CreatePacket(command, payload=b''):
"""Construct and return a packet"""
payload_length = len(payload)
checksum = hashlib.sha512(payload).digest()[0:4]
I've already solved this in 7e1f6e8. Yes, at first I wrote more tests.
@ -101,3 +101,3 @@
host.split(".")[0], True)
elif host.find(':') == -1:
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
return b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
python2.7 has no problem with bytes literals
@ -284,3 +287,4 @@
def CreatePacket(command, payload=b''):
"""Construct and return a packet"""
payload_length = len(payload)
checksum = hashlib.sha512(payload).digest()[0:4]
Okay, I'll merge your changes
maybe
if not hostStandardFormat:
?
check
bool(b'')
andbool(b'1')
in python2 and python3 to make sure it workstest if pack returns
bytes
in python2.Try reverting this hunk
Retest after remongin this hunk.
should be only one section, with bytes, no distinguishing between python2 and python3
try making everything into bytes, we'll see if it still works.
It works
it's about str vs bytes here, to not insert a literal like
b''
, maybe bool makes sence but the condition is rather about the emptiness of thehostStandardFormat
value as I see itNo it does not on python2,
It returns
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\x01'
I don't think you need this here. Can you show a corresponding failing check?
I was getting this error
'Found application file keys.dat in src dir'
So, I added tearDown() that fixed it
I will retest removing it, once more
you've already got the pathmagic for this: the
common
module is used in both test suitesfrom pybitmessage import state
import state
I suppose we gonna switch to
from . import state
inside of thepybitmessage
package and using another start script in top level dir, but not earlier than the circular import in thenetwork
package is solved.what's called bytes in py3 in python2 is str
the py3 str analogue in python2 is unicode
that's why you are not gonna get a portable code if you write
str(data)
, instead you dodata.encode('utf-8') # arg may be dropped in python3
please post the link
https://github.com/Bitmessage/PyBitmessage/pull/1792/checks?sha=8d545fa066cdda420e1450ca248dc79ee1f74fba
I can't find the link for that logs, but it was for this commit
I can't understand, why you have kept this? There is another copy of this test with additional samples in the
test_protocol
moduleWorked
Removed
You've lost the logic of the tests refactoring. network group test goes to
test_protocol
Probably it's because you should've remove this module, not add another bikeshed, see. below.
@ -27,0 +67,4 @@
test_ip = '1.2.3.4'
self.assertEqual(b'\x01\x02', protocol.network_group(test_ip))
test_ip = '127.0.0.1'
This is the new
test_network_group()
wrong order
You don't need this hunk either
There was code quality error popped up saying module level imports should be on top
nonsense: this is a library import, why did you place it before the standard library ones and why the for- import is before simple ones? you recently posted a link to pep8 ... so go read it yourself
@ -27,0 +67,4 @@
test_ip = '1.2.3.4'
self.assertEqual(b'\x01\x02', protocol.network_group(test_ip))
test_ip = '127.0.0.1'
Okay, so I guess there's no need for test_networkgroup.py?
Should we remove it?
Edit: Removed it
Ok, I reverted the changes
https://github.com/Bitmessage/PyBitmessage/pull/1792/checks?check_run_id=3230496739
Maybe it's because
skip_python3()
should be after the imports and not in between them.But still, it's weird I was not getting this code quality error before
this branch is out of date, rebase
This hunk was changed in v0.6
there is no
skip_python3()
in v0.6, this hunk is not fitOk I found the issue, It was not properly rebased. I fixed it now.
Yep, Fixed now
reverted
$ python
Python 2.7.18 (default, Aug 26 2020, 16:28:25)
[GCC 9.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
OK. Now you need a Peter's review. I see this as a good material for squashing (;
Next time, please don't squash into one commit. Keep test changes separate from the code changes and write proper commit messages: what you've found in test results, what was changed to fix the issue. Your commit message is sick and not informative.
The proper message might be like this:
Bad signature as well here
Updated verified commit.
Hmm, it looks like you've changed a GPG key...
Yes.
Please rebase and change the commit message.