Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36876

Re: Is there a more elegant way to handle determing fail status?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <donarb@nwlink.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'jeff': 0.04; 'output': 0.04; 'defaults': 0.05; 'none,': 0.05; 'exit': 0.07; 'tests,': 0.07; 'tool,': 0.07; 'wrapper': 0.07; 'none.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'index': 0.13; 'properly': 0.15; 'skip:f 30': 0.15; 'assigns': 0.16; 'cc:name:python list': 0.16; 'diagnostic': 0.16; 'element.': 0.16; 'failed.': 0.16; 'simplified': 0.16; 'summarize': 0.16; 'tool:': 0.16; 'wrote:': 0.17; 'element': 0.17; 'implementing': 0.17; 'skip:{ 20': 0.17; 'variables': 0.17; 'tests': 0.18; '(or': 0.18; 'written': 0.20; 'tells': 0.22; 'defined': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; '15,': 0.23; 'this:': 0.23; 'idea': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'wrote': 0.26; 'values': 0.26; '(e.g.': 0.27; 'coding': 0.27; 'errors.': 0.27; 'correct': 0.28; 'run': 0.28; 'necessary,': 0.29; 'priority': 0.29; 'array': 0.29; 'summary': 0.29; "skip:' 10": 0.30; 'error': 0.30; 'code': 0.31; 'point': 0.31; 'running': 0.32; 'problem': 0.33; 'that,': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'list': 0.35; 'direction': 0.35; 'fail': 0.35; 'so,': 0.35; 'doing': 0.35; 'subject:?': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'explain': 0.36; 'tool': 0.36; 'but': 0.36; 'level.': 0.36; 'enough': 0.36; 'ok,': 0.37; 'level': 0.37; 'passed': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'end': 0.40; 'high': 0.61; 'first': 0.61; 'back': 0.62; 'provide': 0.62; 'series': 0.63; 'our': 0.65; 'results': 0.65; 'else.': 0.65; 'subject:there': 0.65; 'counts': 0.81; 'low': 0.83; '2013': 0.84; 'aggregated': 0.84; 'subject:handle': 0.84; 'subject:status': 0.84; 'this...': 0.84
Newsgroups comp.lang.python
Date Tue, 15 Jan 2013 15:52:43 -0800 (PST)
In-Reply-To <mailman.554.1358292312.2939.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=74.61.37.162; posting-account=j77mzQ8AAAANT_vs79yTKlJVSM4DQEXi
References <mailman.554.1358292312.2939.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 74.61.37.162
MIME-Version 1.0
Subject Re: Is there a more elegant way to handle determing fail status?
From donarb <donarb@nwlink.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.555.1358293973.2939.python-list@python.org> (permalink)
Lines 201
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358293973 news.xs4all.nl 6960 [2001:888:2000:d::a6]:60513
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36876

Show key headers only | View raw


On Tuesday, January 15, 2013 3:24:44 PM UTC-8, J wrote:
> Ok, so I have a diagnostic tool, written by someone else. That tool
> 
> runs a series of small tests defined by the user and can simplified
> 
> summary output that can be one of the following:
> 
> 
> 
> FAILED_CRITICAL
> 
> FAILED_HIGH
> 
> FAILED_MEDIUM
> 
> FAILED_LOW
> 
> PASSED
> 
> 
> 
> I also have a wrapper script I wrote to run these tests, summarize the
> 
> results of all tests aggregated and then fail based on a particular
> 
> fail level.
> 
> 
> 
> The idea is that if I run 3 tests with the diagnostic tool and it
> 
> tells me the following:
> 
> 
> 
> testA: PASSED
> 
> testB: FAILED_MEDIUM
> 
> testC: PASSED
> 
> 
> 
> AND I told the wrapper to only fail on HIGH or above, the wrapper will
> 
> tell me that I had a medium failure, but the wrapper will still exit
> 
> with a 0 (success)
> 
> 
> 
> if I get the same results as above, but tell the wrapper to fail on
> 
> LOW, then it will tell me I had that medium failure, but the wrapper
> 
> will exit with a 1 (failure).
> 
> 
> 
> The problem is that my exit determination looks like this:
> 
> 
> 
>     if fail_priority == fail_levels['FAILED_CRITICAL']:
> 
>         if critical_fails:
> 
>             return 1
> 
>     if fail_priority == fail_levels['FAILED_HIGH']:
> 
>         if critical_fails or high_fails:
> 
>             return 1
> 
>     if fail_priority == fail_levels['FAILED_MEDIUM']:
> 
>         if critical_fails or high_fails or medium_fails:
> 
>             return 1
> 
>     if fail_priority == fail_levels['FAILED_LOW']:
> 
>         if critical_fails or high_fails or medium_fails or low_fails:
> 
>             return 1
> 
> 
> 
>     return 0
> 
> 
> 
> So, to explain the above... the fail level can be set by the user when
> 
> running the wrapper using -f (or it defaults to 'high')
> 
> the wrapper assigns a number to each level using this:
> 
> 
> 
>     # Set correct fail level
> 
>     args.fail_level = 'FAILED_%s' % args.fail_level.upper()
> 
> 
> 
>     # Get our failure priority and create the priority values
> 
>     fail_levels = {'FAILED_CRITICAL':4,
> 
>                    'FAILED_HIGH':3,
> 
>                    'FAILED_MEDIUM':2,
> 
>                    'FAILED_LOW':1}
> 
>     fail_priority = fail_levels[args.fail_level]
> 
> 
> 
> the variables critical_fails, high_fails, medium_fails, low_fails are
> 
> all counters that are etiher None, or the number of tests that were
> 
> failed.
> 
> 
> 
> So using this output from the diagnostic tool:
> 
> 
> 
> testA: PASSED
> 
> testB: FAILED_HIGH
> 
> testC: PASSED
> 
> testD: FAILED_MEDIUM
> 
> testE: PASSED
> 
> 
> 
> critical_fails would be None
> 
> high_fails would be 1
> 
> medium_fails would be 1
> 
> low_fails would be None.
> 
> 
> 
> The exit code determination above works, but it just feels inelegant.
> 
> It feels like there's a better way of implementing that, but I can't
> 
> come up with one that still honors the fail level properly (e.g. other
> 
> solutions will fail on medium, but won't fail properly on medium OR
> 
> higher).
> 
> 
> 
> I can provide the full script if necessary, if the above isn't enough
> 
> to point me in a direction that has a better way of doing this...
> 
> 
> 
> Thanks for looking,
> 
> 
> 
> Jeff

My back of the envelope coding would do it this way. Use an array of fail_counters, with PASSED as the first element all the way up to FAILED_CRITICAL as the last element. Then use a simple loop starting from index fail_priority to the end of the list looking for errors. Like this:

# Array of fail counters
fail_counters = [
    0,  # PASSED
    0,  # LOW
    0,  # MEDIUM
    0,  # HIGH
    0   # CRITICAL
]

... run tests, accumulate error counts in fail_counters

for i in range(fail_priority, len(fail_counters)):
    if fail_counters[i]:
        return 1
return 0

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is there a more elegant way to handle determing fail status? J <dreadpiratejeff@gmail.com> - 2013-01-15 18:24 -0500
  Re: Is there a more elegant way to handle determing fail status? donarb <donarb@nwlink.com> - 2013-01-15 15:52 -0800
  Re: Is there a more elegant way to handle determing fail status? donarb <donarb@nwlink.com> - 2013-01-15 15:52 -0800
  Re: Is there a more elegant way to handle determing fail status? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-16 02:55 +0000

csiph-web