Fix string concatenation to os.path.join and add exception case #11291

pull dongsam wants to merge 1 commits into bitcoin:master from dongsam:Fix-PEP8-warnings changing 1 files +8 −4
  1. dongsam commented at 10:35 PM on September 8, 2017: contributor

    Solved some warnings for Python PEP 8 convention

    and added verification logic about referenced before assignment for output_type

  2. fanquake added the label Tests on Sep 8, 2017
  3. in test/util/bitcoin-util-test.py:77 in 0823f28da7 outdated
      75 |      are not as expected. Error is caught by bctester() and reported.
      76 |      """
      77 |      # Get the exec names and arguments
      78 | -    execprog = buildenv["BUILDDIR"] + "/src/" + testObj['exec'] + buildenv["EXEEXT"]
      79 | -    execargs = testObj['args']
      80 | +    execprog = buildenv["BUILDDIR"] + "/src/" + test_obj['exec'] + buildenv["EXEEXT"]
    


    MarcoFalke commented at 9:21 PM on September 9, 2017:

    I'd assume those should probably use os.path.join to make it work on other os as well.

  4. MarcoFalke commented at 9:25 PM on September 9, 2017: member

    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 testObj to test_obj, as formatting fixes are allowed when none-style but refactoring changes are made to the affected lines.

  5. dongsam commented at 12:51 AM on September 10, 2017: contributor

     @MarcoFalke Thank you for your advice, I just added commit for use os.path.join instead string concatenation

  6. in test/util/bitcoin-util-test.py:78 in f7e0ecb74f outdated
      76 |      are not as expected. Error is caught by bctester() and reported.
      77 |      """
      78 |      # Get the exec names and arguments
      79 | -    execprog = buildenv["BUILDDIR"] + "/src/" + testObj['exec'] + buildenv["EXEEXT"]
      80 | -    execargs = testObj['args']
      81 | +    execprog = os.path.join(buildenv["BUILDDIR"], "src", test_obj["exec"], buildenv["EXEEXT"])
    


    MarcoFalke commented at 1:19 AM on September 10, 2017:

    The last concatenation is string concatenation.

    You can check if the tests pass locally by make check


    dongsam commented at 4:47 AM on September 10, 2017:

    Thanks I just fixed it, Sorry for my careless mistake

  7. in test/util/bitcoin-util-test.py:45 in a334360653 outdated
      45 | +    bctester(os.path.join(config["environment"]["SRCDIR"], "test/util/data"), "bitcoin-util-test.json",
      46 | +             config["environment"])
      47 | +
      48 |  
      49 | -def bctester(testDir, input_basename, buildenv):
      50 | +def bctester(test_dir, input_basename, buildenv):
    


    jnewbery commented at 2:15 PM on September 12, 2017:

    since you're converting to snake_case, how about build_env

  8. in test/util/bitcoin-util-test.py:78 in a334360653 outdated
      76 |      are not as expected. Error is caught by bctester() and reported.
      77 |      """
      78 |      # Get the exec names and arguments
      79 | -    execprog = buildenv["BUILDDIR"] + "/src/" + testObj['exec'] + buildenv["EXEEXT"]
      80 | -    execargs = testObj['args']
      81 | +    execprog = os.path.join(buildenv["BUILDDIR"], "src", test_obj["exec"]) + buildenv["EXEEXT"]
    


    jnewbery commented at 2:15 PM on September 12, 2017:

    exec_prog? (and exec_args and exec_run)

  9. jnewbery commented at 2:18 PM on September 12, 2017: member

    utACK. A couple of nits inline and commits should be squashed to a single commit before merge.

  10. dongsam force-pushed on Sep 12, 2017
  11. in test/util/bitcoin-util-test.py:29 in 5256a595a8 outdated
      26 | -    config.read_file(open(os.path.dirname(__file__) + "/../config.ini"))
      27 | +    config.read_file(open(os.path.join(os.path.dirname(__file__), "../config.ini")))
      28 |  
      29 |      parser = argparse.ArgumentParser(description=__doc__)
      30 | -    parser.add_argument('-v', '--verbose', action='store_true')
      31 | +    parser.add_argument("-v", "--verbose", action="store_true")
    


    MarcoFalke commented at 4:00 PM on September 12, 2017:

    I don't it is worth the overhead to change apostrophe to quotation mark.


    jnewbery commented at 5:15 PM on September 12, 2017:

    agree (and for short symbol-like strings as in this line, single quotes seem to be most people's preferred style)

  12. in test/util/bitcoin-util-test.py:41 in 5256a595a8 outdated
      41 |      # Add the format/level to the logger
      42 |      logging.basicConfig(format=formatter, level=level)
      43 |  
      44 | -    bctester(config["environment"]["SRCDIR"] + "/test/util/data", "bitcoin-util-test.json", config["environment"])
      45 | +    bctester(os.path.join(config["environment"]["SRCDIR"], "test/util/data"), "bitcoin-util-test.json",
      46 | +             config["environment"])
    


    MarcoFalke commented at 4:01 PM on September 12, 2017:

    Changing this line solely to split it into two causes difficulties grepping in the future.


    jnewbery commented at 5:17 PM on September 12, 2017:

    ... and most of our python files don't adhere to the 79 char max line length (which I think is a good thing!)

  13. in test/util/bitcoin-util-test.py:59 in 5256a595a8 outdated
      66 | -            failed_testcases.append(testObj["description"])
      67 | +            bctest(test_dir, test_obj, build_env)
      68 | +            logging.info("PASSED: " + test_obj["description"])
      69 | +        except Exception as e:
      70 | +            logging.info("FAILED: " + test_obj["description"])
      71 | +            logging.error("Error %s: %s" % (test_obj["description"], e))
    


    MarcoFalke commented at 4:02 PM on September 12, 2017:

    Can you explain why it makes sense to first log to info and then the same to the error level?

  14. in test/util/bitcoin-util-test.py:105 in 5256a595a8 outdated
     119 | -        if not outputData:
     120 | -            logging.error("Output data missing for " + outputFn)
     121 | +        if not output_data:
     122 | +            logging.error("Output data missing for " + output_fn)
     123 | +            raise Exception
     124 | +        if not output_type:
    


    MarcoFalke commented at 4:05 PM on September 12, 2017:

    Generally, I'd prefer if refactoring is separate (at least a separate commit) from changing behavior.

  15. in test/util/bitcoin-util-test.py:156 in 5256a595a8 outdated
     190 |          raise Exception
     191 |  
     192 | -    if "error_txt" in testObj:
     193 | -        want_error = testObj["error_txt"]
     194 | +    if "error_txt" in test_obj:
     195 | +        want_error = test_obj["error_txt"]
    


    MarcoFalke commented at 4:06 PM on September 12, 2017:

    I don't think it makes sense to replace every variable in the whole file by a lower_case name.

  16. MarcoFalke commented at 4:11 PM on September 12, 2017: member

    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.

  17. in test/util/bitcoin-util-test.py:23 in 5256a595a8 outdated
      19 | @@ -20,40 +20,44 @@
      20 |  import subprocess
      21 |  import sys
      22 |  
      23 | +
    


    jnewbery commented at 5:17 PM on September 12, 2017:

    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.

  18. jnewbery commented at 5:23 PM on September 12, 2017: member

    @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 os.path changes would make this more palatable for reviewers.

  19. dongsam force-pushed on Sep 13, 2017
  20. dongsam force-pushed on Sep 13, 2017
  21. dongsam force-pushed on Sep 13, 2017
  22. dongsam renamed this:
    Fix PEP8 warnings about formatting
    Fix string concatenation to os.path.join and add exception case
    on Sep 13, 2017
  23. MarcoFalke commented at 11:10 AM on October 5, 2017: member

    Needs rebase

  24. dongsam force-pushed on Oct 5, 2017
  25. in test/util/bitcoin-util-test.py:46 in b7fc18ac62 outdated
      42 | @@ -43,12 +43,11 @@ def main():
      43 |      formatter = '%(asctime)s - %(levelname)s - %(message)s'
      44 |      # Add the format/level to the logger
      45 |      logging.basicConfig(format=formatter, level=level)
      46 | -
    


    jnewbery commented at 2:06 PM on October 5, 2017:

    nit: why remove this line? Blank lines are used within functions to indicate logical sections.


    dongsam commented at 2:10 PM on October 5, 2017:

    sorry, that was mistake while rebasing, I'll add again now


    jnewbery commented at 2:28 PM on October 5, 2017:

    You've now added trailing whitespace :(

  26. dongsam force-pushed on Oct 5, 2017
  27. in test/util/bitcoin-util-test.py:95 in 5bd360002e outdated
      92 |          stdinCfg = subprocess.PIPE
      93 |  
      94 |      # Read the expected output data (if there is any)
      95 |      outputFn = None
      96 |      outputData = None
      97 | +    outputType = None
    


    jnewbery commented at 2:29 PM on October 5, 2017:

    Is this change (and the one at line 107) intentional?


    dongsam commented at 2:46 PM on October 5, 2017:

    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


    jnewbery commented at 2:32 PM on October 9, 2017:

    Yes, this is a good additional check.

  28. dongsam force-pushed on Oct 5, 2017
  29. in test/util/bitcoin-util-test.py:108 in f1c5277df7 outdated
     106 |              raise
     107 |          if not outputData:
     108 |              logging.error("Output data missing for " + outputFn)
     109 |              raise Exception
     110 | +        if not outputType:
     111 | +            logging.error("Output type missing for " + outputFn)
    


    jnewbery commented at 2:31 PM on October 9, 2017:

    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)
    

    fanquake commented at 1:38 PM on November 17, 2017:

    @dongsam Could you address @jnewbery's nit here? Looks like this is pretty much ready for merge.


    dongsam commented at 2:15 PM on December 8, 2017:

    @fanquake I just change and rebase the error text, sorry for late response

  30. dongsam force-pushed on Dec 8, 2017
  31. Fix string concatenation to os.path.join and add exception case a3ac7672ed
  32. in test/util/bitcoin-util-test.py:80 in 856b3e2811 outdated
      76 | @@ -77,32 +77,36 @@ def bctest(testDir, testObj, buildenv):
      77 |      are not as expected. Error is caught by bctester() and reported.
      78 |      """
      79 |      # Get the exec names and arguments
      80 | -    execprog = buildenv["BUILDDIR"] + "/src/" + testObj['exec'] + buildenv["EXEEXT"]
      81 | +    execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"]) + buildenv["EXEEXT"]
    


    jnewbery commented at 7:31 PM on December 8, 2017:

    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?


    dongsam commented at 2:32 AM on December 9, 2017:

    I thought also but that was mistook, buildenv["EXEEXT"] is not path, so occur error when with os.path.join that need just string concatenation

    comment


    jnewbery commented at 5:16 AM on December 9, 2017:

    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())


    dongsam commented at 6:17 AM on December 9, 2017:

    oh, sorry I misunderstood, that's look better, I'll update :)

  33. dongsam force-pushed on Dec 9, 2017
  34. jnewbery commented at 3:55 PM on December 9, 2017: member

    utACK a3ac7672ed9c63b954d3f368a90616448d31b4c3. Needs to be tested on windows.

  35. in test/util/bitcoin-util-test.py:48 in a3ac7672ed
      47 | @@ -48,7 +48,7 @@ def main():
      48 |  
    


    MarcoFalke commented at 6:41 PM on December 9, 2017:

    ^ 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'
    
  36. in test/util/bitcoin-util-test.py:51 in a3ac7672ed
      47 | @@ -48,7 +48,7 @@ def main():
      48 |  
      49 |  def bctester(testDir, input_basename, buildenv):
      50 |      """ Loads and parses the input file, runs all tests and reports results"""
      51 | -    input_filename = testDir + "/" + input_basename
      52 | +    input_filename = os.path.join(testDir, input_basename)
    


    MarcoFalke commented at 11:23 PM on December 9, 2017:

    Might as well pass in input_filename to bctester and instead do the path.join in line 47, no?

  37. MarcoFalke commented at 5:25 AM on December 30, 2017: member

    Going to merge since this is a strict improvement.

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    utACK a3ac7672ed9c63b954d3f368a90616448d31b4c3
    -----BEGIN PGP SIGNATURE-----
    
    iQIcBAEBCgAGBQJaRyMzAAoJENLqSFDnUoslIfgP/0jDVYpEb4TBa5/gBHwQJWqk
    ez+gDdtwFpJteURQoc4sDFzkGq4xFiltUBuZoDspjgOq8eETvn7mgGpd4t71ZwUy
    /7t8yIbFFVR94RhOXCRN/8z9u4vfE7068CeiNwmq+9tP6fRGpsfqCKSbY4qaYuR5
    c0RtmOds3ZEknAASMcarT0b+iiBv9gN3ryVlRochrWiO92/lRpfWYvkv0HldDZba
    +N1SAPju8KfSjcZRvZ6/3vOyfYChgrXh+y67MJLMGZCkct8YllcjXvPYy5Km74wI
    oEZm/TBq4aW3FNgDk4EPHWnKVCA/qC73TzaO3V4QnfqEZz5pXxSEbhldQpo7q+Lm
    s/Ve9FJdwMtnS1Gk+wrzoFZCioq6DVgoWixmwT0eJYB2bL9IeeBinceAIOAr08Sz
    3IgXgBgaxkaLZSYBp8kkkIsn8WYi0JD2tnDVxcTSBaGH1igdKogLWQDXqEd+Mu1D
    k+EArOVMWWeX/pgGoEV1u8Ze7mvZSGwxJxHsJtWGdCoXPgrFrZQFpaba4JkrGTq8
    d1vg+8v1+kpxSGlpehiX+2sEunrU5c6XwmSny2zAZassBJ0sTySglhwlqmI493fP
    3d0h0mOI2OX7SMxfos1psIrAOTQEEikWqMsxLnG/hehAlj7vOit7GFYCRha6kduE
    ElsosotNEXWBPPI7crsO
    =hB1L
    -----END PGP SIGNATURE-----
    
  38. MarcoFalke merged this on Dec 30, 2017
  39. MarcoFalke closed this on Dec 30, 2017

  40. MarcoFalke referenced this in commit a332a7d5a1 on Dec 30, 2017
  41. PastaPastaPasta referenced this in commit 9c7874ad1a on Jan 17, 2020
  42. PastaPastaPasta referenced this in commit 7c87be5e39 on Jan 22, 2020
  43. PastaPastaPasta referenced this in commit 0262542eb2 on Jan 22, 2020
  44. PastaPastaPasta referenced this in commit d387215bcd on Jan 29, 2020
  45. PastaPastaPasta referenced this in commit 4003f8e84e on Jan 29, 2020
  46. PastaPastaPasta referenced this in commit c46ae38c27 on Jan 29, 2020
  47. PastaPastaPasta referenced this in commit d086f160b5 on Jan 31, 2020
  48. ckti referenced this in commit ca50f255bd on Mar 28, 2021
  49. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 03:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me