Fix string concatenation to os.path.join and add exception case#11291
Fix string concatenation to os.path.join and add exception case#11291maflcko merged 1 commit intobitcoin:masterfrom
Conversation
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
I'd assume those should probably use os.path.join to make it work on other os as well.
|
Thank you for putting so much effort in your first contribution. However, according to our developer guidelines we can not accept pull requests that solely change formatting and style. Nonetheless, you are welcome to address my issue with this file instead. Also note that you can change |
|
@MarcoFalke Thank you for your advice, I just added commit for use |
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
The last concatenation is string concatenation.
You can check if the tests pass locally by make check
There was a problem hiding this comment.
Thanks I just fixed it, Sorry for my careless mistake
jnewbery
left a comment
There was a problem hiding this comment.
utACK. A couple of nits inline and commits should be squashed to a single commit before merge.
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
since you're converting to snake_case, how about build_env
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
exec_prog? (and exec_args and exec_run)
a334360 to
5256a59
Compare
maflcko
left a comment
There was a problem hiding this comment.
Again, I appreciate the effort, but according to the developer notes such refactoring patches can not be accepted.
Do not submit patches solely to modify the style of existing code.
And https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#refactoring
This will cause merge conflicts with other open pull requests and consumes precious review time.
Please note that the non-refactoring changes in this pull are much appreciated and I'd like to have them merged cleanly without the formatting changes.
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
I don't it is worth the overhead to change apostrophe to quotation mark.
There was a problem hiding this comment.
agree (and for short symbol-like strings as in this line, single quotes seem to be most people's preferred style)
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
Changing this line solely to split it into two causes difficulties grepping in the future.
There was a problem hiding this comment.
... and most of our python files don't adhere to the 79 char max line length (which I think is a good thing!)
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
Can you explain why it makes sense to first log to info and then the same to the error level?
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
Generally, I'd prefer if refactoring is separate (at least a separate commit) from changing behavior.
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
I don't think it makes sense to replace every variable in the whole file by a lower_case name.
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
For short util modules like this, and even for most of our test scripts, I don't think 2 lines separating each function is necessary. It makes sense for large projects where you want visual separation between top-level classes, but I think it's unnecessary here.
|
@dongsam we don't have particularly strict style guidelines for our python code. The only style notes are in https://github.com/bitcoin/bitcoin/blob/master/test/functional/README.md. Since A Foolish Consistency is the Hobgoblin of Little Minds, we don't usually open PRs to adhere to PEP-8 style, unless there's some good reason to do so (eg making bugs less likely). If I'm doing substantial work on a test script, I often start the PR with a tidy-up commit, but even that is sometimes unpopular and puts off reviewers. If you're looking for your first commit, I think @MarcoFalke is right that removing the style changes from this PR and just having the |
c259a68 to
2ce3867
Compare
|
Needs rebase |
2ce3867 to
b7fc18a
Compare
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
nit: why remove this line? Blank lines are used within functions to indicate logical sections.
There was a problem hiding this comment.
sorry, that was mistake while rebasing, I'll add again now
There was a problem hiding this comment.
You've now added trailing whitespace :(
b7fc18a to
5bd3600
Compare
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
You've now added trailing whitespace :(
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
Is this change (and the one at line 107) intentional?
There was a problem hiding this comment.
Yes, there was potential risk outputType can be None so I added initial outputType and exception line when outputType is None, if you think it is not needed, i can remove again
There was a problem hiding this comment.
Yes, this is a good additional check.
5bd3600 to
f1c5277
Compare
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
suggestion: change the error text slightly here to clarify what the problem is:
logging.error("Output file %s does not have a file extension" % outputFn)There was a problem hiding this comment.
@fanquake I just change and rebase the error text, sorry for late response
f1c5277 to
856b3e2
Compare
test/util/bitcoin-util-test.py
Outdated
There was a problem hiding this comment.
I think this is better as:
execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"] + buildenv["EXEEXT"])(ie buildenv["EXEEXT"] should be appended to testObj["exec"] before joining into a path), but I don't have a windows machine to test this on.
Is there a reason you put buildenv["EXEEXT"] outside the os.path.join?
There was a problem hiding this comment.
right, that's why you should have:
execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"] + buildenv["EXEEXT"])
(concatenate testObj["exec"] and buildenv["EXEEXT"] as a single argument to os.path.join())
There was a problem hiding this comment.
oh, sorry I misunderstood, that's look better, I'll update :)
856b3e2 to
a3ac767
Compare
|
utACK a3ac767. Needs to be tested on windows. |
| @@ -48,7 +48,7 @@ def main(): | |||
|
|
|||
There was a problem hiding this comment.
^ one line above.
"test/util/data" throws an error on windows:
FileNotFoundError: [Errno 2] No such file or directory: '.../Downloads/workspace/bitcoin\\test/util/data\\bitcoin-util-test.json'
| def bctester(testDir, input_basename, buildenv): | ||
| """ Loads and parses the input file, runs all tests and reports results""" | ||
| input_filename = testDir + "/" + input_basename | ||
| input_filename = os.path.join(testDir, input_basename) |
There was a problem hiding this comment.
Might as well pass in input_filename to bctester and instead do the path.join in line 47, no?
|
Going to merge since this is a strict improvement. |
…ion case a3ac767 Fix string concatenation to os.path.join and add exception case (dongsamb) Pull request description: Solved some warnings for [Python PEP 8 convention](https://www.python.org/dev/peps/pep-0008/) - [Method Names and Instance Variables](https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables) lowercase with words separated by underscores as necessary to improve readability. - `testDir` to `test_dir` - `inputData` to `input_data` - ... - [Blank Lines](https://www.python.org/dev/peps/pep-0008/#blank-lines) Surround top-level function and class definitions with two blank lines. - [Exception Names](https://www.python.org/dev/peps/pep-0008/#exception-names) and added verification logic about referenced before assignment for `output_type` Tree-SHA512: 346d08799f03077a2b7257ccdca123b4945b89dbf0677dba452d96b81ce186ec7b5dcdb10b8bb59cfce657a7aedbb7df64921036cbd1bf4ad8bd313d40faa796
… exception case a3ac767 Fix string concatenation to os.path.join and add exception case (dongsamb) Pull request description: Solved some warnings for [Python PEP 8 convention](https://www.python.org/dev/peps/pep-0008/) - [Method Names and Instance Variables](https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables) lowercase with words separated by underscores as necessary to improve readability. - `testDir` to `test_dir` - `inputData` to `input_data` - ... - [Blank Lines](https://www.python.org/dev/peps/pep-0008/#blank-lines) Surround top-level function and class definitions with two blank lines. - [Exception Names](https://www.python.org/dev/peps/pep-0008/#exception-names) and added verification logic about referenced before assignment for `output_type` Tree-SHA512: 346d08799f03077a2b7257ccdca123b4945b89dbf0677dba452d96b81ce186ec7b5dcdb10b8bb59cfce657a7aedbb7df64921036cbd1bf4ad8bd313d40faa796

Solved some warnings for Python PEP 8 convention
Method Names and Instance Variables
lowercase with words separated by underscores as necessary to improve readability.
testDirtotest_dirinputDatatoinput_dataBlank Lines
Surround top-level function and class definitions with two blank lines.
Exception Names
and added verification logic about referenced before assignment for
output_type