#22 Filter empty bugs
Closed a year ago by adamwill. Opened a year ago by nielsenb.
fedora-qa/ nielsenb/relval empty-bugs-fix  into  main

file modified
+3 -1
@@ -123,7 +123,9 @@ 

          white = re.compile(r'\s')

          bugs = white.sub('', bugs)

          bugs = bugs.split(',')

-         if bugs == '':

+         # Filter empty strings

+         bugs = [bug for bug in bugs if bug != '']

+         if len(bugs) == 0:

              bugs = None

      comment = ''

      comm = input("Enter a comment if you like. If not, just hit Enter.\n"

@@ -0,0 +1,20 @@ 

+ # Copyright Red Hat

+ #

+ # This file is part of relval.

+ #

+ # wikitcms is free software; you can redistribute it and/or modify

+ # it under the terms of the GNU General Public License as published by

+ # the Free Software Foundation, either version 3 of the License, or

+ # (at your option) any later version.

+ #

+ # This program is distributed in the hope that it will be useful,

+ # but WITHOUT ANY WARRANTY; without even the implied warranty of

+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+ # GNU General Public License for more details.

+ #

+ # You should have received a copy of the GNU General Public License

+ # along with this program.  If not, see <http://www.gnu.org/licenses/>.

+ #

+ # Authors:

+ # Brandon Nielsen <nielsenb@jetfuse.net>

+ #

The added file is too large to be shown here, see it at: relval/tests/test_report_results.py

This is a followup from #20.

Improve handling of bugs string with no bugs.

The result of a string split operation is always an array, so the if bugs == '' conditional would never evaluate to true. This works around that with a filter of the split result to remove empty strings and changes the conditional to an array length check.

I have a version of this I like better...

bugs = input("Enter the IDs of any bugs associated with this report, "
             "separated by commas. ")
if bugs:
    # filter all whitespace
    bugs = re.sub(r'\s', '', bugs)
    # split on commas
    bugs = bugs.split(',')
    # drop any empty strings
    bugs = [bug for bug in bugs if bug]
if not bugs:
    # turn '' or [] into None
    bugs = None

if it passes your tests I'll go with that instead. Thanks for pointing out the problem though.

Hum, your tests don't actually cover this path, AFAICT - you didn't test input like " " or ",," or " , ," or "123, ,456" etc. (Hmm, it occurs to me we don't test that all actual characters are digits, either...if we're going to all this trouble we probably should...)

still, my version seems to work.

Pull-Request has been closed by adamwill

a year ago