Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.04; 'exit': 0.07; 'tests,': 0.07; 'tool,': 0.07; 'wrapper': 0.07; 'cc:addr :python-list': 0.10; 'properly': 0.15; 'skip:f 30': 0.15; 'cc:name:python list': 0.16; 'diagnostic': 0.16; 'simplified': 0.16; 'summarize': 0.16; 'wrote:': 0.17; 'implementing': 0.17; 'tests': 0.18; 'written': 0.20; 'tells': 0.22; 'defined': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'idea': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'looks': 0.26; 'wrote': 0.26; '(e.g.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'summary': 0.29; 'code': 0.31; 'print': 0.32; 'problem': 0.33; 'that,': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'fail': 0.35; 'subject:?': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'tool': 0.36; 'but': 0.36; 'level.': 0.36; 'ok,': 0.37; 'level': 0.37; 'passed': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'header:Received:5': 0.40; 'high': 0.61; 'series': 0.63; 'results': 0.65; 'else.': 0.65; 'subject:there': 0.65; '2013': 0.84; 'aggregated': 0.84; 'oscar': 0.84; 'subject:handle': 0.84; 'subject:status': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=vyldvjd+CDQt3u6MUFEQQaXI/7xyPlJD0Zl32zLttIc=; b=qsIROHfloxnI5VZYltbpELsInVrC+Fm5Q6WHUlqshY5mXxyKMhCmha3aNEtrhgRNF2 DJzhyVdPOh/rPi3Mm0etG7qtwHNjCv6HrAlU1ogaL9CCNhCJjcDPXHlVuykz1xty4ZzY rsd1MQVkvjhPL6ed57OlOd01GmjSyVx4+1cvoUgLdLjM8b5USE8tVMPdRK9myfFHSLK8 posiNeBbclzpr34NZLGTyI3y0cUSns1MZDvA2mitRETDnqNXP/u6lgW3SZzLesG9z7Mh tJ+NigEpOCFi7LO8LCY0Vq2oMxqQydbSqyF9IoFWvI6UBKc2Evh4ATbQxlriSJQPSCDU z7ig== MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 15 Jan 2013 23:56:04 +0000 Subject: Re: Is there a more elegant way to handle determing fail status? From: Oscar Benjamin To: J Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358294166 news.xs4all.nl 6960 [2001:888:2000:d::a6]:35750 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36877 On 15 January 2013 23:24, 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 > [SNIP] > > 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). How about the following? FAILED_CRITICAL = 4 FAILED_HIGH = 3 FAILED_MEDIUM = 2 FAILED_LOW = 1 PASSED = 0 if fail_level: print fail_message if fail_level > fail_priority: return 1 Oscar