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

Discussion in 'Python' started by Oscar Benjamin, Jan 15, 2013.

  1. 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
    Oscar Benjamin, Jan 15, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kamilche
    Replies:
    7
    Views:
    279
    Peter Hansen
    Jun 29, 2004
  2. Lilith
    Replies:
    8
    Views:
    343
    Dave Rahardja
    Sep 2, 2005
  3. J
    Replies:
    3
    Views:
    148
    Steven D'Aprano
    Jan 16, 2013
  4. Ian Kelly
    Replies:
    0
    Views:
    138
    Ian Kelly
    Jan 16, 2013
  5. Dr.Ruud
    Replies:
    1
    Views:
    158
    Ted Zlatanov
    Feb 21, 2013
Loading...

Share This Page