Skip to content

Commit

Permalink
Merge pull request #11 from opencomputeproject/make-example-runnable
Browse files Browse the repository at this point in the history
Make code example from README.md runnable
  • Loading branch information
mimir-d authored Sep 2, 2023
2 parents 4671c0f + a26e8c1 commit 4f7f9fd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
-->
-->

0 comments on commit 4f7f9fd

Please sign in to comment.