-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from opencomputeproject/make-example-runnable
Make code example from README.md runnable
- Loading branch information
Showing
1 changed file
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,17 +78,24 @@ The specification does not impose any particular level of usage. To be compliant | |
A very simple starter example, which just outputs a diagnosis: | ||
```py | ||
import ocptv.output as tv | ||
import random | ||
def get_fan_speed(): | ||
return random.randrange(1500, 1700) | ||
def main(): | ||
run = tv.TestRun(name="simple_diagnosis", version="1.0") | ||
dut = tv.Dut(id="server0", name="server0.domain.net") | ||
with run.scope(dut=dut): | ||
step = run.add_step("check_fanspeed") | ||
with step.scope(): | ||
if get_fan_speed() > 1600: # assuming external get_fan_speed() impl | ||
step.add_diagnosis(DiagnosisType.PASS, verdict="fan_ok") | ||
if get_fan_speed() >= 1600: | ||
step.add_diagnosis(tv.DiagnosisType.PASS, verdict="fan_ok") | ||
else: | ||
step.add_diagnosis(DiagnosisType.FAIL, verdict="fan_low") | ||
step.add_diagnosis(tv.DiagnosisType.FAIL, verdict="fan_low") | ||
if __name__ == '__main__': | ||
main() | ||
``` | ||
Expected output (slightly reformatted for readability): | ||
|
@@ -190,4 +197,4 @@ An email contact is also available at: [email protected] | |
<!-- | ||
due to https://github.com/pypa/readme_renderer/issues/163 we must use absolute links everywhere | ||
--> | ||
--> |