Quick script to help reporting bugs for python

While poking around the testrepository package I ran into the cryptic error message of 'unicodeescape' codec can't decode bytes in position 56-57: truncated \uXXXX escape. I set out to reproduce the bug, but that is of course an iterative process, like anything else in coding, so I set out to script it. Since I expect I'll need this again, and someone else might need it too, I'm recording it here.

Note

I eventually figured out the problem was that the recommended default for testrepository has a different command line behavior from the built in unittest's runner:

  • python -m unittest discover bugrepro
  • testr run bugrepro doesn't get translated to the discover root, but into LISTOPT variable (python -m subunit.run discover . $LISTOPT $IDOPTION)

Sure, a nicer exception message would have been nice.

My Environment

While for serious development I use Linux VMs, for explorations/hobbies, I use the base Windows 7 on my command line from git-bash - it's enough for basic scripting things, plus I tend to use git anyway, and I don't like Powershell.

The script

#!/bin/sh
function d() {
    echo "\$ $*"
    $*
}

function win_info() {
    systeminfo | grep "\(OS Name\|OS Manufacturer\|System Type\|Locale\)"
}

REPRO_FOLDER=bugrepro
d win_info
d python --version
d pip freeze
d git --version
d grep ^ -nH `find $REPRO_FOLDER -name \*.py`
d python -m unittest discover $REPRO_FOLDER
d ls .testr* -l
d cat .testr.conf
d testr run $REPRO_FOLDER
d testr run

Running ./bugrepro.sh 2>&1 | tee bugrepro.txt  > /dev/null produces the following output (cropped, you can see the full output here):

$ win_info
OS Name:                   Microsoft Windows 7 Professional 
OS Manufacturer:           Microsoft Corporation
System Type:               x64-based PC
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
$ python --version
Python 2.7.4
$ pip freeze
extras==0.0.3

Things I learned

While this took somewhat longer than expected (and writing this post wasn't even planned!) and I haven't even reported the actual bug yet (Yak shaving...), but I don't mind - especially because I did all this while recovering from a nasty cold :)

Open Questions (aka: do I want to shave further yaks?!):

  • cmd.exe /C doesn't seem to behave as one would expect it when invoked from git-bash (msysgit, 1.8.1) - it doesn't exit and the execution to continue requires an exit command!

  • I always want to do metaprogramming in bash - how could I display the body of a bash function? I'm thinking of something similar to what one does with alias

    $ alias foo='echo foo'
    $ foo
    foo
    $ alias foo
    alias foo='echo foo'
    
  • is there a better way for passing arguments in bash? I ended up doing grep ^ because I went crazy trying to escape find... -exec...\;. and making the script use #!/bin/bash -x would be an overkill here, and I just want to echo back the command that was executed...

What do you think? I would love if you would leave a comment - drop me an email at hello@zsoldosp.eu, tell me on Twitter!

Posted on in bash, code, note to self, python, software by

Share this post if you liked it - on Digg, Facebook, Google+, reddit, or Twitter

Your email address